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

  1. /*
  2.  * Function (s) demonstrated in this program: OpenIcon
  3.  *
  4.  * Description:
  5.  * This sample program demonstrates how to use the OpenIcon Windows
  6.  * function.  Two windows are created.  The first window is initially
  7.  * displayed as an open window.  The second window is initially
  8.  * displayed as an iconized window.  After both windows are created and
  9.  * displayed then a message box prompts the user to press return.  Upon
  10.  * receiving <RETURN>, The message box closes.  This is followed by a
  11.  * call to the function OpenIcon which opens the iconized window.
  12.  *
  13.  */
  14.  
  15. #include <windows.h>
  16. #include <string.h>
  17. #include "openicon.h"
  18.  
  19. long    FAR PASCAL WndProc1 (HWND, unsigned, WORD, LONG);
  20. long    FAR PASCAL WndProc2 (HWND, unsigned, WORD, LONG);
  21.  
  22. static char     szAppName1 [] = "OpenIcon, window number 1";
  23. static char     szAppName2 [] = "OpenIcon, window number 2";
  24. static char    szResName [] = "ResMenu";
  25. static HWND hWnd1, hWnd2;
  26.  
  27. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  28. HANDLE      hInstance, hPrevInstance;
  29. LPSTR       lpszCmdLine;
  30. int    nCmdShow;
  31.   {
  32.   WNDCLASS wndclass;
  33.   MSG      msg;
  34.   HDC      hDC;
  35.   HMENU    hMenu;
  36.  
  37.   if (!hPrevInstance)
  38.     {
  39.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  40.     wndclass.lpfnWndProc   = WndProc1;
  41.     wndclass.cbClsExtra    = 0;
  42.     wndclass.cbWndExtra    = 0;
  43.     wndclass.hInstance     = hInstance;
  44.     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  45.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  46.     wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  47.     wndclass.lpszMenuName  = NULL;
  48.     wndclass.lpszClassName = szAppName1;
  49.  
  50.     if (!RegisterClass (&wndclass))
  51.       return FALSE;
  52.  
  53.     wndclass.lpfnWndProc   = WndProc2;
  54.     wndclass.lpszClassName = szAppName2;
  55.  
  56.     if (!RegisterClass (&wndclass))
  57.       return FALSE;
  58.     }
  59.  
  60.   hMenu = LoadMenu (hInstance, "ResMenu");
  61.  
  62.   hWnd1 = CreateWindow (szAppName1, szAppName1,
  63.                        WS_OVERLAPPEDWINDOW,
  64.                        CW_USEDEFAULT, 0,
  65.                        CW_USEDEFAULT, 0,
  66.                        NULL, hMenu, hInstance, NULL);
  67.  
  68.   ShowWindow (hWnd1, nCmdShow);
  69.   UpdateWindow (hWnd1);
  70.  
  71.   hWnd2 = CreateWindow (szAppName2, szAppName2,
  72.                        WS_OVERLAPPEDWINDOW,
  73.                        CW_USEDEFAULT, 0,
  74.                        CW_USEDEFAULT, 0,
  75.                        NULL, NULL, hInstance, NULL);
  76.  
  77.   ShowWindow (hWnd2, SW_MINIMIZE);
  78.  
  79.   while (GetMessage (&msg, NULL, 0, 0))
  80.     {
  81.     TranslateMessage (&msg);
  82.     DispatchMessage (&msg);
  83.     }
  84.   return (msg.wParam);
  85.   }
  86.  
  87. long    FAR PASCAL WndProc1 (hWnd1, iMessage, wParam, lParam)
  88. HWND     hWnd1;
  89. unsigned iMessage;
  90. WORD     wParam;
  91. LONG     lParam;
  92.   {
  93.   switch (iMessage)
  94.     {
  95.     case WM_COMMAND:
  96.       if (wParam == IDM_EXECUTE)
  97.         OpenIcon (hWnd2);                /* Open the iconized window */
  98.       break;
  99.  
  100.     case WM_DESTROY:
  101.       PostQuitMessage (0);
  102.       break;
  103.  
  104.     default:
  105.       return DefWindowProc (hWnd1, iMessage, wParam, lParam);
  106.     }
  107.   return (0L);
  108.   }
  109.  
  110. long    FAR PASCAL WndProc2 (hWnd2, iMessage, wParam, lParam)
  111. HWND     hWnd2;
  112. unsigned iMessage;
  113. WORD     wParam;
  114. LONG     lParam;
  115.   {
  116.   HDC hDC;
  117.   PAINTSTRUCT ps;
  118.  
  119.   switch (iMessage)
  120.     {
  121.     case WM_PAINT:
  122.       hDC = BeginPaint (hWnd2, &ps);
  123.       TextOut (hDC, 30, 30,
  124.           (LPSTR)"This window was opened by the OpenIcon function", 47);
  125.       EndPaint (hWnd2, &ps);
  126.       break;
  127.  
  128.     case WM_DESTROY:
  129.       PostQuitMessage (0);
  130.       break;
  131.  
  132.     default:
  133.       return DefWindowProc (hWnd2, iMessage, wParam, lParam);
  134.     }
  135.   return (0L);
  136.   }
  137.