home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / graphics / cric.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.9 KB  |  155 lines

  1. /*
  2.  *  Function Name:   CreateIC
  3.  *  Program Name:    cric.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.0
  7.  *
  8.  *  Description:
  9.  *   An information context is retrieved from the display, and the brush is
  10.  *   extracted.  The brush information for the IC is then displayed on
  11.  *   the screen to show that the IC has valid information.
  12.  */
  13.  
  14. #include "windows.h"
  15. #include "stdio.h"
  16.  
  17. long    FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  18.  
  19. /***********************************************************************/
  20.  
  21. void CALL_CreateIC(hWnd, hDC)
  22. HWND hWnd;
  23. HDC  hDC;
  24. {
  25.   HDC hIC;
  26.   PLOGBRUSH pBrush;
  27.   HBRUSH  hICBrush;
  28.   char    szstring[80];
  29.   int    nLength;
  30. /*  information context created   */
  31.   hIC = CreateIC((LPSTR)"DISPLAY", (LPSTR)NULL, (LPSTR)NULL, (LPSTR)NULL);
  32.  
  33.   if (hIC == NULL)
  34.   {
  35.     MessageBox(hWnd, (LPSTR)"CreateIC failed", (LPSTR)"ERROR", MB_ICONHAND);
  36.     return;
  37.   }
  38.  
  39.   pBrush = (PLOGBRUSH) LocalAlloc(LMEM_MOVEABLE, sizeof(LOGBRUSH));
  40.   hICBrush = SelectObject(hIC, CreateSolidBrush((LONG)0));
  41.   GetObject(hICBrush, 8, (LPSTR) pBrush);   /* put brush into structure */
  42.   nLength = sprintf(szstring, "Information Context Brush Attributes are:"
  43.       "   style=%u, color=%lx, hatch=%d ",
  44.       pBrush->lbStyle, pBrush->lbColor, pBrush->lbHatch);
  45.   TextOut (hDC, 10, 10, (LPSTR) szstring, nLength);
  46.  
  47.   return;
  48. }
  49.  
  50.  
  51. /**************************************************************************/
  52.  
  53. /* Procedure called when the application is loaded for the first time */
  54. BOOL WinInit( hInstance )
  55. HANDLE hInstance;
  56. {
  57.   WNDCLASS   wcClass;
  58.  
  59.   wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  60.   wcClass.lpfnWndProc    = WndProc;
  61.   wcClass.cbClsExtra     = 0;
  62.   wcClass.cbWndExtra     = 0;
  63.   wcClass.hInstance      = hInstance;
  64.   wcClass.hIcon          = LoadIcon( hInstance, NULL );
  65.   wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  66.   wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  67.   wcClass.lpszMenuName   = (LPSTR)NULL;
  68.   wcClass.lpszClassName  = (LPSTR)"CreateIC";
  69.  
  70.   if (!RegisterClass( (LPWNDCLASS) & wcClass ) )
  71. /* Initialization failed.
  72.          * Windows will automatically deallocate all allocated memory.
  73.          */
  74.     return FALSE;
  75.  
  76.   return TRUE;        /* Initialization succeeded */
  77. }
  78.  
  79.  
  80. int    PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  81. HANDLE hInstance, hPrevInstance;
  82. LPSTR lpszCmdLine;
  83. int    cmdShow;
  84. {
  85.   MSG   msg;
  86.   HWND  hWnd;
  87.   HMENU hMenu;
  88.  
  89.   if (!hPrevInstance)
  90.   {
  91. /* Call initialization procedure if this is the first instance */
  92.     if (!WinInit( hInstance ))
  93.       return FALSE;
  94.   }
  95.  
  96.   hWnd = CreateWindow((LPSTR)"CreateIC",
  97.       (LPSTR)"CreateIC()",
  98.       WS_OVERLAPPEDWINDOW,
  99.       CW_USEDEFAULT,
  100.       CW_USEDEFAULT,
  101.       CW_USEDEFAULT,
  102.       CW_USEDEFAULT,
  103.       (HWND)NULL,        /* no parent */
  104.   (HMENU)NULL,       /* use class menu */
  105.   (HANDLE)hInstance, /* handle to window instance */
  106.   (LPSTR)NULL        /* no params to pass on */
  107.   );
  108.  
  109. /* Make window visible according to the way the app is activated */
  110.   ShowWindow( hWnd, cmdShow );
  111.   UpdateWindow( hWnd );
  112.  
  113. /* Polling messages from event queue */
  114.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  115.   {
  116.     TranslateMessage((LPMSG) & msg);
  117.     DispatchMessage((LPMSG) & msg);
  118.   }
  119.  
  120.   return (int)msg.wParam;
  121. }
  122.  
  123.  
  124. /* Procedures which make up the window class. */
  125. long    FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  126. HWND hWnd;
  127. unsigned    message;
  128. WORD wParam;
  129. LONG lParam;
  130. {
  131.   PAINTSTRUCT ps;
  132.  
  133.   switch (message)
  134.   {
  135.  
  136.   case WM_PAINT:
  137.     BeginPaint( hWnd, (LPPAINTSTRUCT) & ps );
  138.     CALL_CreateIC(hWnd, ps.hdc);
  139.     ValidateRect(hWnd, (LPRECT) NULL);
  140.     EndPaint( hWnd, (LPPAINTSTRUCT) & ps );
  141.     break;
  142.  
  143.   case WM_DESTROY:
  144.     PostQuitMessage( 0 );
  145.     break;
  146.  
  147.   default:
  148.     return DefWindowProc( hWnd, message, wParam, lParam );
  149.     break;
  150.   }
  151.   return(0L);
  152. }
  153.  
  154.  
  155.