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

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