Move the form to the vicinity of the mouse (VB6)

Source: Internet
Author: User
Private   Declare   Function getcursorpos () Function Getcursorpos Lib   " USER32 " (Lppoint As Pointapi) As   Long
Private   Declare   Sub getclientrect () Sub Getclientrect Lib   " USER32 " ( Byval Hwnd As   Long , Lprect As Rect)
Private   Declare   Function movewindow () Function Movewindow Lib   " USER32 " ( Byval Hwnd As   Long , Byval X As   Long , Byval Y As   Long , Byval Nwidth As   Long , Byval Nheight As   Long , Byval Brepaint As   Long ) As   Long
Private Type rect
Left   As   Long
Top As   Long
Right   As   Long
Bottom As   Long
End Type

Private Type pointapi
X As   Long
Y As   Long
End Type
Private Cursorpoint As Pointapi
Private Dialogrect As Rect

' Move the form near the mouse
Public   Sub movedialogtocursor () Sub Movedialogtocursor ( Byref Moveform As Form)
Getcursorpos cursorpoint
Getclientrect moveform. hwnd, dialogrect
Movewindow moveform. hwnd, cursorpoint. x +   10 , Cursorpoint. Y +   10 , Dialogrect. Right - Dialogrect. Left, dialogrect. Bottom - Dialogrect. Top, 0

If Moveform. Left + Moveform. Width > Screen. Width -   10   Then
Moveform. Left = Screen. Width - Moveform. Width -   10
End   If

If Moveform. Top + Moveform. Height > Screen. Height -   10   Then
Moveform. Top = Screen. Height - Moveform. Height -   10
End   If

Getclientrect moveform. hwnd, dialogrect
If Dialogrect. Right < Cursorpoint. x And Dialogrect. Bottom < Cursorpoint. Y Then
Movewindow moveform. hwnd, cursorpoint. x - (Dialogrect. Right - Dialogrect. Left) -   10 , Cursorpoint. Y - (Dialogrect. Bottom - Dialogrect. Top) -   10 , Dialogrect. Right - Dialogrect. Left, dialogrect. Bottom - Dialogrect. Top, 0
End   If
End sub

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.