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

  1. /*
  2.  *
  3.  *  Function demonstrated in this program: FlashWindow
  4.  *  Compiler version: C 5.1
  5.  *
  6.  *  This program demonstrates the use of the function FlashWin. This function    
  7.  *  "flashes" the given window once. Flashing window means changing the 
  8.  *  appearance of its caption bar or icon as if the window were changing form 
  9.  *  inactive to active status, or vice versa. (A grey caption bar or unframed
  10.  *  incon changes to a black caption bar or framed icon; a black caption bar 
  11.  *  or framed icon changes to a grey caption bar or unframed icon.)
  12.  *
  13.  */
  14.  
  15. #include <windows.h>
  16.  
  17. LONG FAR PASCAL WindowProc (HANDLE, unsigned, WORD, LONG);
  18.  
  19. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  20. HANDLE hInstance, hPrevInstance;
  21. LPSTR  lpszCmdLine;
  22. int    cmdShow;
  23.   {
  24.   MSG  msg;
  25.   HWND hWnd;
  26.   HMENU hMenu;
  27.  
  28.   if (!hPrevInstance)
  29.     {
  30.     WNDCLASS rClass;
  31.  
  32.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  33.     rClass.lpfnWndProc   = WindowProc;
  34.     rClass.cbClsExtra    = 0;
  35.     rClass.cbWndExtra    = 0;
  36.     rClass.hInstance     = hInstance;
  37.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  38.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  39.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  40.     rClass.lpszMenuName  = (LPSTR) NULL;
  41.     rClass.lpszClassName = (LPSTR) "flashwin";
  42.  
  43.     if (!RegisterClass ( ( LPWNDCLASS) &rClass))
  44.       return FALSE;
  45.     }
  46.  
  47.   hMenu = CreateMenu ();
  48.   ChangeMenu (hMenu, NULL, "Flash!", 100, MF_APPEND);
  49.  
  50.   hWnd = CreateWindow ( (LPSTR) "flashwin", (LPSTR) "FlashWindow",
  51.                       WS_OVERLAPPEDWINDOW,
  52.                       CW_USEDEFAULT, CW_USEDEFAULT,
  53.                       CW_USEDEFAULT, CW_USEDEFAULT,
  54.                       (HWND) NULL, (HMENU) hMenu,
  55.                       (HANDLE) hInstance, (LPSTR) NULL);
  56.  
  57.   ShowWindow (hWnd, cmdShow);
  58.   UpdateWindow (hWnd);
  59.   
  60.   while (GetMessage ( (LPMSG)&msg, NULL, 0, 0))
  61.     {
  62.     TranslateMessage ( (LPMSG)&msg);
  63.     DispatchMessage ( (LPMSG)&msg);
  64.     }
  65.   exit (msg.wParam);
  66.   }
  67.  
  68. long FAR PASCAL WindowProc (hWnd, message, wParam, lParam)
  69. HWND        hWnd;
  70. unsigned    message;
  71. WORD        wParam;
  72. LONG        lParam;
  73.   {
  74.   static BOOL bInverted = TRUE;  /* To keep track of Active State of Window */
  75.  
  76.   switch (message)
  77.     {
  78.     case WM_COMMAND:
  79.       if (wParam == 100)
  80.         FlashWindow (hWnd, TRUE);
  81.       else
  82.         return (DefWindowProc (hWnd, message, wParam, lParam));
  83.       break;
  84.  
  85.     case WM_DESTROY:
  86.       PostQuitMessage (0);
  87.       break;
  88.  
  89.     default:
  90.       return (DefWindowProc (hWnd, message, wParam, lParam));
  91.       break;
  92.     }
  93.   return (0L);
  94.   }
  95.