home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / object / enobj.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  4.1 KB  |  152 lines

  1. /*
  2.  *  Function Name:   EnumObjects
  3.  *  Program Name:    enobj.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.1
  7.  *
  8.  *  Description:
  9.  *   This function enumerates the pens and brushes available on a
  10.  *   device.  The program below will count the number of pen
  11.  *   enumerations.
  12.  */
  13.  
  14. #include "windows.h"
  15. #include "stdio.h"
  16.  
  17. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  18.  
  19. HANDLE hInst;
  20. int    nResult;
  21.  
  22. /*************************************************************************/
  23.  
  24. short FAR PASCAL EnumProc(lpObj, lpData)
  25. LPLOGPEN lpObj;
  26. LPSTR lpData;
  27. {
  28. /*  nPenStyle = lpObj->lopnStyle;   */
  29.   nResult++;                            /* enumerations counted   */
  30.   return (1);                    /* return value is user defined.   */
  31. }
  32.  
  33. /***********************************************************************/
  34.  
  35. void CALL_EnumObjects(hDC)
  36. HDC hDC;
  37. {
  38.   FARPROC lpprocEnumObj;
  39.   char    szstring[80];
  40.   int     nLength;
  41.  
  42.     lpprocEnumObj = MakeProcInstance ((FARPROC) EnumProc, hInst);
  43.     EnumObjects (hDC, OBJ_PEN, lpprocEnumObj, 0L);
  44.     FreeProcInstance ((FARPROC) lpprocEnumObj);
  45.  
  46.     nLength = sprintf(szstring, "Pen Enumerations = %d ", nResult);
  47.     TextOut (hDC, 10, 10, szstring, nLength);
  48.     nResult = 0;
  49.     return;
  50. }
  51.  
  52. /**************************************************************************/
  53.  
  54. /* Procedure called when the application is loaded for the first time */
  55. BOOL WinInit( hInstance )
  56. HANDLE hInstance;
  57. {
  58.     WNDCLASS   wcClass;
  59.  
  60.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  61.     wcClass.lpfnWndProc    = WndProc;
  62.     wcClass.cbClsExtra     =0;
  63.     wcClass.cbWndExtra     =0;
  64.     wcClass.hInstance      = hInstance;
  65.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  66.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  67.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  68.     wcClass.lpszMenuName   = (LPSTR)NULL;
  69.     wcClass.lpszClassName  = (LPSTR)"EnumObjects";
  70.  
  71.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  72.         /* Initialization failed.
  73.          * Windows will automatically deallocate all allocated memory.
  74.          */
  75.         return FALSE;
  76.  
  77.     return TRUE;        /* Initialization succeeded */
  78. }
  79.  
  80.  
  81. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  82. HANDLE hInstance, hPrevInstance;
  83. LPSTR lpszCmdLine;
  84. int cmdShow;
  85. {
  86.     MSG   msg;
  87.     HWND  hWnd;
  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)"EnumObjects",
  97.                         (LPSTR)"EnumObjects()",
  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.     hInst = hInstance;
  109.  
  110.     /* Make window visible according to the way the app is activated */
  111.     ShowWindow( hWnd, cmdShow );
  112.     UpdateWindow( hWnd );
  113.  
  114.     /* Polling messages from event queue */
  115.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  116.         {
  117.         TranslateMessage((LPMSG)&msg);
  118.         DispatchMessage((LPMSG)&msg);
  119.         }
  120.  
  121.     return (int)msg.wParam;
  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_EnumObjects(ps.hdc);
  139.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  140.         break;
  141.  
  142.     case WM_DESTROY:
  143.         PostQuitMessage( 0 );
  144.         break;
  145.  
  146.     default:
  147.         return DefWindowProc( hWnd, message, wParam, lParam );
  148.         break;
  149.     }
  150.     return(0L);
  151. }
  152.