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

  1. /*
  2.  * GetActiveWindow
  3.  *
  4.  * This function obtains a handle to the active window.
  5.  *
  6.  */
  7.  
  8. #include <windows.h>
  9. #include "getactw.h"
  10.  
  11. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  12. HANDLE hInstance, hPrevInstance;
  13. LPSTR  lpszCmdLine;
  14. int    nCmdShow;
  15. {
  16.   HWND     hWnd;     /* Window handle.          */
  17.   WNDCLASS wndclass; /* Window class structure. */
  18.   MSG      msg;      /* Message structure.      */
  19.  
  20.   if (!hPrevInstance) 
  21.     {
  22.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  23.     wndclass.lpfnWndProc   = ActiveWndProc;
  24.     wndclass.cbClsExtra    = 0;
  25.     wndclass.cbWndExtra    = 0;
  26.     wndclass.hInstance     = hInstance;
  27.     wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  28.     wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  29.     wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  30.     wndclass.lpszMenuName  = (LPSTR)"getactw";
  31.     wndclass.lpszClassName = (LPSTR)"getactw";
  32.  
  33.     if (!RegisterClass(&wndclass))
  34.       return FALSE;
  35.     }
  36.  
  37.   hWnd = CreateWindow ((LPSTR)"getactw",
  38.                        (LPSTR)"GetActiveWindow",
  39.                        WS_OVERLAPPEDWINDOW,
  40.                        CW_USEDEFAULT, 0,
  41.                        CW_USEDEFAULT, 0,
  42.                        NULL, NULL,
  43.                        hInstance, NULL);
  44.  
  45.   ShowWindow(hWnd, nCmdShow);
  46.   UpdateWindow(hWnd);
  47.  
  48.   while (GetMessage(&msg, NULL, 0, 0))
  49.     {
  50.     TranslateMessage(&msg);
  51.     DispatchMessage(&msg);
  52.     } 
  53.   return (msg.wParam);
  54. }
  55.  
  56. long FAR PASCAL ActiveWndProc(hWnd, iMessage, wParam, lParam)
  57. HWND     hWnd;
  58. unsigned iMessage;
  59. WORD     wParam;
  60. LONG     lParam;
  61. {
  62.   HWND hWndActive; /* Handle to the active window. */
  63.  
  64.   switch(iMessage)
  65.     {
  66.      case WM_COMMAND:
  67.        switch (wParam)
  68.          {
  69.          int i; /* Loop Counter. */
  70.          case IDM_GETACTIVEW:
  71.            /* Get the active window and flash that handle. */
  72.            hWndActive = GetActiveWindow();
  73.            for (i = 0; i < 5; i++)
  74.              {
  75.              FlashWindow(hWndActive, FALSE);
  76.              MessageBeep(NULL);
  77.              }
  78.            break;
  79.  
  80.          default:
  81.            return DefWindowProc(hWnd, iMessage, wParam, lParam);
  82.            break;
  83.          }
  84.       break;
  85.  
  86.   case WM_DESTROY:
  87.     PostQuitMessage(0);
  88.     break;
  89.  
  90.   default:
  91.     return DefWindowProc(hWnd, iMessage, wParam, lParam);
  92.     break;
  93.   }
  94.   return (0L); 
  95. }
  96.  
  97.