The mouse is an indispensable input tool in Windows environment, the flexible use of mouse function in the application, will bring great convenience to the work. Visual FOXPRO6.0 and Visual BASIC6.0 are Microsoft Visual STUDIO98 object-oriented Visual development environments that are powerful and simple to design. It provides events and API functions related to mouse operations, So writing the mouse function program becomes very simple, just call these events and API functions in your program.
I. Mouse-related events and Windows API functions:
1.MOUSEDOWN press the mouse event.
The event is raised when the user presses any of the buttons on the mouse.
Call Format:
Private Sub form_mousedown (Button As Integer, Shift As Integer, X as single, Y as single)
The ①button parameter is used to indicate the state of the mouse button. It is represented by a binary. The value of the parameter values is as follows:
001: Press the left button. 010: Right button pressed.
011: The left and right buttons are pressed. 000: None of them have been pressed.
100: The middle button is pressed. 111: Three buttons are pressed.
The ②shift parameter is used to indicate the state of the Shift,ctrl and alt three keys. The value of the parameter is as follows:
001:shift pressed. 010:ctrl pressed.
110:ctrl and Alt Press. 011:shift and CTRL Press.
100:alt pressed. 101:shift and Alt Press.
111:shift,ctrl and ALT are pressed.
The ③ parameters x and y indicate the position of the mouse when it is pressed on the object.
2.MOUSEUP releases mouse events.
The event is raised when the user releases the mouse button.
Call format: (the parameter meaning is the same as the MouseDown procedure.)
Private Sub form_mouseup (Button As Integer, Shift As Integer, X as single, Y as single)
3.MOUSEMOVE Move mouse event.
The event is raised when the user moves the mouse to a new location.
Call format: (the parameter meaning is the same as the MouseDown procedure.)
Private Sub form_mousemove (Button As Integer, Shift As Integer, X as single, Y as single)
The Swapmousebutton () function of the 4.WINDOWS API swap the left and right keys of the mouse.
Syntax format:
Private Declare Function Swapmousebutton Lib "USER32" Alias "Swapmousebuttona" (ByVal bswap As Integer) As Integer
Parameter Bswap meaning: If true, the left button produces a mouse message with the right button, and the right button produces a left press
button's mouse message. If False, the mouse button's input is normally interpreted.
return value Meaning: If true, the left and right button function of the mouse has been swapped. As for flase, the mice
The function of the standard button is restored to its original state.
─────────────────────────────────────
Two. Examples of VISUAL FoxPro applications:
Example one: Use mouse events to draw a circle on a form.
When the left mouse button is pressed, it can be plotted, and when the left mouse button is released, it cannot be plotted, and when the mouse is moved,
Then draw the picture. The left mouse button pressed or not as a drawing of the switch, mouse movement on the continuous drawing, this example is
Draw the circle continuously.
Create the following event on the form FORM1:
Form1lparameters Nbutton, Nshift, nXCoord, nYCoord
Form1.init event, create a global variable mark, the switch variable for whether or not to paint,
When Mark is true, it can be plotted, otherwise it cannot be plotted.
Public mark
Thisform.scalemode=3
thisform.drawwidth=2
Form1.mousedown event, set Mark to True to show that you can paint.
Lparameters Nbutton, Nshift, nXCoord, nYCoord
mark=.t.
Form1.mouseup event, set Mark to False, indicating that it is not drawing.
Lparameters Nbutton, Nshift, nXCoord, nYCoord
Mark=.f.
Form1.mousemove event, move the mouse to draw a continuous circle.
Lparameters Nbutton, Nshift, nXCoord, nYCoord
If Mark and Bittest (nbutton,0)
Thisform.circle (20,nxcoord,nycoord)
Endi
Example two: Use mouse events to toggle the icon in the icon button.
The Picture property of the COMMAND1 control is C:\B.BMP
Form1.Load event, define switch variable Mouse_down.
Public Mouse_down
Mouse_down=0
Form1.mousedown event that displays the icon when the mouse is pressed.
Lparameters Nbutton, Nshift, nXCoord, nYCoord
Thisform.command1.picture= "C:\A.BMP"
Mouse_down=1
Form1.mouseup event that displays the icon when the mouse is released.
Lparameters Nbutton, Nshift, nXCoord, nYCoord
Thisform.command1.picture= "C:\B.bmp"
Form1.mousemove event, to determine whether the mouse left the graphics button, if left, then show the release of the icon.
Lparameters Nbutton, Nshift, nXCoord, nYCoord
If Mouse_down=1
if (nxcoord$#@60;0.or. nxcoord$#@62;thisform.command1.width). Or. (nycoord$#@60;0. Or. Nycoord$#@62;thisform.command1.height)
Thisform.command1.picture= "C:\B.BMP"
Endi
Endi