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

  1. /*
  2.  *  SetActiveWindow
  3.  *  setactwn.c,
  4.  *
  5.  *  This program demonstrates the use of the function SetActiveWindow.
  6.  *  It makes a tiled window or popup style window the active window. 
  7.  *
  8.  */
  9.  
  10. #include "windows.h"
  11.  
  12. /* Procedure called when the application is loaded for the first time */
  13. BOOL WinInit( hInstance )
  14. HANDLE hInstance;
  15. {
  16.     WNDCLASS   wcClass;
  17.  
  18.     /* registering the parent window class */
  19.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  20.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  21.     wcClass.lpszMenuName   = (LPSTR)NULL;
  22.     wcClass.lpszClassName  = (LPSTR)"Setactwn";
  23.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  24.     wcClass.hInstance      = hInstance;
  25.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  26.     wcClass.lpfnWndProc    = DefWindowProc;
  27.     wcClass.cbClsExtra     = 0;
  28.     wcClass.cbWndExtra     = 0;
  29.  
  30.     RegisterClass( (LPWNDCLASS)&wcClass );
  31.     return TRUE;        /* Initialization succeeded */
  32. }
  33.  
  34.  
  35. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  36. HANDLE hInstance, hPrevInstance;
  37. LPSTR lpszCmdLine;
  38. int cmdShow;
  39. {
  40.     MSG          msg;                 /* Window messages                */
  41.     HWND         hWnd;                /* Handle to the parent window    */
  42.     HDC          hDC;                 /* Display context of client area */
  43.  
  44.     WinInit (hInstance);
  45.  
  46.     hWnd = CreateWindow((LPSTR)"Setactwn",
  47.                         (LPSTR)"Active Window",
  48.                         WS_OVERLAPPEDWINDOW,
  49.                         50,                /* x         */
  50.                         50,                /* y         */
  51.                         600,               /* width     */
  52.                         250,               /* height    */
  53.                         (HWND)NULL,        /* no parent */
  54.                         (HMENU)NULL,       /* use class menu */
  55.                         (HANDLE)hInstance, /* handle to window instance */
  56.                         (LPSTR)NULL        /* no params to pass on */
  57.                        );
  58.  
  59.     /* Make window visible according to the way the app is activated */
  60.     ShowWindow( hWnd, cmdShow );
  61.     UpdateWindow( hWnd );
  62.  
  63.     /* Message Box will make the parent window inactive */
  64.     MessageBox (hWnd, (LPSTR)"The window is not active\n(Look at the caption bar)", 
  65.                 (LPSTR)"Before", MB_OK);
  66.  
  67.     /* make the window becomes the active window */
  68.     SetActiveWindow (hWnd);
  69.     hDC = GetDC (hWnd);
  70.     TextOut (hDC, 10, 10, (LPSTR)" Now this window is active.", 26);
  71.     ReleaseDC (hWnd, hDC);
  72.  
  73.     /* Polling messages from event queue */
  74.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  75.       { 
  76.         TranslateMessage ((LPMSG)&msg);
  77.         DispatchMessage  ((LPMSG)&msg);
  78.       }
  79.  
  80.     return (int)msg.wParam;
  81. }
  82.