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

  1. /*
  2.  *
  3.  *   qenabled.c
  4.  *
  5.  *   This program demonstrates the use of the IsWindowEnabled function.
  6.  *   IsWindowEnabled checks to see if the given window is enabled to receive
  7.  *   input. Each window in this application, if enabled, should display a
  8.  *   message box in response to a left button click. IsWindowEnabled is called
  9.  *   from WinMain in this sample application.
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long    FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  15. long    FAR PASCAL ChildAProc(HWND, unsigned, WORD, LONG);
  16. long    FAR PASCAL ChildBProc(HWND, unsigned, WORD, LONG);
  17.  
  18. HWND hChAWnd = NULL;
  19. HWND hChBWnd = NULL;
  20.  
  21.  
  22. int    PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  23. HANDLE     hInstance, hPrevInstance;
  24. LPSTR     lpszCmdLine;
  25. int    cmdShow;
  26. {
  27.   MSG        msg;
  28.   HWND        hWnd;
  29.   HMENU     hMenu;
  30.   BOOL        bEnabled;
  31.   WNDCLASS  wndclass;
  32.  
  33.   if (!hPrevInstance)
  34.   {
  35.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  36.     wndclass.lpfnWndProc     = WndProc;
  37.     wndclass.cbClsExtra     = 0;
  38.     wndclass.cbWndExtra     = 0;
  39.     wndclass.hInstance     = hInstance;
  40.     wndclass.hIcon         = NULL;
  41.     wndclass.hCursor     = LoadCursor(NULL, IDC_ARROW);
  42.     wndclass.hbrBackground     = GetStockObject(WHITE_BRUSH);
  43.     wndclass.lpszMenuName     = NULL;
  44.     wndclass.lpszClassName     = "Sample Application";
  45.  
  46.     if (!RegisterClass(&wndclass))
  47.       return FALSE;
  48.  
  49.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  50.     wndclass.lpfnWndProc     = ChildAProc;
  51.     wndclass.cbClsExtra     = 0;
  52.     wndclass.cbWndExtra     = 0;
  53.     wndclass.hInstance     = hInstance;
  54.     wndclass.hIcon         = NULL;
  55.     wndclass.hCursor     = LoadCursor(NULL, IDC_ARROW);
  56.     wndclass.hbrBackground     = GetStockObject(WHITE_BRUSH);
  57.     wndclass.lpszMenuName     = NULL;
  58.     wndclass.lpszClassName     = "CHILD A";
  59.  
  60.     if (!RegisterClass(&wndclass))
  61.       return FALSE;
  62.  
  63.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  64.     wndclass.lpfnWndProc     = ChildBProc;
  65.     wndclass.cbClsExtra     = 0;
  66.     wndclass.cbWndExtra     = 0;
  67.     wndclass.hInstance     = hInstance;
  68.     wndclass.hIcon         = NULL;
  69.     wndclass.hCursor     = LoadCursor(NULL, IDC_ARROW);
  70.     wndclass.hbrBackground     = GetStockObject(WHITE_BRUSH);
  71.     wndclass.lpszMenuName     = NULL;
  72.     wndclass.lpszClassName     = "CHILD B";
  73.  
  74.     if (!RegisterClass(&wndclass))
  75.       return FALSE;
  76.   }
  77.  
  78.   hWnd = CreateWindow("Sample Application",
  79.       "IsWindowEnabled",
  80.       WS_OVERLAPPEDWINDOW,
  81.       CW_USEDEFAULT,
  82.       CW_USEDEFAULT,
  83.       CW_USEDEFAULT,
  84.       CW_USEDEFAULT,
  85.       NULL,
  86.       NULL,
  87.       hInstance,
  88.       NULL);
  89.   ShowWindow(hWnd, cmdShow);
  90.   UpdateWindow(hWnd);
  91.  
  92.   hChAWnd = CreateWindow("CHILD A",
  93.       "Child A",
  94.       WS_CHILD | WS_SIZEBOX | WS_VISIBLE | WS_CAPTION | WS_CLIPSIBLINGS,
  95.       5,
  96.       5,
  97.       150,
  98.       150,
  99.       hWnd,
  100.       (HMENU)1,
  101.       hInstance,
  102.       NULL);
  103.  
  104.   hChBWnd = CreateWindow("CHILD B",
  105.       "Child B",
  106.       WS_CHILD | WS_SIZEBOX | WS_VISIBLE | WS_CAPTION | WS_CLIPSIBLINGS,
  107.       270,
  108.       5,
  109.       150,
  110.       150,
  111.       hWnd,
  112.       (HMENU)2,
  113.       hInstance,
  114.       NULL);
  115.  
  116.   MessageBox(hWnd,
  117.       "if Child A is enabled",
  118.       "I am going to see...",
  119.       MB_OK);
  120.   if (IsWindowEnabled(hChAWnd))
  121.     MessageBox(hWnd,
  122.         "Child A IS enabled",
  123.         "'IsWindowEnabled' says...",
  124.         MB_OK);
  125.   else
  126.     MessageBox(hWnd,
  127.         "Child A is NOT enabled",
  128.         "'IsWindowEnabled' says...",
  129.         MB_OK);
  130.   MessageBox(hWnd,
  131.       "disable Child B",
  132.       "I am going to...",
  133.       MB_OK);
  134.   EnableWindow(hChBWnd, FALSE);
  135.   MessageBox(hWnd,
  136.       "if Child B is enabled",
  137.       "I am going to see...",
  138.       MB_OK);
  139.   if (IsWindowEnabled(hChBWnd))
  140.     MessageBox(hWnd,
  141.         "Child B IS enabled",
  142.         "'IsWindowEnabled' says...",
  143.         MB_OK);
  144.   else
  145.     MessageBox(hWnd,
  146.         "Child B is NOT enabled",
  147.         "'IsWindowEnabled' says...",
  148.         MB_OK);
  149.  
  150.   while (GetMessage(&msg, NULL, 0, 0))
  151.   {
  152.     TranslateMessage(&msg);
  153.     DispatchMessage(&msg);
  154.   }
  155.  
  156.   return msg.wParam;
  157. }
  158.  
  159.  
  160. long    FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  161. HWND      hWnd;
  162. unsigned    message;
  163. WORD      wParam;
  164. LONG      lParam;
  165. {
  166.   switch (message)
  167.   {
  168.   case WM_LBUTTONDOWN:
  169.     {
  170.       MessageBox(hWnd,
  171.           "Left Button Click",
  172.           "PARENT WINDOW",
  173.           MB_OK);
  174.       break;
  175.     }
  176.   case WM_DESTROY:
  177.     {
  178.       PostQuitMessage(0);
  179.       break;
  180.     }
  181.   default:
  182.     return DefWindowProc(hWnd, message, wParam, lParam);
  183.   }
  184.   return(0L);
  185. }
  186.  
  187.  
  188. long    FAR PASCAL ChildAProc(hChAWnd, message, wParam, lParam)
  189. HWND hChAWnd;
  190. unsigned    message;
  191. WORD wParam;
  192. LONG lParam;
  193. {
  194.   PAINTSTRUCT ps;
  195.  
  196.   switch (message)
  197.   {
  198.  
  199.   case WM_LBUTTONDOWN:
  200.     MessageBox(hChAWnd, (LPSTR)"Left Button Click",
  201.         (LPSTR)"CHILD A",
  202.         MB_OK);
  203.     break;
  204.  
  205.   case WM_DESTROY:
  206.     PostQuitMessage(0);
  207.     break;
  208.  
  209.   case WM_PAINT:
  210.     BeginPaint(hChAWnd, (LPPAINTSTRUCT) & ps);
  211.     EndPaint(hChAWnd, (LPPAINTSTRUCT) & ps);
  212.     break;
  213.  
  214.   default:
  215.     return DefWindowProc(hChAWnd, message, wParam, lParam);
  216.     break;
  217.   }
  218.   return(0L);
  219. }
  220.  
  221.  
  222. long    FAR PASCAL ChildBProc(hChBWnd, message, wParam, lParam)
  223. HWND hChBWnd;
  224. unsigned    message;
  225. WORD wParam;
  226. LONG lParam;
  227. {
  228.   PAINTSTRUCT ps;
  229.  
  230.   switch (message)
  231.   {
  232.  
  233.   case WM_LBUTTONDOWN:
  234.     MessageBox(hChBWnd, (LPSTR)"Left Button Click",
  235.         (LPSTR)"CHILD B",
  236.         MB_OK);
  237.     break;
  238.  
  239.   case WM_DESTROY:
  240.     PostQuitMessage(0);
  241.     break;
  242.  
  243.   case WM_PAINT:
  244.     BeginPaint(hChBWnd, (LPPAINTSTRUCT) & ps);
  245.     EndPaint(hChBWnd, (LPPAINTSTRUCT) & ps);
  246.     break;
  247.  
  248.   default:
  249.     return DefWindowProc(hChBWnd, message, wParam, lParam);
  250.     break;
  251.   }
  252.   return(0L);
  253. }
  254.  
  255.  
  256.