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

  1. /*
  2.  
  3. Function(s) demonstrated in this program: GetClassLong
  4.  
  5. Windows version:  2.03
  6.  
  7. Windows SDK version:  2.00
  8.  
  9. Compiler version:  C 5.10
  10.  
  11. Description:  This function retrieves the given LONG value from the 
  12.    respective class structure.
  13.  
  14. Additional Comments:
  15.  
  16. */
  17.  
  18. #define NOMINMAX
  19. #include <windows.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include "GetCLong.h"
  23.  
  24.  
  25. HWND     hWndParent1;
  26. HANDLE   hInstMain;
  27.  
  28. char     szOutputBuffer1 [70];
  29. char     szOutputBuffer2 [500];
  30.  
  31.  
  32. /****************************************************************************/
  33. /************************    Message Structure      *************************/
  34. /****************************************************************************/
  35.  
  36. struct { char *szMessage; }
  37.        Messages [] = {
  38. "About\0",
  39. "     This is a sample application to demonstrate the\n\
  40. use of the GetClassLong Windows function.",
  41.  
  42. "Help Message",
  43. "     This program uses the GetClassLong Windows\n\
  44. function to get a pointer to the menu name of the\n\
  45. current window.  Use the menu to invoke this\n\
  46. function.",
  47.  
  48. };    
  49.  
  50. /****************************************************************************/
  51.  
  52. void ProcessMessage (HWND, int); 
  53.  
  54. void ProcessMessage (hWnd, MessageNumber) 
  55.      HWND     hWnd;
  56.      int      MessageNumber;
  57. {
  58.      sprintf (szOutputBuffer1, "%s", Messages [MessageNumber]);
  59.      sprintf (szOutputBuffer2, "%s", Messages [MessageNumber + 1]);
  60.      MessageBox (hWnd, szOutputBuffer2, szOutputBuffer1, MB_OK);
  61. }       
  62.  
  63. /****************************************************************************/
  64.  
  65. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  66.      HANDLE      hInstance, hPrevInstance ;
  67.      LPSTR       lpszCmdLine ;
  68.      int         nCmdShow ;
  69.      {
  70.      static char szAppName [] = "GetCLong" ;
  71.      HWND        hWnd ;
  72.      WNDCLASS    wndclass ;
  73.      MSG msg;
  74.      short       xScreen, yScreen ;
  75.  
  76.      if (!hPrevInstance) 
  77.           {
  78.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  79.           wndclass.lpfnWndProc   = WndProc ;
  80.           wndclass.cbClsExtra    = 0 ;
  81.           wndclass.cbWndExtra    = 0 ;
  82.           wndclass.hInstance     = hInstance ;
  83.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  84.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  85.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  86.           wndclass.lpszMenuName  = szAppName ;
  87.           wndclass.lpszClassName = szAppName ;
  88.  
  89.           if (!RegisterClass (&wndclass))
  90.                return FALSE ;
  91.           }
  92.  
  93.      xScreen = GetSystemMetrics (SM_CXSCREEN) ;
  94.      yScreen = GetSystemMetrics (SM_CYSCREEN) ;
  95.  
  96.      hWndParent1 = CreateWindow (szAppName,     /* window class name       */
  97.                     "GetClassLong",             /* window caption          */
  98.                     WS_OVERLAPPEDWINDOW,        /* window style            */
  99.                     CW_USEDEFAULT,              /* initial x position      */
  100.                     0,                          /* initial y position      */
  101.                     CW_USEDEFAULT,              /* initial x size          */
  102.                     0,                          /* initial y size          */
  103.                     NULL,                       /* parent window handle    */
  104.                     NULL,                       /* window menu handle      */
  105.                     hInstance,                  /* program instance handle */
  106.                     NULL) ;                     /* create parameters       */
  107.  
  108.      ShowWindow (hWndParent1, nCmdShow) ;
  109.      UpdateWindow (hWndParent1) ;
  110.  
  111.      hInstMain = hInstance;
  112.  
  113.      while (GetMessage(&msg, NULL, 0, 0))
  114.      {
  115.       TranslateMessage(&msg);
  116.       DispatchMessage(&msg);
  117.      } 
  118.      return (msg.wParam) ;     
  119.      }
  120.  
  121. /****************************************************************************/
  122.  
  123. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  124. HWND     hWnd ;
  125. unsigned iMessage ;
  126. WORD     wParam ;
  127. LONG     lParam ;
  128. {
  129.  LONG        lpMenu;
  130.  HMENU       hMenu;
  131.  HDC         hDC;
  132.  PAINTSTRUCT ps;
  133.  static int  xClient, yClient;
  134.  switch(iMessage)
  135.  {
  136.   case WM_CREATE:
  137.        hMenu = GetSystemMenu (hWnd, FALSE);
  138.  
  139.        ChangeMenu (hMenu, NULL, "&About", IDM_ABOUT, 
  140.                    MF_APPEND | MF_STRING);
  141.        break;
  142.  
  143.   case WM_SYSCOMMAND:
  144.        switch (wParam) {
  145.           case IDM_ABOUT:
  146.                ProcessMessage (hWnd, 0);
  147.                break;
  148.           default:
  149.                return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  150.        }
  151.        break;
  152.  
  153.   case WM_COMMAND:
  154.        switch (wParam) {
  155.           case IDM_GETCLASSLONG:
  156.                lpMenu = GetClassLong (hWnd, GCL_MENUNAME);
  157.                sprintf (szOutputBuffer1, 
  158.                         "The pointer to the menu name is %x", lpMenu);
  159.                MessageBox (hWnd, szOutputBuffer1, "GetClassLong", MB_OK);
  160.                break;
  161.  
  162.           case IDM_HELP:
  163.                ProcessMessage (hWnd, 2);
  164.                break;
  165.        }
  166.        break;
  167.  
  168.   case WM_PAINT:
  169.        BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  170.        EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  171.        break;
  172.  
  173.   case WM_DESTROY:
  174.        PostQuitMessage(0);
  175.        break;
  176.  
  177.   default:
  178.   {
  179.    return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  180.   }
  181.  }
  182.  return (0L); 
  183. }
  184.  
  185.  
  186.  
  187.