Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form_MouseMove over "x" button? Way to know? 1

Status
Not open for further replies.

patrickdrd

Programmer
Nov 21, 2003
149
GR
Hi everyone!

Is there a way to know (in Form_MouseMove event) when the mouse passes over the "x" button?

I' m looking of a way to change the vbhourglass pointer when the mouse passes over the "x" button to vbdefault.

Thanks in advance!
 
Seen something similar in the VBA forum
Alternate Text on A Command Button(thread707-1159453)


________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Put that in buttons MouseMove event..

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
something like..

Code:
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Screen.MousePointer = vbDefault
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Screen.MousePointer = vbHourglass
End Sub


------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
I am OK with the command button, my form has a cancel command button which changes the pointer to vbdefault when the mouse is over it,

but I want to make it change when the pointer is over the "x" button (Unload button - top right corner of the form)
 
Is it possible to provide me with an example?

Thanks for the help.
 
Create a new project with a form. Add the following code to the form:
Code:
[blue]Option Explicit

Private Sub Form_Load()
    lpPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ' Remove subclassing
    If lpPrevWndProc <> 0 Then SetWindowLong hwnd, GWL_WNDPROC, lpPrevWndProc
End Sub[/blue]
Then add a module, and add the following to that module:
Code:
[blue]Option Explicit

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const GWL_WNDPROC = (-4)
Public lpPrevWndProc As Long

Private Const WM_NCHITTEST = &H84
Private Const HTCLOSE = 20

Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If Msg = WM_NCHITTEST Then
        If DefWindowProc(hwnd, Msg, wParam, lParam) = HTCLOSE Then
            If Screen.MousePointer <> vbHourglass Then
                Screen.MousePointer = vbHourglass
            End If
        Else
            If Screen.MousePointer <> vbDefault Then
                Screen.MousePointer = vbDefault
            End If
        End If
    End If
    WindowProc = CallWindowProc(lpPrevWndProc, hwnd, Msg, wParam, lParam)
End Function[/blue]

Note: make sure that you close the program in the IDE through the Form's 'X' button (or its system menu), otherwise the IDE will probably blow up (do a keyword search in this forum on subclassing to find threads from number of us that explains why)
 
Probably safest way is to skin your form and use your own close button in the Controlbox(titlebar).

________________________________________________________
Zameer Abdulla
Help to find Missing people
Seek counsel of him who makes you weep, and not of him who makes you laugh.
 
This code is for a form with a progress bar control I' m working on.

Will subclassing slow down my code?
 
>skin your form

Oh dear

>Will subclassing slow down my code?

Depends what you do in the WindowProc
 
Nothing else than what strongm suggested.

Is this a slowdown?
 
Erm .. I am strongm, and the answer is that it shouldn't cause a slowdown that your users can notice
 
<Will subclassing slow down my code?

Well, I tried it, and I don't notice a slowdown. I got a quick eye, too. :)

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top