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

  1. /*
  2.  *  Function Name:   EnumProps
  3.  *  Program Name:    enprops.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.1
  7.  *
  8.  *  Description:
  9.  *   This function will enumerate properties assigned to a window.
  10.  *   The program below will assign two properties to the window
  11.  *   and display them during the enumeration.
  12.  */
  13.  
  14. #include "windows.h"
  15. #include "string.h"
  16.  
  17. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  18.  
  19. HANDLE hInst;
  20. int    nResult;
  21.  
  22. /*************************************************************************/
  23.  
  24. int FAR PASCAL EnumProc(hWnd, lpString, hData)
  25. HWND   hWnd;
  26. LPSTR  lpString;
  27. HANDLE hData;
  28. {
  29.   HDC  hDC;
  30.   static int nInc = 10;
  31.  
  32.   hDC = GetDC(hWnd);
  33.   TextOut(hDC, 10, nInc+=20, lpString, strlen((PSTR) LOWORD(lpString)));
  34.   ReleaseDC (hWnd, hDC);
  35.   return (1);                    /* return value is user defined.   */
  36. }
  37.  
  38. /***********************************************************************/
  39.  
  40. void CALL_EnumProps(hWnd, hDC)
  41. HWND hWnd;
  42. HDC hDC;
  43. {
  44.   FARPROC lpprocEnumProp;
  45.   char szstring[80];
  46.  
  47.   SetProp (hWnd, (LPSTR)"prop1", (HANDLE) NULL);
  48.   SetProp (hWnd, (LPSTR)"prop2", (HANDLE) NULL);
  49.  
  50.     lpprocEnumProp = MakeProcInstance ((FARPROC) EnumProc, hInst);
  51.     EnumProps (hWnd, lpprocEnumProp);       /*  function demonstrated   */
  52.     FreeProcInstance ((FARPROC) lpprocEnumProp);
  53.  
  54.   RemoveProp(hWnd, (LPSTR)"prop1");
  55.   RemoveProp(hWnd, (LPSTR)"prop2");
  56.  
  57.   return;
  58. }
  59.  
  60. /**************************************************************************/
  61.  
  62. /* Procedure called when the application is loaded for the first time */
  63. BOOL WinInit( hInstance )
  64. HANDLE hInstance;
  65. {
  66.     WNDCLASS   wcClass;
  67.  
  68.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  69.     wcClass.lpfnWndProc    = WndProc;
  70.     wcClass.cbClsExtra     =0;
  71.     wcClass.cbWndExtra     =0;
  72.     wcClass.hInstance      = hInstance;
  73.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  74.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  75.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  76.     wcClass.lpszMenuName   = (LPSTR)NULL;
  77.     wcClass.lpszClassName  = (LPSTR)"EnumProps";
  78.  
  79.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  80.         /* Initialization failed.
  81.          * Windows will automatically deallocate all allocated memory.
  82.          */
  83.         return FALSE;
  84.  
  85.     return TRUE;        /* Initialization succeeded */
  86. }
  87.  
  88.  
  89. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  90. HANDLE hInstance, hPrevInstance;
  91. LPSTR lpszCmdLine;
  92. int cmdShow;
  93. {
  94.     MSG   msg;
  95.     HWND  hWnd;
  96.  
  97.     if (!hPrevInstance)
  98.         {
  99.         /* Call initialization procedure if this is the first instance */
  100.         if (!WinInit( hInstance ))
  101.             return FALSE;
  102.         }
  103.  
  104.     hWnd = CreateWindow((LPSTR)"EnumProps",
  105.                         (LPSTR)"EnumProps()",
  106.                         WS_OVERLAPPEDWINDOW,
  107.                         CW_USEDEFAULT,
  108.                         CW_USEDEFAULT,
  109.                         CW_USEDEFAULT,
  110.                         CW_USEDEFAULT,
  111.                         (HWND)NULL,        /* no parent */
  112.                         (HMENU)NULL,       /* use class menu */
  113.                         (HANDLE)hInstance, /* handle to window instance */
  114.                         (LPSTR)NULL        /* no params to pass on */
  115.                         );
  116.     hInst = hInstance;
  117.  
  118.     /* Make window visible according to the way the app is activated */
  119.     ShowWindow( hWnd, cmdShow );
  120.     UpdateWindow( hWnd );
  121.  
  122.     /* Polling messages from event queue */
  123.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  124.         {
  125.         TranslateMessage((LPMSG)&msg);
  126.         DispatchMessage((LPMSG)&msg);
  127.         }
  128.  
  129.     return (int)msg.wParam;
  130. }
  131.  
  132. /* Procedures which make up the window class. */
  133. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  134. HWND hWnd;
  135. unsigned message;
  136. WORD wParam;
  137. LONG lParam;
  138. {
  139.     PAINTSTRUCT ps;
  140.  
  141.     switch (message)
  142.     {
  143.  
  144.     case WM_PAINT:
  145.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  146.         CALL_EnumProps(hWnd, ps.hdc);
  147.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  148.         break;
  149.  
  150.     case WM_DESTROY:
  151.         PostQuitMessage( 0 );
  152.         break;
  153.  
  154.     default:
  155.         return DefWindowProc( hWnd, message, wParam, lParam );
  156.         break;
  157.     }
  158.     return(0L);
  159. }
  160.