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

  1. /*
  2.  *
  3.  *   qvisible.c
  4.  *
  5.  *   This program demonstrates the use of the IsWindowVisible function.
  6.  */
  7.  
  8. #include "windows.h"
  9.  
  10. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  11. long    FAR PASCAL ChildProc (HWND, unsigned, WORD, LONG);
  12.  
  13. HWND hChildWnd = NULL;
  14.  
  15. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE     hInstance, hPrevInstance;
  17. LPSTR      lpszCmdLine;
  18. int        cmdShow;
  19.   {
  20.   MSG        msg;
  21.   HWND        hWnd;
  22.   HMENU     hMenu;
  23.   WNDCLASS  wndclass;
  24.  
  25.   if (!hPrevInstance)
  26.     {
  27.     wndclass.style        = CS_HREDRAW | CS_VREDRAW;
  28.     wndclass.lpfnWndProc    = WndProc;
  29.     wndclass.cbClsExtra     = 0;
  30.     wndclass.cbWndExtra     = 0;
  31.     wndclass.hInstance        = hInstance;
  32.     wndclass.hIcon        = NULL;
  33.     wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  34.     wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);
  35.     wndclass.lpszMenuName   = NULL;
  36.     wndclass.lpszClassName  = "Sample Application";
  37.  
  38.     if (!RegisterClass (&wndclass))
  39.       return FALSE;
  40.  
  41.     wndclass.style        = CS_HREDRAW | CS_VREDRAW;
  42.     wndclass.lpfnWndProc    = ChildProc;
  43.     wndclass.cbClsExtra     = 0;
  44.     wndclass.cbWndExtra     = 0;
  45.     wndclass.hInstance        = hInstance;
  46.     wndclass.hIcon        = NULL;
  47.     wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  48.     wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);
  49.     wndclass.lpszMenuName   = NULL;
  50.     wndclass.lpszClassName  = "CHILD";
  51.  
  52.     if (!RegisterClass (&wndclass))
  53.       return FALSE;
  54.     }
  55.  
  56.   hWnd = CreateWindow ("Sample Application",
  57.       "IsWindowVisible",
  58.       WS_OVERLAPPEDWINDOW,
  59.       CW_USEDEFAULT,
  60.       CW_USEDEFAULT,
  61.       CW_USEDEFAULT,
  62.       CW_USEDEFAULT,
  63.       NULL,
  64.       NULL,
  65.       hInstance,
  66.       NULL);
  67.  
  68.   ShowWindow (hWnd, cmdShow);
  69.   UpdateWindow (hWnd);
  70.  
  71.   hChildWnd = CreateWindow ("CHILD",
  72.       "Child",
  73.       WS_CHILD | WS_SIZEBOX | WS_CAPTION | WS_CLIPSIBLINGS,
  74.       5,
  75.       5,
  76.       150,
  77.       150,
  78.       hWnd,
  79.       (HMENU)1,
  80.       hInstance,
  81.       NULL);
  82.  
  83.   MessageBox (hWnd, "the child window is visible", "I am going to see if...",
  84.              MB_OK);
  85.   if (IsWindowVisible (hChildWnd))
  86.     MessageBox (hWnd, "the child window IS visible",
  87.         "'IsWindowVisible' says...", MB_OK);
  88.   else
  89.     MessageBox (hWnd, "the child window is NOT visible",
  90.         "'IsWindowVisible' says...", MB_OK);
  91.  
  92.   ShowWindow (hChildWnd, SW_SHOWNORMAL);
  93.  
  94.   MessageBox (hWnd, "the child window is visible",
  95.              "I am going to see if...", MB_OK);
  96.  
  97.   if (IsWindowVisible (hChildWnd))
  98.     MessageBox (hWnd, "the child window IS visible",
  99.         "'IsWindowVisible' says...", MB_OK);
  100.   else
  101.     MessageBox (hWnd, "the child window is NOT visible",
  102.                 "'IsWindowVisible' says...", MB_OK);
  103.  
  104.   while (GetMessage (&msg, NULL, 0, 0))
  105.     {
  106.     TranslateMessage (&msg);
  107.     DispatchMessage (&msg);
  108.     }
  109.   return msg.wParam;
  110.   }
  111.  
  112.  
  113. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  114. HWND      hWnd;
  115. unsigned  message;
  116. WORD      wParam;
  117. LONG      lParam;
  118.   {
  119.   switch (message)
  120.     {
  121.     case WM_LBUTTONDOWN:
  122.       MessageBox (hWnd, "Left Button Click", "PARENT WINDOW", MB_OK);
  123.       break;
  124.  
  125.     case WM_DESTROY:
  126.       PostQuitMessage (0);
  127.       break;
  128.  
  129.     default:
  130.       return DefWindowProc (hWnd, message, wParam, lParam);
  131.     }
  132.   return (0L);
  133.   }
  134.  
  135. long    FAR PASCAL ChildProc (hChildWnd, message, wParam, lParam)
  136. HWND      hChildWnd;
  137. unsigned  message;
  138. WORD      wParam;
  139. LONG      lParam;
  140.   {
  141.   switch (message)
  142.     {
  143.     case WM_LBUTTONDOWN:
  144.       MessageBox (hChildWnd, (LPSTR)"Left Button Click", (LPSTR)"CHILD A",
  145.                   MB_OK);
  146.       break;
  147.  
  148.     case WM_DESTROY:
  149.       PostQuitMessage (0);
  150.       break;
  151.  
  152.     default:
  153.       return DefWindowProc (hChildWnd, message, wParam, lParam);
  154.       break;
  155.     }
  156.   return (0L);
  157.   }
  158.