Actions of the Windows api--cursor

Source: Internet
Author: User
Tags cursorinfo

Gets and sets the position of the cursor on the screen

GetCursorPos gets the position of the cursor on the screen, the cursor position is always specified in screen coordinates and is not affected by the window mapping mode that contains the cursor

Function Prototypes:

BOOL GetCursorPos (Lppoint lppoint);

Parameter description:

Lppoint: Type lppoint, output parameter; A pointer to the structure of the cursor at the screen coordinate point

return value:

BOOL type, the call successfully returned non 0, the failure returned 0;

Setcursorpos sets the position of the cursor on the screen, if the new coordinates are not set by the latest Clipcursor function call in the screen rectangle, the system automatically adjusts the coordinates so that the cursor rests within the rectangle

Function Prototypes:

BOOL setcursorpos (int x,int Y);

Parameter description:

x: type int, input parameter, set the x coordinate of the cursor in screen coordinates

Y: Type int, input parameter, set the Y coordinate of the cursor in screen coordinates

return value:

BOOL type, the call successfully returned non 0, the failure returned 0;

C # code invocation case

    /// <summary>    /// coordinates    of the cursor /// </summary>     [StructLayout (layoutkind.sequential)]    publicstruct  lppoint    {        publicint  X;          Public int Y;    }
1         //Get cursor Position2[DllImport ("user32.dll", EntryPoint ="GetCursorPos")]3         unsafe  Public Static extern BOOLGetCursorPos (lppoint*lppoint);4         //Set cursor Position5[DllImport ("user32.dll", EntryPoint ="Setcursorpos")]6          Public Static extern BOOLSetcursorpos (intXintY);7 8         unsafe Static voidMain (string[] args)9         {Ten             intx = -, y = -; One              for(inti =0; I < $; i++) A             { -Setcursorpos (x + i, y +i); - lppoint Lppoint; theGetCursorPos (&lppoint); -Console.WriteLine ("[X:{0},y:{1}]", Lppoint.x, lppoint.y); -Thread.Sleep ( -); -             } + Console.readkey (); -}
Gets the current cursor handle

GetCursor gets the handle of the current cursor

Function Prototypes:

Hcursor WINAPI getcursor (void);

Parameter description:

No reference

return value:

Returns the handle of the current cursor if no NULL is returned

C # code invocation case

1[DllImport ("user32.dll", EntryPoint ="getcursor")]2          Public Static externIntPtr getcursor ();3 4         unsafe Static voidMain (string[] args)5         {6 Console.WriteLine (GetCursor ());7 Console.readkey ();8}
Get Global cursor Information

Getcursorinfo getting information about the global cursor

Function Prototypes:

BOOL Getcursorinfo (Pcursorinfo PCI);

Parameter description:

Pci:pcursorinfo type, input and output parameters, a pointer to a struct of pcursorinfo, a function call must be set before a parameter struct CSize member's value is sizeof (Cursorinfo)

return value:

BOOL type, the call successfully returned non 0, the failure returned 0;

C # code invocation case

1      Public structCursorinfo2     {3          Public intcbsize;//the size of the struct, which can be assigned by sizeof (Cursorinfo)4          Public intFlags//A value of 0 cursor is hidden, a value of 0x00000001 cursor is displayed, and a value of 0x00000002 disables the cursor, which shows that the system does not draw the cursor and the user uses touch input instead of the mouse5          PublicIntPtr Hcursor;//cursor handle6          PublicLppoint Ptscreenpos;//The coordinates of the cursor on the screen7     }8 9     class ProgramTen     { One[DllImport ("user32.dll", EntryPoint ="Getcursorinfo")] A         unsafe  Public Static extern BOOLGetcursorinfo (cursorinfo*PCI); -  -         unsafe Static voidMain (string[] args) the         { - Cursorinfo PCI; -Pci.cbsize =sizeof(cursorinfo); -Getcursorinfo (&PCI); +Console.WriteLine ("Cbsize:{0},flags:{1},hcursor:{2},[x:{3},y:{4}]", - pci.cbsize, Pci.flags, Pci.hcursor, pci.ptscreenpos.x, pci.ptscreenpos.y); + Console.readkey (); A         } at}
Limit cursor Position

Clipcursor the cursor within the holding area

Function Prototypes:

BOOL WINAPI clipcursor (const RECT * lpRect);

Parameter description:

Lprect:rect type, input parameter, a screen coordinate structure pointer that contains the upper-left and lower-right corners, and if set to NULL, the cursor can be moved anywhere on the screen

return value:

BOOL type, the call successfully returned non 0, the failure returned 0;

C # code invocation case

1      Public structRECT2     {3          Public intLeft//The x-coordinate of the upper-left corner of the rectangle4          Public intTop//The y-coordinate of the upper-left corner of the rectangle5          Public intRight//The x-coordinate of the lower-right corner of the rectangle6          Public intBottom//coordinates of the lower-right corner of the rectangle7     }8 9     class ProgramTen     { One[DllImport ("user32.dll", EntryPoint ="Clipcursor")] A         unsafe  Public Static externIntPtr Clipcursor (rect*lpRect); -  -         unsafe Static voidMain (string[] args) the         { - rect rect; -Rect.left = -; -Rect.top = -; +Rect.right = $; -Rect.bottom = $; +Clipcursor (&rect); A Console.readkey (); at         } -}

Header---Winuser.h

Library---user32.dll

Reference resources: Https://msdn.microsoft.com/zh-cn/vstudio/ms646970%28v=vs.90%29

Use case: Https://msdn.microsoft.com/zh-cn/vstudio/ms648380%28v=vs.90%29#_win32_Creating_a_Cursor

Actions of the Windows api--cursor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.