home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / mslang / curdll / c_demo / cus_cur.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-08  |  7.3 KB  |  188 lines

  1. // Written by:  Robert B. Cooper
  2. //              ELECTRON Software
  3. //              P.O. Box 309
  4. //              Mt. Storm, WV. 26739
  5. //              CompuServe ID#: 73244,3472
  6. //              America OnLine: ELECTRON
  7. //
  8. // Main program file for the Custom Cursor DLL Demonstration.
  9. // This Demo was written in with Microsoft Visual C++ Ver. 1.0
  10. // It can be compiled with any ANSI C standard compiler except you will 
  11. // need to modify the .MAK file that is included.
  12. //
  13. // You have a royalty-free right to use, modify, reproduce and distribute the
  14. // Sample Files CUS_CUR.C, CUR_DLL.DEF, CUS_CUR.H, SAMPLE.RC, RESOURCE.H and 
  15. // CUR_DEMO.MAK(and/or any modified version) in any way you find useful, 
  16. // provided that you agree that ELECTRON SOFTWARE has no warranty obligations
  17. // or liability for any Sample Application Files which are modified.
  18.  
  19.  
  20. #include <windows.h>
  21. #include "Cus_Cur.h"
  22. #include "Resource.h"
  23.  
  24. HANDLE hInst;         // Program instance handle.
  25. HANDLE hCursor;       // Custom Cursor handle.
  26. HANDLE  hLibrary;     // Handle to the CURSOR.DLL.
  27.  
  28. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
  29.      LPSTR lpCmdLine, int nCmdShow)
  30. {   char szAppName[]="Cur_Demo";
  31.     int xScreen, yScreen; 
  32.     WNDCLASS wndclass;
  33.     HWND hWnd;
  34.     MSG msg;
  35.     xScreen = GetSystemMetrics(SM_CXSCREEN);
  36.     yScreen = GetSystemMetrics(SM_CYSCREEN);
  37.     // This next line loads the Custom Cursor DLL into memory and stores
  38.     // the returned value in the hLibrary handle.  This example does not
  39.     // use any error handling routines.  For your application I strongly
  40.     // suggest that you include this feature.
  41.     hLibrary = LoadLibrary("CURSOR.DLL");
  42.     // The LoadCursor function now loads the PENCIL_NW_A from the CURSOR.DLL
  43.     // The returned value is a handle the the custom cursor and is stored in
  44.     // the hCursor handle.  
  45.     hCursor = LoadCursor(hLibrary, "POINTER_NW");
  46.     if (!hPrevInstance)
  47.     {  wndclass.style = CS_HREDRAW | CS_VREDRAW;
  48.        wndclass.lpfnWndProc = WndProc;          
  49.        wndclass.cbClsExtra = 0;                 
  50.        wndclass.cbWndExtra = 0;                 
  51.        wndclass.hInstance = hInstance; 
  52.        wndclass.hIcon = LoadIcon(hInstance, "ID_ATOM");  // Loads the program icon.
  53.        wndclass.hCursor = NULL; // Sets the default cursor to NULL so that 
  54.                                 // you can use a custom cursor.
  55.        wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 
  56.        wndclass.lpszMenuName =  "SampleMenu";  // The menu resource identifier. 
  57.        wndclass.lpszClassName = szAppName;   // Name used in call to CreateWindow.
  58.        if (!RegisterClass(&wndclass)) return FALSE;
  59.     }
  60.     hInst = hInstance;
  61.     hWnd = CreateWindow( szAppName,  " Custom Cursor Demonstration in Microsoft C",   // Text for window title bar.
  62.                          WS_OVERLAPPEDWINDOW,            // Window style.
  63.                          0,                              // Initial x position
  64.                          0,                              // Initial y position.
  65.                          xScreen,                        // Width.
  66.                          yScreen,                        // Height.
  67.                          NULL,                           // Parent window handle.
  68.                          NULL,                           // Window menu handle.
  69.                          hInstance,                      // Program instance handle.
  70.                          NULL                            // Create parameters.
  71.     );
  72.     
  73.     ShowWindow(hWnd, nCmdShow);
  74.     UpdateWindow(hWnd);
  75.     SetCursor(hCursor);  // Sets the cursor shown when the program first starts
  76.                          // to the custom cursor. 
  77.     
  78.     while (GetMessage(&msg, NULL, 0, 0))     
  79.     {  TranslateMessage(&msg);     // Translates virtual key codes
  80.        DispatchMessage(&msg);      // Dispatches message to window
  81.     }
  82.     return msg.wParam;     // Returns the value from PostQuitMessage
  83. }
  84.  
  85. long FAR PASCAL _export WndProc(HWND hWnd, UINT message, 
  86.        WPARAM wParam, LPARAM lParam)
  87. {  
  88.    static RECT rect;
  89.    static int xScreen, yScreen, LButtonPressed, RButtonPressed;
  90.    PAINTSTRUCT ps;
  91.    HDC hDC, hdcMem;
  92.       
  93.    switch (message) 
  94.    {
  95.    case WM_PAINT:
  96.       hDC = BeginPaint(hWnd, &ps);
  97.       hdcMem = CreateCompatibleDC(hDC);
  98.       DeleteDC(hdcMem);
  99.       EndPaint(hWnd, &ps);
  100.       LButtonPressed = RButtonPressed = 0;
  101.       break;
  102.    case WM_SIZE:
  103.       xScreen = LOWORD(lParam); 
  104.       yScreen = HIWORD(lParam);
  105.       LButtonPressed = RButtonPressed = 0;
  106.       break;
  107.    case WM_LBUTTONDOWN:
  108.       LButtonPressed = 1;
  109.       rect.left = LOWORD(lParam);
  110.       rect.top = HIWORD(lParam);                 
  111.       InvalidateRect(hWnd, &rect, FALSE);
  112.       break;
  113.    case WM_RBUTTONDOWN:
  114.       RButtonPressed = 1;
  115.       rect.left = LOWORD(lParam);
  116.       rect.top = HIWORD(lParam);                 
  117.       InvalidateRect(hWnd, &rect, FALSE);
  118.       // Returns the Cursor to the type when the demonstration first started.
  119.       hCursor = LoadCursor(hLibrary, "POINTER_NW");
  120.       SetCursor(hCursor);
  121.       break;
  122.    // The WM_MOUSEMOVE Event is called each time the mouse moves to ensure 
  123.    // that the cursor stays defined to the current custom cursor
  124.    case WM_MOUSEMOVE:
  125.          SetCursor(hCursor);
  126.    break;
  127.    // The WM_COMMAND Event is called when the user chooses a menu item.
  128.    // Each menu item in this demo has a different cursor associated with it.
  129.    // IDM_EXIT closes the program and initiates the WM_DESTROY Event.
  130.    // The About Dialog Box is not functional in this demo.
  131.    case WM_COMMAND:
  132.       switch (wParam)
  133.         {
  134.         case IDM_PRINT:
  135.                hCursor = LoadCursor(hLibrary, "PRINTER");      
  136.              SetCursor(hCursor);
  137.            break;
  138.            case IDM_EXIT:
  139.              SendMessage(hWnd, WM_CLOSE, 0, 0L);
  140.              return 0;
  141.            break;
  142.            case IDM_CUT:
  143.              hCursor = LoadCursor(hLibrary, "SCISSORS_NW");      
  144.              SetCursor(hCursor);                        
  145.            break;
  146.            case IDM_COPY:
  147.              hCursor = LoadCursor(hLibrary, "HAND_DRAG_1");      
  148.              SetCursor(hCursor);                        
  149.            break;
  150.            case IDM_PASTE:
  151.              hCursor = LoadCursor(hLibrary, "PIN_NW");      
  152.              SetCursor(hCursor);                   
  153.            break;
  154.            case IDM_LINE:
  155.              hCursor = LoadCursor(hLibrary, "DRAW_LINE");      
  156.              SetCursor(hCursor);                      
  157.            break;
  158.            case IDM_CIRCLE:
  159.              hCursor = LoadCursor(hLibrary, "DRAW_CIRCLE");      
  160.              SetCursor(hCursor);                        
  161.            break;
  162.            case IDM_FREEHAND:
  163.              hCursor = LoadCursor(hLibrary, "DRAW_FREEHAND");      
  164.              SetCursor(hCursor);                          
  165.            break;
  166.            case IDM_PAINT:
  167.              hCursor = LoadCursor(hLibrary, "PAINT_BRUSH_SW");      
  168.              SetCursor(hCursor);                           
  169.            break;
  170.            case IDM_CONTEXTHELP:
  171.              hCursor = LoadCursor(hLibrary, "CONTEXT_HELP");      
  172.              SetCursor(hCursor);                        
  173.            break;
  174.            case IDM_ABOUT:
  175.              return 0;
  176.            break;
  177.            }
  178.          break;  
  179.    break; 
  180.    case WM_DESTROY:
  181.          FreeLibrary(hLibrary);
  182.       PostQuitMessage(0); 
  183.    break; 
  184.       default:
  185.          return DefWindowProc(hWnd, message, wParam, lParam);
  186.    }
  187.    return 0L;
  188. }