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

  1. /*
  2.  *
  3.  * GetSystemMetrics
  4.  *
  5.  * This program demonstrates the use of the GetSystemMetrics function
  6.  *  by checking to see if the debugging version of Windows is installed.
  7.  *  If the user couble clicks the right mouse button, a message box
  8.  *  is displayed telling if the debugging version of Windows has been
  9.  *  installed.
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. /* Global Variables */
  16. static HANDLE hInst;
  17. static HWND hWnd;
  18.  
  19. /* FORWARD REFERENCES */
  20. long FAR PASCAL WindowProc (HWND, unsigned, WORD, LONG);
  21.  
  22. /* WINMAIN */
  23. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  24. HANDLE hInstance, hPrevInstance;
  25. LPSTR lpszCmdLine;
  26. int cmdShow;
  27. {
  28.   MSG msg;
  29.  
  30.   if (!hPrevInstance)  {
  31.  
  32.      WNDCLASS rClass;
  33.  
  34.      rClass.lpszClassName = (LPSTR)"gsysmtrx";
  35.      rClass.hInstance      = hInstance;
  36.      rClass.lpfnWndProc   = WindowProc;
  37.      rClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  38.      rClass.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);
  39.      rClass.lpszMenuName  = (LPSTR)NULL;
  40.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  41.      rClass.style            = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  42.      rClass.cbClsExtra      = 0;       /* Add double click capabilities. */
  43.      rClass.cbWndExtra      = 0;
  44.  
  45.      RegisterClass((LPWNDCLASS)&rClass);
  46.  
  47.      }
  48.    else
  49.       ;
  50.  
  51.    hInst = hInstance;
  52.  
  53.    hWnd = CreateWindow((LPSTR) "gsysmtrx",
  54.                (LPSTR) "GetSystemMetrics",     /* Create a window.         */
  55.                WS_OVERLAPPEDWINDOW,            /* Make it overlapped.      */
  56.                CW_USEDEFAULT,                  /* Use default coordinates. */
  57.                CW_USEDEFAULT,                  /* Use default coordinates. */
  58.                CW_USEDEFAULT,                  /* Use default coordinates. */
  59.                CW_USEDEFAULT,                  /* Use default coordinates. */
  60.                (HWND)NULL,
  61.                (HMENU)NULL,
  62.                (HANDLE)hInstance,
  63.                (LPSTR)NULL
  64.              );
  65.  
  66.    ShowWindow(hWnd, cmdShow);
  67.  
  68.    UpdateWindow(hWnd);
  69.  
  70.    while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  71.        TranslateMessage(&msg);
  72.        DispatchMessage(&msg);
  73.    }
  74.  
  75.    exit(msg.wParam);
  76.  
  77. } /* WinMain */
  78.  
  79. /* WINDOWPROC */
  80.  
  81. long FAR PASCAL WindowProc(hWnd, identifier, wParam, lParam)
  82. HWND    hWnd;
  83. unsigned identifier;
  84. WORD     wParam;
  85. LONG     lParam;
  86.  
  87. {
  88.    
  89.    switch (identifier) {
  90.  
  91.      case WM_PAINT: {
  92.  
  93.            PAINTSTRUCT ps;
  94.           RECT        rRect;
  95.          HDC        hDC;
  96.  
  97.          hDC=BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  98.          SetMapMode(hDC, MM_ANISOTROPIC);
  99.          SetWindowOrg(hDC, 0, 0);
  100.          SetWindowExt(hDC, 110, 110);
  101.          GetClientRect(hWnd, (LPRECT)&rRect);
  102.          SetViewportOrg(hDC, 0, 0);
  103.          SetViewportExt(hDC, rRect.right, rRect.bottom);
  104.          DrawText(hDC,
  105.                 (LPSTR)"Double Click Right Mouse Button To Conduct Test.",
  106.                 48, (LPRECT)&rRect, DT_SINGLELINE);  /* Place text to    */
  107.          EndPaint(hWnd, (LPPAINTSTRUCT)&ps);          /* prompt for test. */
  108.  
  109.       }
  110.         break;
  111.     
  112.      case WM_RBUTTONDBLCLK:                    /* If the user double   */
  113.        {                                       /* clicks on the right  */
  114.        char szbuf[40];   /* Output buffer       | mouse button, then   */
  115.        int iValue;   /* 0 if no debug, !0 if so | establish needed     */
  116.                                                /* variables and call   */
  117.        iValue = GetSystemMetrics(SM_DEBUG);    /* the GetSystemMetrics */
  118.        if (iValue == 0)                        /* function.  Capture   */
  119.           sprintf(szbuf, "%s%s%s\0",           /* debug information    */
  120.                   "The Debugging Version ",     /* in a zero terminated */
  121.                   "of Windows is NOT ",         /* buffer.              */ 
  122.               "installed.");
  123.        else
  124.           sprintf(szbuf, "%s%s%s\0",
  125.                   "The Debugging Version ",
  126.                   "of Windows is ",
  127.                   "installed.");
  128.  
  129.         MessageBox(hWnd,                   /* Output the buffer in */
  130.                   (LPSTR)szbuf,                /* a message box format */
  131.                   (LPSTR)"GetSystemMetrics",   /* so that the user can */
  132.                    MB_OK);                 /* have a readable and  */
  133.        }                                       /* useful format.       */
  134.        break;
  135.  
  136.      case WM_CLOSE: {
  137.  
  138.           DestroyWindow(hWnd);
  139.        }
  140.          break;
  141.     
  142.     case WM_DESTROY:
  143.         PostQuitMessage(0);
  144.         break;
  145.  
  146.     default:
  147.         return(DefWindowProc(hWnd, identifier, wParam, lParam));
  148.         break;
  149.  
  150.    }
  151.  
  152.    return(0L);
  153.  
  154. }
  155.