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

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