home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / string / gray.c < prev    next >
Text File  |  1988-08-10  |  4KB  |  128 lines

  1. /*
  2.  *   GrayString
  3.  *
  4.  *   This program demonstrates the use of the GrayString function. The
  5.  *   GrayString function outputs gray text to the specified window.
  6.  *
  7.  */
  8.  
  9. #include "windows.h"
  10.  
  11. long FAR PASCAL HelloWndProc(HWND, unsigned, WORD, LONG);
  12.  
  13. /* Procedure called when the application is loaded for the first time */
  14. BOOL HelloInit( hInstance )
  15. HANDLE hInstance;
  16. {
  17.     PWNDCLASS   pHelloClass;
  18.  
  19.     pHelloClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  20.  
  21.     pHelloClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  22.     pHelloClass->hIcon        = LoadIcon( hInstance,NULL);
  23.     pHelloClass->lpszMenuName   = (LPSTR)NULL;
  24.     pHelloClass->lpszClassName    = (LPSTR)"Sample Application";
  25.     pHelloClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  26.     pHelloClass->hInstance      = hInstance;
  27.     pHelloClass->style          = CS_HREDRAW | CS_VREDRAW;
  28.     pHelloClass->lpfnWndProc    = HelloWndProc;
  29.  
  30.     if (!RegisterClass( (LPWNDCLASS)pHelloClass ) )
  31.         /* Initialization failed.
  32.          * Windows will automatically deallocate all allocated memory.
  33.          */
  34.         return FALSE;
  35.  
  36.     LocalFree( (HANDLE)pHelloClass );
  37.     return TRUE;        /* Initialization succeeded */
  38. }
  39.  
  40. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  41. HANDLE hInstance, hPrevInstance;
  42. LPSTR lpszCmdLine;
  43. int cmdShow;
  44. {
  45.     MSG   msg;
  46.     HWND  hWnd;
  47.     HMENU hMenu;
  48.     HDC   hDC;                /* Handle to display context */
  49.     HBRUSH hMyBrush;            /* Handle to a brush     */
  50.     DWORD gray=RGB(0x22,0x22,0x22); /* Red, Green, Blue, values for brush */
  51.  
  52.     HelloInit( hInstance );
  53.     hWnd = CreateWindow((LPSTR)"Sample Application",
  54.             (LPSTR)"Sample Application",
  55.             WS_OVERLAPPEDWINDOW,
  56.             CW_USEDEFAULT,
  57.             CW_USEDEFAULT,
  58.             CW_USEDEFAULT,
  59.             CW_USEDEFAULT,
  60.                         (HWND)NULL,        /* no parent */
  61.                         (HMENU)NULL,       /* use class menu */
  62.                         (HANDLE)hInstance, /* handle to window instance */
  63.                         (LPSTR)NULL        /* no params to pass on */
  64.                         );
  65.  
  66.     /* Make window visible according to the way the app is activated */
  67.     ShowWindow( hWnd, cmdShow );
  68.     UpdateWindow( hWnd );
  69.  
  70. /******************************************************************/
  71.   /* get handle to display context */
  72.      hDC = GetDC(hWnd);
  73.   /* create brush with the colors specified by "gray" */
  74.     hMyBrush = CreateSolidBrush(gray);
  75.   /* if brush not created succesfully */
  76.     if (hMyBrush = NULL)
  77.   /* output error */
  78.     MessageBox(hWnd,(LPSTR)"Unable to Create Brush",(LPSTR)"Too Bad",
  79.            MB_OK);
  80.     else
  81.   /* else output gray text */
  82.  
  83.   GrayString(hDC,hMyBrush,NULL,(DWORD)(LPSTR)"This is gray text",0,5,5,0,0);
  84.  
  85.     /* Polling messages from event queue */
  86.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  87.         TranslateMessage((LPMSG)&msg);
  88.         DispatchMessage((LPMSG)&msg);
  89.         }
  90.  
  91.     return (int)msg.wParam;
  92. }
  93.  
  94. /* Procedures which make up the window class. */
  95. long FAR PASCAL HelloWndProc( hWnd, message, wParam, lParam )
  96. HWND hWnd;
  97. unsigned message;
  98. WORD wParam;
  99. LONG lParam;
  100. {
  101.   PAINTSTRUCT ps;
  102.  
  103.     switch (message)
  104.     {
  105.     case WM_SYSCOMMAND:
  106.         switch (wParam)
  107.         {
  108.         default:
  109.             return DefWindowProc( hWnd, message, wParam, lParam );
  110.         }
  111.         break;
  112.  
  113.     case WM_DESTROY:
  114.         PostQuitMessage( 0 );
  115.         break;
  116.  
  117.     case WM_PAINT:
  118.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  119.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  120.         break;
  121.  
  122.     default:
  123.         return DefWindowProc( hWnd, message, wParam, lParam );
  124.         break;
  125.     }
  126.     return(0L);
  127. }
  128.