home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sb_bc.ddi / BC / CH6 / WSTRIN-1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-18  |  3.8 KB  |  149 lines

  1. /***    Windows Application --- STRING example   ***/
  2. /***                                             ***/
  3. /***    WSTRIN-1 includes                        ***/
  4. /***            (1) WSTRIN-1.C                   ***/
  5. /***            (2) WSTRIN-1.DEF                 ***/
  6. /***            (3) WSTRING.RES                  ***/
  7.  
  8. #pragma hdrfile "windows.sym"
  9. #include <windows.h>
  10. #pragma hdrstop
  11.  
  12. #include "wmenu.h"
  13. #include "string.h"
  14.  
  15. // Declaration
  16.  
  17. void InitString(HANDLE) ;
  18. void InitFirstInstance(HANDLE) ;
  19. void InitEachInstance(HANDLE, int) ;
  20. long FAR PASCAL AppWndProc (HWND, WORD, WORD, LONG) ;
  21.  
  22. static char  szAppName[12] ;
  23. static char  szMenuName[12] ;
  24. static char  szAccelName[12] ;
  25.  
  26. HWND  hwnd ;
  27.  
  28. // Definition
  29.  
  30. int PASCAL WinMain(HANDLE hInstance,
  31.            HANDLE hPrevInstance,
  32.            LPSTR  lpszCmdLine,
  33.            int    nCmdShow)
  34. { HANDLE hAccel ;
  35.   MSG msg ;
  36.  
  37.   InitString(hInstance) ;
  38.  
  39.   if ( !hPrevInstance ) InitFirstInstance(hInstance) ;
  40.  
  41.   InitEachInstance(hInstance,nCmdShow) ;
  42.  
  43.   hAccel = LoadAccelerators(hInstance, szAccelName) ;
  44.  
  45.   while ( GetMessage(&msg, NULL, 0, 0) )
  46.     { if ( !TranslateAccelerator(hwnd, hAccel, &msg) )
  47.      { TranslateMessage(&msg) ;
  48.        DispatchMessage(&msg) ;
  49.      }
  50.     }
  51.   return msg.wParam ;
  52. }
  53.  
  54.  
  55. void InitString(HANDLE hInstance)
  56. {
  57.   LoadString(hInstance, IDS_APP, szAppName,11) ;
  58.   LoadString(hInstance, IDS_MENU, szMenuName,11) ;
  59.   LoadString(hInstance, IDS_ACCEL, szAccelName,11) ;
  60. }
  61.  
  62.  
  63. void InitFirstInstance(HANDLE hInstance)
  64. { WNDCLASS wndclass ;
  65.  
  66.   wndclass.style      = CS_HREDRAW | CS_VREDRAW ;
  67.   wndclass.lpfnWndProc      = AppWndProc ;
  68.   wndclass.cbClsExtra       = 0 ;
  69.   wndclass.cbWndExtra      = 0 ;
  70.   wndclass.hInstance      = hInstance ;
  71.   wndclass.hIcon             = LoadIcon(NULL,IDI_APPLICATION) ;
  72.   wndclass.hCursor      = LoadCursor(NULL,IDC_ARROW) ;
  73.   wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH) ;
  74.   wndclass.lpszMenuName      = szMenuName ;
  75.   wndclass.lpszClassName  = szAppName ;
  76.  
  77.   RegisterClass(&wndclass) ;
  78. }
  79.  
  80.  
  81. void InitEachInstance(HANDLE hInstance, int nCmdShow)
  82. {
  83.   hwnd = CreateWindow(szAppName,               // window class name
  84.               "Windows Application", // window caption
  85.               WS_OVERLAPPEDWINDOW ,
  86.               CW_USEDEFAULT,      // initial x position
  87.               0,                  // initial y position
  88.               CW_USEDEFAULT,      // initial x length
  89.               0,                  // initial y length
  90.               NULL,               // parent window handle
  91.               NULL,               // window menu handle
  92.               hInstance,          // program instance handle
  93.               NULL) ;             // parameters
  94.  
  95.   ShowWindow(hwnd,nCmdShow) ;
  96.   UpdateWindow(hwnd) ;
  97. }
  98.  
  99.  
  100. long FAR PASCAL AppWndProc (HWND hwnd,
  101.                 WORD message,
  102.                 WORD wParam,
  103.                 LONG lParam)
  104. { static WORD Cursor_Check = IDM_CURSOR1,
  105.           Icon_Check   = IDM_ICON1,
  106.           Bitmap_Check = IDM_BITMAP1 ;
  107.   HMENU hMenu ;
  108.  
  109.   switch (message)
  110.     { case WM_COMMAND :
  111.        hMenu = GetMenu(hwnd) ;
  112.        switch(wParam)
  113.          { case IDM_CURSOR1 :
  114.            case IDM_CURSOR2 :
  115.            case IDM_CURSOR3 :
  116.             CheckMenuItem(hMenu, Cursor_Check, MF_UNCHECKED) ;
  117.             Cursor_Check = wParam ;
  118.             CheckMenuItem(hMenu, Cursor_Check, MF_CHECKED) ;
  119.             break ;
  120.  
  121.            case IDM_ICON1 :
  122.            case IDM_ICON2 :
  123.             CheckMenuItem(hMenu, Icon_Check, MF_UNCHECKED) ;
  124.             Icon_Check = wParam ;
  125.             CheckMenuItem(hMenu, Icon_Check, MF_CHECKED) ;
  126.             break ;
  127.  
  128.            case IDM_BITMAP1 :
  129.            case IDM_BITMAP2 :
  130.            case IDM_BITMAP3 :
  131.             CheckMenuItem(hMenu, Bitmap_Check, MF_UNCHECKED) ;
  132.             Bitmap_Check = wParam ;
  133.             CheckMenuItem(hMenu, Bitmap_Check, MF_CHECKED) ;
  134.             break ;
  135.          }
  136.        break ;
  137.  
  138.       case WM_DESTROY :
  139.        PostQuitMessage(0) ;
  140.        break ;
  141.  
  142.       default :
  143.        return DefWindowProc(hwnd, message, wParam, lParam) ;
  144.     }
  145.  
  146.   return 0 ;
  147. }
  148.  
  149.