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

  1. /*
  2.  *  Function Name:   EnableHardwareInput
  3.  *  Program Name:    enhardin.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.0
  7.  *
  8.  *  Description:
  9.  *   This function can disable the mouse and keyboard input.
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  15.  
  16. /***********************************************************************/
  17.  
  18. void CALL_EnableHardwareInput(hWnd)
  19. HWND hWnd;
  20. {
  21.   BOOL      bEnableInput;
  22.  
  23.   bEnableInput = EnableHardwareInput (TRUE);
  24.                                       /* save input specified, else   */
  25.   if (bEnableInput == TRUE)           /* mouse and keyboard diasbled  */
  26.     MessageBox(hWnd,(LPSTR)"mouse & keyboard enabled",
  27.               (LPSTR)"EnableHardwareInput", MB_OK);
  28.   else
  29.     MessageBox(hWnd,(LPSTR)"mouse & keyboard disabled",
  30.               (LPSTR)"EnableHardwareInput", MB_OK);
  31.  
  32.   return;
  33. }
  34.  
  35. /**************************************************************************/
  36.  
  37. /* Procedure called when the application is loaded for the first time */
  38. BOOL WinInit( hInstance )
  39. HANDLE hInstance;
  40. {
  41.     WNDCLASS   wcClass;
  42.  
  43.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  44.     wcClass.lpfnWndProc    = WndProc;
  45.     wcClass.cbClsExtra     =0;
  46.     wcClass.cbWndExtra     =0;
  47.     wcClass.hInstance      = hInstance;
  48.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  49.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  50.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  51.     wcClass.lpszMenuName   = (LPSTR)NULL;
  52.     wcClass.lpszClassName  = (LPSTR)"EnableHardwareInput";
  53.  
  54.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  55.         /* Initialization failed.
  56.          * Windows will automatically deallocate all allocated memory.
  57.          */
  58.         return FALSE;
  59.  
  60.     return TRUE;        /* Initialization succeeded */
  61. }
  62.  
  63.  
  64. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  65. HANDLE hInstance, hPrevInstance;
  66. LPSTR lpszCmdLine;
  67. int cmdShow;
  68. {
  69.     MSG   msg;
  70.     HWND  hWnd;
  71.  
  72.     if (!hPrevInstance)
  73.         {
  74.         /* Call initialization procedure if this is the first instance */
  75.         if (!WinInit( hInstance ))
  76.             return FALSE;
  77.         }
  78.  
  79.     hWnd = CreateWindow((LPSTR)"EnableHardwareInput",
  80.                         (LPSTR)"EnableHardwareInput()",
  81.                         WS_OVERLAPPEDWINDOW,
  82.                         CW_USEDEFAULT,
  83.                         CW_USEDEFAULT,
  84.                         CW_USEDEFAULT,
  85.                         CW_USEDEFAULT,
  86.                         (HWND)NULL,        /* no parent */
  87.                         (HMENU)NULL,       /* use class menu */
  88.                         (HANDLE)hInstance, /* handle to window instance */
  89.                         (LPSTR)NULL        /* no params to pass on */
  90.                         );
  91.  
  92.     /* Make window visible according to the way the app is activated */
  93.     ShowWindow( hWnd, cmdShow );
  94.     UpdateWindow( hWnd );
  95.  
  96.     /* Polling messages from event queue */
  97.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  98.         {
  99.         TranslateMessage((LPMSG)&msg);
  100.         DispatchMessage((LPMSG)&msg);
  101.         }
  102.  
  103.     return (int)msg.wParam;
  104. }
  105.  
  106. /* Procedures which make up the window class. */
  107. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  108. HWND hWnd;
  109. unsigned message;
  110. WORD wParam;
  111. LONG lParam;
  112. {
  113.     PAINTSTRUCT ps;
  114.  
  115.     switch (message)
  116.     {
  117.  
  118.     case WM_PAINT:
  119.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  120.         CALL_EnableHardwareInput(hWnd);
  121.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  122.         break;
  123.  
  124.     case WM_DESTROY:
  125.         PostQuitMessage( 0 );
  126.         break;
  127.  
  128.     default:
  129.         return DefWindowProc( hWnd, message, wParam, lParam );
  130.         break;
  131.     }
  132.     return(0L);
  133. }
  134.