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

  1. /*
  2.  *   IsIconic
  3.  *
  4.  *   This program demonstrates the use of the IsIconic function. The
  5.  *   IsIconic function returns a boolean telling whether the  specified
  6.  *   window is iconic. Choosing the "Iconic?" option in the system menu
  7.  *   enacts the call to IsIconic in this sample application.
  8.  */
  9.  
  10. #include "windows.h"
  11. #define IDSABOUT 200
  12.  
  13. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  14.  
  15.  
  16. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  17. HANDLE hInstance, hPrevInstance;
  18. LPSTR lpszCmdLine;
  19. int    cmdShow;
  20.   {
  21.   MSG   msg;
  22.   HWND  hWnd;
  23.   HMENU hMenu;
  24.   PWNDCLASS   pHelloClass;
  25.  
  26.   pHelloClass = (PWNDCLASS)LocalAlloc (LPTR, sizeof (WNDCLASS));
  27.  
  28.   pHelloClass->hCursor        = LoadCursor (NULL, IDC_ARROW);
  29.   pHelloClass->hIcon             = LoadIcon (hInstance, NULL);
  30.   pHelloClass->lpszMenuName   = (LPSTR)NULL;
  31.   pHelloClass->lpszClassName     = (LPSTR)"Sample Application";
  32.   pHelloClass->hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  33.   pHelloClass->hInstance      = hInstance;
  34.   pHelloClass->style          = CS_HREDRAW | CS_VREDRAW;
  35.   pHelloClass->lpfnWndProc    = HelloWndProc;
  36.  
  37.   if (!RegisterClass ( (LPWNDCLASS)pHelloClass))
  38.     return FALSE;
  39.  
  40.   LocalFree ( (HANDLE)pHelloClass);
  41.  
  42.   hWnd = CreateWindow ( (LPSTR)"Sample Application", (LPSTR)"Sample Application",
  43.                       WS_OVERLAPPEDWINDOW,
  44.                       CW_USEDEFAULT, 0,
  45.                       CW_USEDEFAULT, 0,
  46.                       NULL,     NULL, hInstance, NULL);
  47.  
  48. /* Insert "Iconic?" into system menu */
  49.   hMenu = GetSystemMenu (hWnd, FALSE);
  50.   ChangeMenu (hMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
  51.   ChangeMenu (hMenu, 0, (LPSTR)"Iconic?", IDSABOUT, MF_APPEND | MF_STRING);
  52.  
  53.   ShowWindow (hWnd, cmdShow);
  54.   UpdateWindow (hWnd);
  55.  
  56.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  57.     {
  58.     TranslateMessage ( (LPMSG) & msg);
  59.     DispatchMessage ( (LPMSG) & msg);
  60.     }
  61.   return (int)msg.wParam;
  62.   }
  63.  
  64. /* Procedures which make up the window class. */
  65. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  66. HWND hWnd;
  67. unsigned    message;
  68. WORD wParam;
  69. LONG lParam;
  70.   {
  71.   BOOL icon;     /** holds return value from call to IsIconic **/
  72.  
  73.   switch (message)
  74.     {
  75.     case WM_SYSCOMMAND:
  76.       switch (wParam)
  77.         {
  78.         case IDSABOUT:
  79.           icon = IsIconic (hWnd);    /**  is window iconic ?     **/
  80.           if (icon)       /**  if yes, say so         **/
  81.             MessageBox (hWnd, (LPSTR)"This window is iconic",
  82.                 (LPSTR)"ICONIC INFO", MB_OK);
  83.           else /**  if window not iconic, say so  **/
  84.             MessageBox (hWnd, (LPSTR)"This window is NOT iconic",
  85.                 (LPSTR)"ICONIC INFO", MB_OK);
  86.           break;
  87.         default:
  88.           return DefWindowProc (hWnd, message, wParam, lParam);
  89.         }
  90.       break;
  91.  
  92.     case WM_DESTROY:
  93.       PostQuitMessage (0);
  94.       break;
  95.  
  96.     default:
  97.       return DefWindowProc (hWnd, message, wParam, lParam);
  98.       break;
  99.     }
  100.   return (0L);
  101.   }
  102.