Hello all, hope you can clear this puzzle for me.
On the main form in load event I have
Ok, this works fine, it adds a line in systemmenu and calls given proc (Handler(...))
But then I close the program it quits VB IDE as well.
Ok, I guess I should restore previous WNDPROC, do I?
Here interesting things starts.
If I put the code for restoring WNDPROC say to keyPress window, like this
and press this key - then I exit OK and go to VB IDE.
BUT! If I put that very code (except If KeyAscii = ... ) in form's Query Unload - it bombs out of VB IDE.
I checked that I do not try to do it twice (Hooked global var), I even added logging to file to check if I have multyple calls of load / query unload - no, it called only once... I checked returned val of SetWindowLong (res variable), it's not 0. Actually I believe it's same value - be it called from query Unload or KeyPress.
So far I just commented out piece that adds line to menu.
But it really makes me wonder what I doing wrong.
Any ideas?
On the main form in load event I have
Code:
Dim Lng_Menu&
Lng_Menu = GetSystemMenu(hwnd, False)
AppendMenuA Lng_Menu, MF_SEPARATOR, 0, vbNullString
AppendMenuA Lng_Menu, MF_CALLBACKS, &HF, "About"
If Not Hooked Then
lpOldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf Handler)
Hooked = True
End If
But then I close the program it quits VB IDE as well.
Ok, I guess I should restore previous WNDPROC, do I?
Here interesting things starts.
If I put the code for restoring WNDPROC say to keyPress window, like this
Code:
Dim Lng_Menu As Long, res As Long
If KeyAscii = Asc("q") Then
'reset handler to prev
If Hooked Then
Lng_Menu = GetSystemMenu(Me.hwnd, False)
res = SetWindowLong(hwnd, GWL_WNDPROC, lpOldProc)
Hooked = False
Close #1
End If
BUT! If I put that very code (except If KeyAscii = ... ) in form's Query Unload - it bombs out of VB IDE.
I checked that I do not try to do it twice (Hooked global var), I even added logging to file to check if I have multyple calls of load / query unload - no, it called only once... I checked returned val of SetWindowLong (res variable), it's not 0. Actually I believe it's same value - be it called from query Unload or KeyPress.
So far I just commented out piece that adds line to menu.
But it really makes me wonder what I doing wrong.
Any ideas?