Page 215 - DCAP408_WEB_PROGRAMMING
P. 215

Unit 13: Windows GDI




                                                                                                Notes


             Notes  In GDI calls screen position 0,0 is the top left of the window. If you need to work out
             the window width and height follow this link here: Window size
          An example application showing these GDI functions can be downloaded here: WinGDIdemo.exe.
          In addition the source code for this demo can also be downloaded: WinGDIDemoCode.zip
          The different GDI capabilities:

              Displaying Text
              Displaying Pixels
              Drawing Lines
              Drawing Filled Shapes

              Pens & Brushes
              Window size
              Forcing a redraw

          13.1.1 Displaying  Text

          To display some text you can use the TextOut function. In order to use this you need to obtain a
          handle to the device, an HDC and release it after use.
          To obtain  the handle you call: BeginPaint, it takes your window handle  and a pointer to a
          PAINTSTRUCT that you have declared. This structure is just used by windows so you don't need
          to do anything apart from pass it on to functions.
          The definition of the TextOut function is:
          BOOL TextOut(HDC hdc, int x, int y, LPCSTR lpString, int cbString);

          It takes the handle you were returned from BeginPaint, the x, y position on screen, a pointer to
          some text and the number of characters you want to display.
          After displaying your text you must call EndPaint to release the handle.

          For example, to display 'Hello World' at screen position 10,10 you could do this:
          PAINTSTRUCT ps;
          HDC hdc = BeginPaint(hWnd, &ps);
          TextOut(hdc,10,10,"Hello World",11);

          EndPaint(hWnd, &ps);



             Did u know?  What is GDI +?
             Windows GDI+ is a class-based API for C/C++ programmers. It enables applications to
             use graphics and formatted text on both the video display and the printer.









                                           LOVELY PROFESSIONAL UNIVERSITY                                   209
   210   211   212   213   214   215   216   217   218   219   220