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

  1. /*
  2.  *  This program demonstrates the use of the function BringWindowToTop.
  3.  *  It brings a popup style or child style window to the top of a stack
  4.  *  of overlapping windows. 
  5.  */
  6.  
  7. #include "windows.h"
  8.  
  9. /* Registering the parent and child window classes */
  10. BOOL WinInit( hInstance )
  11. HANDLE hInstance;
  12. {
  13.   WNDCLASS   wcParentClass, wcChildClass;
  14.  
  15. /* registering the parent window class */
  16.   wcParentClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  17.   wcParentClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  18.   wcParentClass.lpszMenuName   = (LPSTR)NULL;
  19.   wcParentClass.lpszClassName  = (LPSTR)"Parent";
  20.   wcParentClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  21.   wcParentClass.hInstance      = hInstance;
  22.   wcParentClass.style          = CS_HREDRAW | CS_VREDRAW;
  23.   wcParentClass.lpfnWndProc    = DefWindowProc;
  24.   wcParentClass.cbClsExtra     = 0;
  25.   wcParentClass.cbWndExtra     = 0;
  26.  
  27.   RegisterClass( (LPWNDCLASS) & wcParentClass );
  28.  
  29. /* registering the child window class */
  30.   wcChildClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  31.   wcChildClass.hIcon          = (HICON)NULL;
  32.   wcChildClass.lpszMenuName   = (LPSTR)NULL;
  33.   wcChildClass.lpszClassName  = (LPSTR)"Child";
  34.   wcChildClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  35.   wcChildClass.hInstance      = hInstance;
  36.   wcChildClass.style          = CS_HREDRAW | CS_VREDRAW;
  37.   wcChildClass.lpfnWndProc    = DefWindowProc;
  38.   wcChildClass.cbClsExtra     = 0;
  39.   wcChildClass.cbWndExtra     = 0;
  40.  
  41.   RegisterClass( (LPWNDCLASS) & wcChildClass );
  42.   return TRUE;        /* Initialization succeeded */
  43. }
  44.  
  45.  
  46. int    PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  47. HANDLE hInstance, hPrevInstance;
  48. LPSTR lpszCmdLine;
  49. int    cmdShow;
  50. {
  51.   HWND  hParent, hChild1, hChild2;     /* Handles to the windows */
  52.  
  53.   WinInit (hInstance);
  54.  
  55. /* creating the parent window */
  56.   hParent = CreateWindow((LPSTR)"Parent",
  57.       (LPSTR)"Parent Window",
  58.       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  59.     50,                /* x         */
  60. 50,                /* y         */
  61. 600,               /* width     */
  62. 250,               /* height    */
  63.   (HWND)NULL,        /* no parent */
  64.   (HMENU)NULL,       /* use class menu */
  65.   (HANDLE)hInstance, /* handle to window instance */
  66.   (LPSTR)NULL        /* no params to pass on */
  67.   );
  68.  
  69. /* Make window visible according to the way the app is activated */
  70.   ShowWindow( hParent, cmdShow );
  71.   UpdateWindow( hParent );
  72.  
  73. /* creating the child windows */
  74.   hChild1 = CreateWindow ((LPSTR) "Child",
  75.       (LPSTR) "Child #1",
  76.       WS_CHILD | WS_CLIPSIBLINGS | WS_CAPTION | WS_VISIBLE,
  77.     50,                 /* x         */
  78. 50,                 /* y         */
  79. 100,                /* width     */
  80. 50,                 /* height    */
  81.   (HWND) hParent,     /* parent of this window   */
  82.   (HMENU) 1,          /* child window identifier */
  83.   (HANDLE) hInstance, /* handle to window instance */
  84.   (LPSTR) NULL);      /* no params to pass on    */
  85.  
  86.   hChild2 = CreateWindow ((LPSTR) "Child",
  87.       (LPSTR) "Child #2",
  88.       WS_CHILD | WS_CLIPSIBLINGS | WS_CAPTION | WS_VISIBLE,
  89.     60,                 /* x          */
  90. 60,                 /* y          */
  91. 100,                /* width      */
  92. 50,                 /* height     */
  93.   (HWND) hParent,     /* parent of this window   */
  94.   (HMENU) 2,          /* child window identifier */
  95.   (HANDLE) hInstance, /* handle to window instance */
  96.   (LPSTR) NULL);      /* no params to pass on    */
  97.  
  98.  
  99. /* Bring the bottom window to the top */
  100.   MessageBox (hParent, (LPSTR)"Before bringing the bottom window up",
  101.       (LPSTR)"Ready ?", MB_OK);
  102.  
  103.   BringWindowToTop (hChild2);
  104.  
  105.   MessageBox (hParent, (LPSTR)"Child #2 has been brought up!",
  106.       (LPSTR)"Done", MB_OK);
  107.  
  108.   return 0;
  109. }
  110.  
  111.  
  112.