Programming MOUSEENTER, MouseExit event

zhaozj2021-02-11  188

Programming MOUSEENTER, MouseExit event

MouseEnter and mouseExit events provided by many third-party controls are supplemented by the MouseMove event (MouseMove events can not be valid) whether the mouse is outside the control, but these controls or registration, or the other actual actual control control, In addition, adding too many controls in the program also affects the performance of the program, using Windows API functions, we can simulate MouseEnter and MouseExit in Mousemove, although there is no real in the source code, but it is indeed The functions of these two events. All right! Let us realize it. First load a module, declare the following two API functions in the module: public declare function setcapture lib "user32" _ (BYVAL HWND As long) The function of the "User32" () As long setcapture is: Set the mouse Capture the specified window (Windows Each control is a window. For example, the icon displayed on the desktop is a window, actually two, another display describes the icon, the system will receive this window all mouse movements or All the information tap. ReleaseCapture's functionality is: cancel the capture of mouse information. The Windows system is a message system that is waiting for the user's message, and adds a corresponding, but after processing a message, the system is waiting for the following rounds. Message delivery is the core of Windows. Let's place a button or other control in Form1, but this control must have a window handle (hwnd), such as the image control provided by the VB is a sub-graphic control, no window handle, and Picture, Command Button and other controls have a window handle We will take the Command Button to make a demonstration, add a Command button on Form1, add the following code inside the Command1_Mousemove () event: Private submmand1_mousemove (Button As Integer, _ Shift As Integer, x as single, y as single) with COMMAND1 'When the mouse is outside the control outside if NOT ((x <0) or (Y <0) or (Y> .height)) The' mouse pointer is outside the button, let other The control also received the standard event ReleaseCapture 'In order not to let the mousemove event repeatedly triggered if .caption <> "outside" the .caption = "Outside" End if' mouse pointer on the button, capturing him but the mouse is removed, we will receive the mouse Event setCapture .hWnd else .caption = "inside" end if End wirth SUB

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

New Post(0)