|
-
Oct 30th, 2002, 09:04 AM
#1
Thread Starter
Frenzied Member
Weird reaction on a popup menu *RESOLVED*
I have text box which has has a popup menu associated with the right click of the mouse, however, the user is required to click twice in order for my menui to appear. The first click displays the Cut,Copy,Paste menu and then the next click shows my menu. I have stepped through the code and the event is firing.
any suggestions?
Mega.
Last edited by Mega_Man; Oct 30th, 2002 at 03:52 PM.
"If at first you don't succeed, then skydiving is not for you"
-
Oct 30th, 2002, 09:30 AM
#2
I believe the only way to turn off the built-in menu is through message hooking. Are you aware of message hooking and it's problems? If not, then one thing you need to know is that when message hooking is active, if you stop your running program by clicking the little "End" button on the IDE menu, VB crashes. To get around that annoying behavior I have a Conditional Compilation Argument called Testing that I turn on in development and off when I compile.
VB Code:
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
' In Form_Load do the following (you could use the For Each method of stepping through the controls)
For intIndex = 0 To Controls.Count - 1
#If Testing Then
' Don't hook
#Else
If TypeOf Controls(intIndex) Is TextBox Then
' Turn off the TextBox system right-click menu
Call Hook(Controls(intIndex).hwnd)
End If
#End If
Next
Private Sub Form_Unload(Cancel As Integer)
Call UnHook
End Sub
Public Sub Hook(hwnd As Long)
lngHWnd = hwnd
lpPrevWndProc = SetWindowLong(lngHWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
-
Oct 30th, 2002, 09:38 AM
#3
Thread Starter
Frenzied Member
Martin,
Thanks a lot. Much appreciated. 
Mega.
"If at first you don't succeed, then skydiving is not for you"
-
Oct 30th, 2002, 11:06 AM
#4
Thread Starter
Frenzied Member
Martin,
Are there a couple of API calls missing here?
I cannot seem to get it to work. Missing reference to WindowProc etc..
Mega.
"If at first you don't succeed, then skydiving is not for you"
-
Oct 30th, 2002, 11:11 AM
#5
Sorry...
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
Also I believe that the Hook and UnHook subs need to be in a code module.
-
Oct 30th, 2002, 11:13 AM
#6
and 
VB Code:
Public Const WM_RBUTTONUP = &H205
Public lpPrevWndProc As Long
Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP
'Do nothing
'Or popup you own menu
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hwnd, _
uMsg, wParam, lParam)
End Select
End Function
-
Oct 30th, 2002, 11:23 AM
#7
Thread Starter
Frenzied Member
"If at first you don't succeed, then skydiving is not for you"
-
Nov 28th, 2002, 10:00 AM
#8
Lively Member
hi there
how do you actually use the windowproc procedure?
can you please send me an example?
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|