home *** CD-ROM | disk | FTP | other *** search
- /*
- CICONIND.C -- Creates a cursor on the fly from a bit pattern
- using CreateCursorIconIndirect
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC CICONIND (for Borland C++ v3.00)
- WINIOMS CICONIND (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include "wmhandlr.h"
- #include "winio.h"
-
- /* undocumented structure */
- #include "cursicon.h"
-
- WORD awANDBits[64] =
- { 0x0100, 0xffff, 0xfd7e, 0xffff,
- 0xfd7e, 0xffff, 0x0d60, 0xffff,
- 0xed6e, 0xffff, 0xed6e, 0xffff,
- 0x6d6c, 0xffff, 0x0101, 0xffff,
- 0x6d6c, 0xffff, 0xed6e, 0xffff,
- 0xed6e, 0xffff, 0x0d60, 0xffff,
- 0xfd7e, 0xffff, 0xfd7e, 0xffff,
- 0x0100, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff,
- 0xffff, 0xffff, 0xffff, 0xffff};
-
- WORD awXORBits[64] = {0};
-
- /* undocumented function */
- extern HANDLE FAR PASCAL CreateCursorIconIndirect(HANDLE hInstance,
- LPCURSORICONINFO lpInfo,
- LPSTR lpANDbits, LPSTR lpXORbits);
-
- #include "checkord.c"
-
- HANDLE hNewCursor, hOldCursor;
- WMHANDLER prev_lbuttondown, prev_lbuttonup;
- CURSORICONINFO iconinfo;
-
- long my_lbuttondown(HWND hwnd, WORD wMsg, WORD wParam,
- DWORD lParam)
- {
- printf("Changing the cursor to a 'rifle sight'.\n");
- hOldCursor = SetClassWord(winio_current(), GCW_HCURSOR,
- hNewCursor);
- SetCapture(hwnd);
- SetCursor(hNewCursor);
- return (*prev_lbuttondown)(hwnd, wMsg, wParam, lParam);
- }
-
- long my_lbuttonup(HWND hwnd, WORD wMsg, WORD wParam,
- DWORD lParam)
- {
- printf("Changing back to the regular cursor.\n");
- SetClassWord(hwnd, GCW_HCURSOR, hOldCursor);
- ReleaseCapture();
- SetCursor(hOldCursor);
- return (*prev_lbuttonup)(hwnd, wMsg, wParam, lParam);
- }
-
- int main()
- {
- // Ord/name check
- if (! CheckOrdName("CreateCursorIconIndirect", "USER", 408))
- return 0;
-
- winio_about("CICONIND"
- "\nCreates a cursor on the fly from a bit pattern"
- "\nusing CreateCursorIconIndirect"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- iconinfo.pntHotSpot.x = 7;
- iconinfo.pntHotSpot.y = 7;
- iconinfo.nWidth = 32;
- iconinfo.nHeight = 32;
- iconinfo.nWidthBytes = 4;
- iconinfo.byPlanes = 1;
- iconinfo.byBitsPix = 1;
-
- // Create a cursor
- if ((hNewCursor = CreateCursorIconIndirect(__hInst, &iconinfo,
- (LPSTR) &awANDBits, (LPSTR) &awXORBits)) == NULL)
- {
- printf("Could not create a cursor....!!\n");
- return 0;
- }
-
- prev_lbuttondown = wmhandler_set(winio_current(),
- WM_LBUTTONDOWN, (WMHANDLER) my_lbuttondown);
- prev_lbuttonup = wmhandler_set(winio_current(),
- WM_LBUTTONUP, (WMHANDLER) my_lbuttonup);
-
- printf("Press the left mouse button to use a\n"
- "cursor created by CreateCursorIconIndirect().\n"
- "Release the button to restore the regular cursor\n\n"
- "Close the window to exit\n\n");
-
- return 0;
- }
-
-