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

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