home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / string / extexto.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  4KB  |  137 lines

  1. /*
  2.  *  Function Name:   ExtTextOut
  3.  *  Program Name:    extexto.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.1
  7.  *
  8.  *  Description:
  9.  *   The program below will display text in the given rectangular region.
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  15.  
  16. /***********************************************************************/
  17.  
  18. void CALL_ExtTextOut(hWnd, hDC)
  19. HWND hWnd;
  20. HDC hDC;
  21. {
  22.   RECT    rTextRect;
  23.   BOOL    bDrawn;
  24.  
  25.   rTextRect.left    = 0;
  26.   rTextRect.top     = 0;
  27.   rTextRect.right   = 350;
  28.   rTextRect.bottom  = 25;
  29.                                      /* function demonstrated */
  30.   bDrawn = ExtTextOut (hDC, 10, 10, ETO_CLIPPED, (LPRECT) &rTextRect,
  31.              (LPSTR) "Sample showing ExtTextOut", 25, (LPINT) NULL);
  32.  
  33.   if (bDrawn == FALSE)
  34.     MessageBox(hWnd, (LPSTR)"ExtTextOut failed", (LPSTR)"ERROR", MB_ICONHAND);
  35.   return;
  36. }
  37.  
  38. /**************************************************************************/
  39.  
  40. /* Procedure called when the application is loaded for the first time */
  41. BOOL WinInit( hInstance )
  42. HANDLE hInstance;
  43. {
  44.     WNDCLASS   wcClass;
  45.  
  46.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  47.     wcClass.lpfnWndProc    = WndProc;
  48.     wcClass.cbClsExtra     =0;
  49.     wcClass.cbWndExtra     =0;
  50.     wcClass.hInstance      = hInstance;
  51.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  52.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );  /* black brush */
  53.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( BLACK_BRUSH );
  54.     wcClass.lpszMenuName   = (LPSTR)NULL;
  55.     wcClass.lpszClassName  = (LPSTR)"ExtTextOut";
  56.  
  57.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  58.         /* Initialization failed.
  59.          * Windows will automatically deallocate all allocated memory.
  60.          */
  61.         return FALSE;
  62.  
  63.     return TRUE;        /* Initialization succeeded */
  64. }
  65.  
  66.  
  67. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  68. HANDLE hInstance, hPrevInstance;
  69. LPSTR lpszCmdLine;
  70. int cmdShow;
  71. {
  72.     MSG   msg;
  73.     HWND  hWnd;
  74.  
  75.     if (!hPrevInstance)
  76.         {
  77.         /* Call initialization procedure if this is the first instance */
  78.         if (!WinInit( hInstance ))
  79.             return FALSE;
  80.         }
  81.  
  82.     hWnd = CreateWindow((LPSTR)"ExtTextOut",
  83.                         (LPSTR)"ExtTextOut()",
  84.                         WS_OVERLAPPEDWINDOW,
  85.                         CW_USEDEFAULT,
  86.                         CW_USEDEFAULT,
  87.                         CW_USEDEFAULT,
  88.                         CW_USEDEFAULT,
  89.                         (HWND)NULL,        /* no parent */
  90.                         (HMENU)NULL,       /* use class menu */
  91.                         (HANDLE)hInstance, /* handle to window instance */
  92.                         (LPSTR)NULL        /* no params to pass on */
  93.                         );
  94.  
  95.     /* Make window visible according to the way the app is activated */
  96.     ShowWindow( hWnd, cmdShow );
  97.     UpdateWindow( hWnd );
  98.  
  99.     /* Polling messages from event queue */
  100.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  101.         {
  102.         TranslateMessage((LPMSG)&msg);
  103.         DispatchMessage((LPMSG)&msg);
  104.         }
  105.  
  106.     return (int)msg.wParam;
  107. }
  108.  
  109. /* Procedures which make up the window class. */
  110. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  111. HWND hWnd;
  112. unsigned message;
  113. WORD wParam;
  114. LONG lParam;
  115. {
  116.     PAINTSTRUCT ps;
  117.  
  118.     switch (message)
  119.     {
  120.  
  121.     case WM_PAINT:
  122.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  123.         CALL_ExtTextOut(hWnd, ps.hdc);
  124.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  125.         break;
  126.  
  127.     case WM_DESTROY:
  128.         PostQuitMessage( 0 );
  129.         break;
  130.  
  131.     default:
  132.         return DefWindowProc( hWnd, message, wParam, lParam );
  133.         break;
  134.     }
  135.     return(0L);
  136. }
  137.