Visual c ++ 6.0 API function operation tips set ZZ cursor and mouse operations

Source: Internet
Author: User
In the process of compiling the application software, we often need to operate the cursor and the mouse. In this article, I introduced the Windows system's API functions for operating the mouse and the cursor, it also provides the code for using the introduced API functions in visual c6.0 ++ to perform operations on the mouse and the optical mark.

 1. Hide and display the cursor

Function: int showcursor (bool bshow );

The bshow parameter is a Boolean value. If the bshow parameter is set to false, the cursor is hidden. If the bshow parameter is set to true, the cursor is displayed. the return value of this function is an integer type, which is an exponent hidden or displayed by the mouse; when the return value is greater than or equal to 0, the cursor is displayed; otherwise, the mouse is hidden; if the initial value of the mouse is installed, the cursor is 0.

Instance:

In the dialog box-based application, place two buttons named hidecursor and showcursor, and then place a cstatic control named label1 to display the cursor counter.

Source code:

// Reduce the value of the cursor counter by one. If the value is smaller than zero, hide the cursor.
Void cmytestdlg: onhidecursor ()
{
Int I;
I = showcursor (false );
Cstring string;
String. Format (_ T ("% d"), I );
Label1.setwindowtext (& string );
}
// Add one to the value of the cursor counter. If the value is greater than or equal to zero, the cursor is displayed.
Void cmytestdlg: onshowcursor ()
{
Int J;
J = showcursor (true );
Cstring string;
String. Format (_ T ("% d"), J );
Label1.setwindowtext (& string );
}

Run the program and click the showcursor button consecutively. You will see that the counter is continuously incremented by 1 from 1 (when the cursor is displayed, the initial value is 0). Then, click the hidecursor button consecutively, the counter is reduced by 1. When the counter is-1, the cursor is hidden.

  2. Switch the left and right mouse buttons and restore

Function:

BOOL SwapMouseButton ( BOOL fSwap );

The fswap parameter is a Boolean value. "True" indicates that the left and right mouse keys are switched. "false" indicates that the default left and right hand habits are restored. The return value is also a Boolean value. After the switch, the return value is true, and the return value is false.

Instance:

Put two buttons in the application, with the names reversemouse and restoremouse respectively.

Source code:

// Exchange the left and right mouse keys
Void cmytestdlg: onreversemouse ()
{
Bool T;
T = swapmousebutton (true );
If (t)
MessageBox ("the left and right mouse keys are exchanged successfully! ");
}

// Restore the left and right mouse Key Exchange
Void cmytestdlg: onrestoremouse ()
{
Bool T;
T = swapmousebutton (false );
If (! T)
MessageBox ("the left and right mouse keys are restored to the default status! ");
}

Run the program and left-click reversemouse to switch between the left and right mouse keys. Right-click restoremouse to restore the function.

3. Get the double-click Time

1. functions:
UINT GetDoubleClickTime(VOID);

This function has no parameter; its return value is millisecond, which is the effective interval of double-clicking the mouse.

Instance:

Place a button in the window named getdoubleclicktime. Then, place a cstatic control named label1 to display the double-click Time.

Source code:

// Obtain and display the double-click Time of the mouse.
Void cmytestdlg: ongetdoubleclicktime ()
{
Int dtime;
Cstring string;
Dtime: = getdoubleclicktime ();
String. Format (_ T ("% d"), dtime );
Label1.setwindowtext (& string );
}

Run the program and click getdoubleclicktime. The double-click Time is displayed in label1 in milliseconds.

  Iv. Set the double-click Time

Function:

BOOL SetDoubleClickTime ( UINT uInterval );

The uinterval parameter indicates the time for double-clicking the mouse, in milliseconds. The default time is 500;

The return value is a Boolean value.

Instance:

Place a button in the window named setdoubleclicktime.

Source code:

// Set the double-click Time of the mouse.
Void cmytestdlg: onsetdoubleclicktime ()
{
Bool T;
T = setdoubleclicktime (500 );
If (t)
MessageBox ("the mouse double-click Time is successfully set! ");
}

Run the program, click btnsetdoubleclicktime, and the double-click Time has changed.

  5. Lock the mouse in a certain range

Function:

BOOL ClipCursor ( CONST RECT *lpRect );

The parameter * lprect points to the pointer to the area of the mouse's movable rectangle. the return value is Boolean, indicating whether the lock is successful or not.

Instance:

Put two buttons in the window, named lockmouse and unlockmouse.

Source code:

// Lock the mouse in a fixed area
Void cmytestdlg: onlockmouse ()
{
Rect;
Bool block;
Rect. Left = 10; // set the size of the locked area;
Rect. Top = 10;
Rect. Rights = 200;
Rect. bottomtom = 200;
Block: = clipcursor (& rect); // restrict the area where the mouse moves
If (Block)
MessageBox ("the mouse is fixed in the specified area! ");
}

The essence of locking the mouse to unlock is to lock the mouse in the entire screen area.

Void cmytestdlg: onlockmouse ()
{
Rect;
Bool block;
Rect. Left = 0; // set the size of the locked area;
Rect. Top = 0;
Rect. Rights = 600;
Rect. bottomtom = 800;
Block = clipcursor (& rect );
If (Block)
MessageBox ("the mouse is fixed in the screen area! ");
}

Run the program and click lockmouse. The mouse is locked in a fixed area, and then click unlockmouse to lock the unlock. Of course, you can also use other methods to unlock the mouse, such as locking the mouse in a window to unlock the mouse.

In short, API functions are powerful. We can use them in a variety of rapid development tools to enhance the functions of our programs. The above programs have been debugged in Windows2000 and Visual C ++ 6.0.

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.