Win32 User Interface Design Basis CURSOR

zhaozj2021-02-17  58

Win32 User Interface Design Basis CURSOR

Time: 2002-10-31 21:28:40 Read 313 times

1. Standard mouse replacement Windows provides a range of standard mice with IDC_, with a setSystemCursor () function to replace the system's standard mouse. SetSystemCusor () has two parameters, the first one for a loadcursor () (loadCursor () function to be replaced by loadImage () function), createcursor () or copycursor () obtained Cursor pointer. E.g:

HCURSOR hnewCur; hnewCur = LoadCursor (hInst, MAKEINTRESOURCE (NEWCURSOR); NEWCURSOR as hInst in a Cursor, SetSystemCursor (hnewCur, OCR_NORMAL); user defined mouse replace the system default mouse, when the user uses LoadCursor (NULL, IDC_ARROW) again; loading The standard mouse will be a user-loaded rather than the system-predefined mouse 2. Replacing Cursor's method 1. New Cursor this method is most cumbersome, but the user has complete control, such as the location of the hotspot, not The default left upper corner, the specific method is to fill in an iconifo structure:

TypeDef struct iconinfo {bool fic; is an icon, assigning it to false, indicating that the structure is used to create a mouse DWORD Xhotspot; hotspot X coordinate DWORD YHOTSPOT; HotSpot's Y coordinate hbitmap hbmmask; mouse appearance mask diagram, used Filtered mouse background hbitmap hbmcolor; mouse appearance picture} iconInfo; fill in Createicon Indirect () get a HICON handle, if you build a mouse, convert it to hcursor, for example::

ICONINFO ii; HCURSOR hnewCur; ii.fIcon = FALSE; ii.yHotspot = 0; ii.yHotspot = 0; ii.hbmMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDBCURSORMASK)); ii.hbmColor = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_CURSOR) HNewcur = (HCURSOR) CreateiconIndirect (& II); 2, loading Cursor loading is the most commonly used method, the loaded mouse can be a designed CURSOR in the VC integrated development environment, or may be a .ani or .cur file. 1) Load from the file:

LoadCursorfromFile (); for example: loadingCursorfromfile ("c: //anicur.ani") loads an animated mouse. 2) Loading from an integrated development environment: loadCursor (NewCursor); NewCursor can be designed in the resource editor. It is also to be explained that loadImage () is a function of loadcursor (), loadbitmap (), and loadcursorfromfile (), which sets multiple functions of the function, more convenient, main difference is that there is a sign coming Note Loading bitmap, icon function mouse. 3, use the Cursor 1) setCursor () capture the WM_MouseMoveor message of the window, add call to setCursor () in its handler, for example: setCursor (HNewcur); where HNewcur is obtained by any of the above methods HCURSOR 2) SetClasslong () Capture WM_MouseMove message is only valid for windows with window functions, and the host is not available. The SETCLASSLONG () function should be used to replace the Button class's mouse, for example: hwnd hnewcur; hnewcur = loadingcursorfromfile ("c: //winnt//cursors/animcur.ani"); hbutton = (hwnd) getdlgitem (IDC_BUTTON) // IDC_Button To change the control IDSetClasslong (HButton, GCL_HCURSOR, (long) hnewcur); 3) registerclass () or registerclassex () function This is the most troublesome method, but it can act on all the same window classes. window. When retiSterclass () or registerclassex (), fill in WNDCLASS, assign a custom Cursor handle to HCursor, such as WndClassex WCX;

Wcx.hcursor = loadingcursor (HinST, MakeintResource (Newcur)); 4, Mouse Operation Function 1) Cut mouse, limit the mouse moving clipcursor () function Used to cut the mouse, the parameter is a pointer to the RECT, in normal case The mouse is cut throughout the screen. If a window of a program is going to cut the mouse, you must first use getClipCursor () to get the screen's mouse clip area, then use the clipCursor () clipping the mouse to the program window, the program must be exited Reduce the shear area of ​​the mouse into a screen rectangle to avoid affecting other programs using a mouse. Suppose we want to limit the mouse to the window hWnd, should:

Rect RT1; // Store screen cut rectangular Rect RT2; // Storage program window Cut rectangular getClipCursor (& RT1); // Get the current mouse shear rectangle fill in RT1, if the mouse is not cut by other programs, then The entire rectangle is the screen rectangle getWindowRect (hwnd, & rt2); // Get the rectangle of the program window HWND to RT2ClipCursor (& RT2); // After the RT2 program of the shear mouse should be: ClipCursor (& RT1); // Put the mouse Clearance reduction is RT1 (screen) 2) Tracking the mouse location getCursorpos () to get the current mouse position, setCursorpos () Set the mouse location, for example:

转载请注明原文地址:https://www.9cbs.com/read-30561.html

New Post(0)