home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / CICONIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.7 KB  |  114 lines

  1. /*
  2.     CICONIND.C -- Creates a cursor on the fly from a bit pattern
  3.     using CreateCursorIconIndirect
  4.  
  5.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  6.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  7.  
  8.     Build using: WINIOBC CICONIND (for Borland C++ v3.00)
  9.                  WINIOMS CICONIND (for Microsoft C/SDK)
  10. */
  11.  
  12. #include <windows.h> 
  13. #include "wmhandlr.h" 
  14. #include "winio.h" 
  15.  
  16. /* undocumented structure */ 
  17. #include "cursicon.h"
  18.  
  19. WORD awANDBits[64] =
  20.         {   0x0100, 0xffff, 0xfd7e, 0xffff,
  21.             0xfd7e, 0xffff, 0x0d60, 0xffff,
  22.             0xed6e, 0xffff, 0xed6e, 0xffff,
  23.             0x6d6c, 0xffff, 0x0101, 0xffff,
  24.             0x6d6c, 0xffff, 0xed6e, 0xffff,
  25.             0xed6e, 0xffff, 0x0d60, 0xffff,
  26.             0xfd7e, 0xffff, 0xfd7e, 0xffff,
  27.             0x0100, 0xffff, 0xffff, 0xffff,
  28.             0xffff, 0xffff, 0xffff, 0xffff,
  29.             0xffff, 0xffff, 0xffff, 0xffff,
  30.             0xffff, 0xffff, 0xffff, 0xffff,
  31.             0xffff, 0xffff, 0xffff, 0xffff,
  32.             0xffff, 0xffff, 0xffff, 0xffff,
  33.             0xffff, 0xffff, 0xffff, 0xffff,
  34.             0xffff, 0xffff, 0xffff, 0xffff,
  35.             0xffff, 0xffff, 0xffff, 0xffff};
  36.  
  37. WORD awXORBits[64] = {0};
  38.  
  39. /* undocumented function */ 
  40. extern HANDLE FAR PASCAL CreateCursorIconIndirect(HANDLE hInstance,
  41.                     LPCURSORICONINFO lpInfo,
  42.                     LPSTR lpANDbits, LPSTR lpXORbits);
  43.  
  44. #include "checkord.c"
  45.  
  46. HANDLE hNewCursor, hOldCursor;
  47. WMHANDLER prev_lbuttondown, prev_lbuttonup;
  48. CURSORICONINFO iconinfo;
  49.  
  50. long my_lbuttondown(HWND hwnd, WORD wMsg, WORD wParam,
  51.                                                 DWORD lParam)
  52.     {
  53.     printf("Changing the cursor to a 'rifle sight'.\n");
  54.     hOldCursor = SetClassWord(winio_current(), GCW_HCURSOR,
  55.                                                 hNewCursor);
  56.     SetCapture(hwnd);
  57.     SetCursor(hNewCursor);
  58.     return (*prev_lbuttondown)(hwnd, wMsg, wParam, lParam);
  59.     }
  60.  
  61. long my_lbuttonup(HWND hwnd, WORD wMsg, WORD wParam,
  62.                                                 DWORD lParam)
  63.     {
  64.     printf("Changing back to the regular cursor.\n");
  65.     SetClassWord(hwnd, GCW_HCURSOR, hOldCursor);
  66.     ReleaseCapture();
  67.     SetCursor(hOldCursor);
  68.     return (*prev_lbuttonup)(hwnd, wMsg, wParam, lParam);
  69.     }
  70.  
  71. int main() 
  72.     {
  73.     // Ord/name check
  74.     if (! CheckOrdName("CreateCursorIconIndirect", "USER", 408))
  75.         return 0;
  76.  
  77.     winio_about("CICONIND"
  78.         "\nCreates a cursor on the fly from a bit pattern"
  79.         "\nusing CreateCursorIconIndirect"
  80.         "\n\nFrom Chapter 6 of"
  81.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  82.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  83.         );
  84.     
  85.     iconinfo.pntHotSpot.x = 7;
  86.     iconinfo.pntHotSpot.y = 7;
  87.     iconinfo.nWidth = 32;
  88.     iconinfo.nHeight = 32;
  89.     iconinfo.nWidthBytes = 4;
  90.     iconinfo.byPlanes = 1;
  91.     iconinfo.byBitsPix = 1;
  92.     
  93.     // Create a cursor
  94.     if ((hNewCursor = CreateCursorIconIndirect(__hInst, &iconinfo,
  95.                 (LPSTR) &awANDBits, (LPSTR) &awXORBits)) == NULL)
  96.         {
  97.         printf("Could not create a cursor....!!\n");
  98.         return 0;
  99.         }
  100.  
  101.     prev_lbuttondown = wmhandler_set(winio_current(),
  102.                     WM_LBUTTONDOWN, (WMHANDLER) my_lbuttondown);
  103.     prev_lbuttonup = wmhandler_set(winio_current(),
  104.                     WM_LBUTTONUP, (WMHANDLER) my_lbuttonup);
  105.     
  106.     printf("Press the left mouse button to use a\n"
  107.             "cursor created by CreateCursorIconIndirect().\n"
  108.             "Release the button to restore the regular cursor\n\n"
  109.             "Close the window to exit\n\n");
  110.  
  111.     return 0;
  112.     }
  113.  
  114.