home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / window / setwnpos.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  5KB  |  142 lines

  1. /*
  2.  *   SetWindowPos
  3.  *   setwnpos.c
  4.  *
  5.  *   This function changes the size, position, and ordering of child,
  6.  *   popup, and top-level windows.  Child, pop-up, and top-level windows
  7.  *   are ordered according to their appearance on the screen; the topmost
  8.  *   window receives the highest rank, and it is the first window in the
  9.  *   list.  This ordering is recorded in a window list.
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. /* Forward references */
  16.  
  17. BOOL FAR PASCAL SetWnPosInit( HANDLE );
  18.  
  19. long FAR PASCAL SetWnPosWndProc(HWND, unsigned, WORD, LONG);
  20.  
  21. /* ---------------------------------------------------------------------- */
  22.  
  23. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, CmdShow )
  24. HANDLE hInstance, hPrevInstance;
  25. LPSTR lpszCmdLine;
  26. int CmdShow;
  27. {
  28.     MSG   msg;
  29.     HWND  hParent, hPopup;
  30.     HMENU hMenu;
  31.  
  32.     SetWnPosInit( hInstance );
  33.     hParent = CreateWindow((LPSTR)"ShowOwnedPopups",
  34.             (LPSTR)"ShowOwnedPopups",
  35.             WS_OVERLAPPEDWINDOW,
  36.             CW_USEDEFAULT,
  37.             CW_USEDEFAULT,
  38.             CW_USEDEFAULT,
  39.             CW_USEDEFAULT,
  40.          (HWND)NULL,        /* no parent */
  41.          (HMENU)NULL,       /* use class menu */
  42.          (HANDLE)hInstance, /* handle to window instance */
  43.          (LPSTR)NULL        /* no params to pass on */
  44.          );
  45.  
  46.     /* Make window visible according to the way the app is activated */
  47.     ShowWindow( hParent, CmdShow );
  48.     UpdateWindow( hParent );
  49.  
  50. /* Create the popup window */
  51.  
  52.     hPopup = CreateWindow((LPSTR)"ShowOwnedPopups",
  53.                            (LPSTR)"Popup",
  54.                           WS_POPUP|WS_CAPTION|WS_VISIBLE,
  55.                             50,
  56.                             50,
  57.                             200,
  58.                             100,
  59.                          (HWND)hParent,     /* parent */
  60.                          (HMENU)NULL,       /* use class menu */
  61.                          (HANDLE)hInstance, /* handle to window instance */
  62.                          (LPSTR)NULL        /* no params to pass on */
  63.                         );
  64. /****************************************************************************/
  65. /* Begin SetWindowPos */
  66. /* I am about to move and resize the parent window */
  67.  
  68.     MessageBox (hParent, (LPSTR)"Move and resize the SetWindowPos window",
  69.                (LPSTR)"I'm about to ...", MB_OK);
  70.     SetWindowPos(hParent, hPopup, 100, 100, 200, 200, SWP_NOACTIVATE);
  71.  
  72. /* End of SetWindowPos section */
  73. /****************************************************************************/
  74.  
  75.     /* Polling messages from event queue */
  76.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  77.         TranslateMessage((LPMSG)&msg);
  78.         DispatchMessage((LPMSG)&msg);
  79.         }
  80.  
  81.     return (int)msg.wParam;
  82. }
  83.  
  84. /* ---------------------------------------------------------------------- */
  85. /* Procedure called when the application is loaded for the first time */
  86.  
  87. BOOL FAR PASCAL SetWnPosInit( hInstance )
  88. HANDLE hInstance;
  89. {
  90.     PWNDCLASS   pSetWnPosClass;
  91.  
  92.     pSetWnPosClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  93.  
  94.     pSetWnPosClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  95.     pSetWnPosClass->hIcon              = LoadIcon( hInstance,NULL);
  96.     pSetWnPosClass->lpszMenuName   = (LPSTR)NULL;
  97.     pSetWnPosClass->lpszClassName  = (LPSTR)"ShowOwnedPopups";
  98.     pSetWnPosClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  99.     pSetWnPosClass->hInstance      = hInstance;
  100.     pSetWnPosClass->style          = CS_HREDRAW | CS_VREDRAW;
  101.     pSetWnPosClass->lpfnWndProc    = SetWnPosWndProc;
  102.  
  103.     if (!RegisterClass( (LPWNDCLASS)pSetWnPosClass ) )
  104.         /* Initialization failed.
  105.          * Windows will automatically deallocate all allocated memory.
  106.          */
  107.         return FALSE;
  108.  
  109.     LocalFree( (HANDLE)pSetWnPosClass );
  110.     return TRUE;        /* Initialization succeeded */
  111. }
  112.  
  113.  
  114. /* ---------------------------------------------------------------------- */
  115. /* Every message for this window will be delevered right here.         */
  116.  
  117. long FAR PASCAL SetWnPosWndProc( hWnd, message, wParam, lParam )
  118. HWND hWnd;
  119. unsigned message;
  120. WORD wParam;
  121. LONG lParam;
  122. {
  123.     PAINTSTRUCT ps;
  124.  
  125.     switch (message)
  126.     {
  127.     case WM_DESTROY:
  128.         PostQuitMessage( 0 );
  129.         break;
  130.  
  131. /*    case WM_PAINT:
  132.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  133.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  134.         break; */
  135.  
  136.     default:
  137.         return DefWindowProc( hWnd, message, wParam, lParam );
  138.         break;
  139.     }
  140.     return(0L);
  141. }
  142.