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

  1. /*
  2.  *   ShowOwnedPopups
  3.  *   showpops.c
  4.  *
  5.  *   This program demonstrates the use of the function ShowOwnedPopups.
  6.  *   A pop-up window is initially shown visible.   At the same time a
  7.  *   message box appears.  When the message box is acknowledged then 
  8.  *   the pop-up window becomes invisible.  Another message box appears.
  9.  *   When the second message box is acknowledged then the pop-up window
  10.  *   becomes visible again.
  11.  *
  12.  */
  13.  
  14. #include "windows.h"
  15.  
  16. /* Forward references */
  17.  
  18. BOOL FAR PASCAL SampleInit( HANDLE );
  19.  
  20. long FAR PASCAL SampleWndProc(HWND, unsigned, WORD, LONG);
  21.  
  22. /* ---------------------------------------------------------------------- */
  23.  
  24. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, CmdShow )
  25. HANDLE hInstance, hPrevInstance;
  26. LPSTR lpszCmdLine;
  27. int CmdShow;
  28. {
  29.     MSG   msg;
  30.     HWND  hParent,hPopup;
  31.     HMENU hMenu;
  32.  
  33.     SampleInit( hInstance );
  34.     hParent = CreateWindow((LPSTR)"ShowOwnedPopups",
  35.             (LPSTR)"ShowOwnedPopups",
  36.             WS_OVERLAPPEDWINDOW,
  37.             CW_USEDEFAULT,
  38.             CW_USEDEFAULT,
  39.             CW_USEDEFAULT,
  40.             CW_USEDEFAULT,
  41.          (HWND)NULL,        /* no parent */
  42.          (HMENU)NULL,       /* use class menu */
  43.          (HANDLE)hInstance, /* handle to window instance */
  44.          (LPSTR)NULL        /* no params to pass on */
  45.          );
  46.  
  47.     /* Make window visible according to the way the app is activated */
  48.     ShowWindow( hParent, CmdShow );
  49.     UpdateWindow( hParent );
  50.  
  51. /* Create the popup window */
  52.  
  53.     hPopup = CreateWindow((LPSTR)"ShowOwnedPopups",
  54.                            (LPSTR)"Popup",
  55.                           WS_POPUP|WS_CAPTION|WS_VISIBLE,
  56.                             50,
  57.                             50,
  58.                             200,
  59.                             100,
  60.                          (HWND)hParent,     /* parent */
  61.                          (HMENU)NULL,       /* use class menu */
  62.                          (HANDLE)hInstance, /* handle to window instance */
  63.                          (LPSTR)NULL        /* no params to pass on */
  64.                         );
  65. /****************************************************************************/
  66. /* Begging of ShowOwnedPopups section */
  67.  
  68. /* void ShowOwnedPopups( hWnd, fShow ) 
  69.  *
  70.  * The first parameter 'hWnd' is the handle to the parent window that
  71.  * owns the pop-up.  The second parameter 'fShow' is nonzero if all
  72.  * hidden pop-up windows should be shown; it is zero if all visible
  73.  * pop-up windows should be hidden                                          */
  74.  
  75.     MessageBox (hParent, (LPSTR)"Hide the popup.",
  76.                (LPSTR)"Done", MB_OK);
  77.  
  78.     ShowOwnedPopups(hParent,FALSE);                /* Hide the popup */  
  79.  
  80.     MessageBox (hParent, (LPSTR)"Show the popup.",
  81.                  (LPSTR)"Done", MB_OK);
  82.  
  83.     ShowOwnedPopups(hParent,TRUE);                /* Show the popup */
  84.  
  85. /* End of ShowOwnedPopups section */
  86. /****************************************************************************/
  87.  
  88.     /* Polling messages from event queue */
  89.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  90.         TranslateMessage((LPMSG)&msg);
  91.         DispatchMessage((LPMSG)&msg);
  92.         }
  93.  
  94.     return (int)msg.wParam;
  95. }
  96.  
  97. /* ---------------------------------------------------------------------- */
  98. /* Procedure called when the application is loaded for the first time */
  99.  
  100. BOOL FAR PASCAL SampleInit( hInstance )
  101. HANDLE hInstance;
  102. {
  103.     PWNDCLASS   pSampleClass;
  104.  
  105.     pSampleClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  106.  
  107.     pSampleClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  108.     pSampleClass->hIcon              = LoadIcon( hInstance,NULL);
  109.     pSampleClass->lpszMenuName   = (LPSTR)NULL;
  110.     pSampleClass->lpszClassName  = (LPSTR)"ShowOwnedPopups";
  111.     pSampleClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  112.     pSampleClass->hInstance      = hInstance;
  113.     pSampleClass->style          = CS_HREDRAW | CS_VREDRAW;
  114.     pSampleClass->lpfnWndProc    = SampleWndProc;
  115.  
  116.     if (!RegisterClass( (LPWNDCLASS)pSampleClass ) )
  117.         /* Initialization failed.
  118.          * Windows will automatically deallocate all allocated memory.
  119.          */
  120.         return FALSE;
  121.  
  122.     LocalFree( (HANDLE)pSampleClass );
  123.     return TRUE;        /* Initialization succeeded */
  124. }
  125.  
  126.  
  127. /* ---------------------------------------------------------------------- */
  128. /* Every message for this window will be delevered right here.         */
  129.  
  130. long FAR PASCAL SampleWndProc( hWnd, message, wParam, lParam )
  131. HWND hWnd;
  132. unsigned message;
  133. WORD wParam;
  134. LONG lParam;
  135. {
  136.     PAINTSTRUCT ps;
  137.  
  138.     switch (message)
  139.     {
  140.     case WM_DESTROY:
  141.         PostQuitMessage( 0 );
  142.         break;
  143.  
  144. /*    case WM_PAINT:
  145.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  146.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  147.         break; */
  148.  
  149.     default:
  150.         return DefWindowProc( hWnd, message, wParam, lParam );
  151.         break;
  152.     }
  153.     return(0L);
  154. }
  155.