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

  1. /*
  2.  *
  3.  * Function (s) demonstrated in this program: CloseWindow
  4.  *
  5.  * Description:  This function makes a window iconic
  6.  *
  7.  */
  8.  
  9. #define NOMINMAX
  10. #include <windows.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include "CloseWin.h"
  14.  
  15. HWND     hWndMain;
  16. HANDLE   hInstMain;
  17.  
  18. char    szOutputBuffer1 [70];
  19. char    szOutputBuffer2 [500];
  20.  
  21. struct   {
  22.   char    *szMessage; 
  23.   } Messages [] =   {
  24.   "About\0",
  25.   "     This is a sample application to demonstrate the\n\
  26. use of the CloseWindow Windows function.",
  27.  
  28.   "Help Message",
  29.   "     This program uses the CloseWindow Windows\n\
  30. function to minimize this window, the window is\n\
  31. then restored to its original state.  Use the menu\n\
  32. to test this function.",
  33.  
  34.   };
  35.  
  36. /****************************************************************************/
  37.  
  38. void ProcessMessage (HWND, int);
  39.  
  40. void ProcessMessage (hWnd, MessageNumber)
  41. HWND     hWnd;
  42. int    MessageNumber;
  43.   {
  44.   sprintf (szOutputBuffer1, "%s", Messages [MessageNumber]);
  45.   sprintf (szOutputBuffer2, "%s", Messages [MessageNumber + 1]);
  46.   MessageBox (hWnd, szOutputBuffer2, szOutputBuffer1, MB_OK);
  47.   }
  48.  
  49. /****************************************************************************/
  50.  
  51. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  52. HANDLE      hInstance, hPrevInstance;
  53. LPSTR       lpszCmdLine;
  54. int     nCmdShow;
  55.   {
  56.   static char   szAppName [] = "CloseWin";
  57.   HWND        hWnd;
  58.   WNDCLASS    wndclass;
  59.   MSG msg;
  60.  
  61.   if (!hPrevInstance)
  62.     {
  63.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  64.     wndclass.lpfnWndProc   = WndProc;
  65.     wndclass.cbClsExtra    = 0;
  66.     wndclass.cbWndExtra    = 0;
  67.     wndclass.hInstance     = hInstance;
  68.     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  69.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  70.     wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  71.     wndclass.lpszMenuName  = szAppName;
  72.     wndclass.lpszClassName = szAppName;
  73.  
  74.     if (!RegisterClass (&wndclass))
  75.       return FALSE;
  76.     }
  77.  
  78. hWndMain = CreateWindow (szAppName,        /* window class name       */
  79.                         "CloseWindow",              /* window caption          */
  80.                         WS_OVERLAPPEDWINDOW,        /* window style            */
  81.                         CW_USEDEFAULT,              /* initial x position      */
  82.                         0,                          /* initial y position      */
  83.                         CW_USEDEFAULT,              /* initial x size          */
  84.                         0,                          /* initial y size          */
  85.                         NULL,                       /* parent window handle    */
  86.                         NULL,                       /* window menu handle      */
  87.                         hInstance,                  /* program instance handle */
  88.                         NULL);                     /* create parameters       */
  89.  
  90.   ShowWindow (hWndMain, nCmdShow);
  91.   UpdateWindow (hWndMain);
  92.  
  93.   hInstMain = hInstance;
  94.  
  95.   while (GetMessage (&msg, NULL, 0, 0))
  96.     {
  97.     TranslateMessage (&msg);
  98.     DispatchMessage (&msg);
  99.     }
  100.   return (msg.wParam);
  101.   }
  102.  
  103. /****************************************************************************/
  104.  
  105. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  106. HWND     hWnd;
  107. unsigned iMessage;
  108. WORD     wParam;
  109. LONG     lParam;
  110.   {
  111.   HMENU       hMenu;
  112.  
  113.   switch (iMessage)
  114.     {
  115.     case WM_CREATE:
  116.       hMenu = GetSystemMenu (hWnd, FALSE);
  117.       ChangeMenu (hMenu, NULL, "&About", IDM_ABOUT, MF_APPEND | MF_STRING);
  118.       break;
  119.  
  120.     case WM_SYSCOMMAND:
  121.       switch (wParam)
  122.         {
  123.         case IDM_ABOUT:
  124.           ProcessMessage (hWnd, 0);
  125.           break;
  126.         default:
  127.           return DefWindowProc (hWnd, iMessage, wParam, lParam);
  128.         }
  129.       break;
  130.  
  131.     case WM_COMMAND:
  132.       switch (wParam)
  133.         {
  134.         case IDM_CLOSEWINDOW:
  135.           MessageBox (hWnd, "About to Use CloseWindow", "CloseWindow", MB_OK);
  136.           CloseWindow (hWnd);
  137.           MessageBox (hWnd, "Restoring window to original state",
  138.                       "CloseWindow", MB_OK);
  139.           SendMessage (hWnd, WM_SYSCOMMAND, SC_RESTORE, 0L);
  140.           break;
  141.  
  142.         case IDM_HELP:
  143.           ProcessMessage (hWnd, 2);
  144.           break;
  145.         }
  146.       break;
  147.  
  148.     case WM_DESTROY:
  149.       PostQuitMessage (0);
  150.       break;
  151.  
  152.     default:
  153.       return DefWindowProc (hWnd, iMessage, wParam, lParam);
  154.     }
  155.   return (0L);
  156.   }
  157.