Hi all,
I found some small problem poping up menu. I created a Form2 with textbox, added to form2 menu, and replaced default menu textbox menu with mine. Then, created same other form2 with everything same plus added command button. Starting form will be second. In to Form2 set for menu load Form1, also and for the command button.
Now if run project with Form2 then press command button and request menu for textbox. Well' you'll that's fine!!! Now, If I load a form usinf Textbox's menu on Form2 to request Form1. In the textbox on Form1 you won't see a user menu enymore, just default.
Conclusion: using button command to load form with user menu - OK, but loading same form using textbox's popuping up menu - Nope!
How do I correct this problem using poping menu?
I have tried to using both methods of loading popup menu with same result:
FORM2
visual basic code:--------------------------------------------------------------------------------
Private Sub Command1_Click()
Form1.Show vbModal
End Sub
Private Sub First_Click()
Form1.Show vbModal
End Sub
'using subclassing
Private Sub Form_Load()
'hereefine a new window procedure for the text box
prevProc = SetWindowLong(Text2.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
'By disabling the textbox
Private Sub Text3_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Text3.Enabled = False
Call Text3_MouseUp(Button, Shift, x, y)
End If
End Sub
Private Sub Text3_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Text3.Enabled = True
PopupMenu mnu
End If
End Sub
visual basic code:--------------------------------------------------------------------------------
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 prevProc As Long
Public Const GWL_WNDPROC = (-4)
Const WM_CONTEXTMENU = &H7B
'this function intercepts all messages (events) sent to the textbox
'it forwards all messages to the default window procedure
'except the WM_CONTEXTMENU message
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_CONTEXTMENU Then
frm.PopupMenu frm.mnu
Else
WindowProc = CallWindowProc(prevProc, hWnd, uMsg, wParam, lParam)
End If
End Function
--------------------------------------------------------------------------------
FORM1:
visual basic code:--------------------------------------------------------------------------------
Private Sub Text3_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Text3.Enabled = False
Call Text3_MouseUp(Button, Shift, x, y)
End If
End Sub
Private Sub Text3_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Text3.Enabled = True
PopupMenu mnuPopup
End If
End Sub
--------------------------------------------------------------------------------
Last edited by Tomazas; August 17th, 2006 at 03:29 PM.
The code in your zip file is nothing like what you are showing here, and I am having a hard time trying to figure out what you are trying to do. Could you re-upload your zip and also maybe a step by step list of what you want to happen and what actually happens.
ETA: Check the zip. Is this what you want?
Last edited by sotoasty; August 17th, 2006 at 02:28 PM.
Reason: Might have figured out what the problem is.
Hi,
I cut out a bit... Made more simple.
Open project, run it. Click on button. You'll see Form2. In this form2 right click in textbox, to get user popup menu. You should see menu 'I want to see this menu'. This is how should work. But also need to get same using different way. Close Form2.
In Form1 right click in tetBox, you'll see menu 'Click here to open Form2'. This will load same form2. Now go to same textbox and do it right click. You'll see Windows standart menu! I want to see same menu as it was in first place: menu text 'I want to see this menu'.
For me seems to be that first popup menu is still in memory and it is not alowing to popup another menu in Form2.
How can I correct this?
Written code contains also SetWindowLong API call which gives me same result as this one. So I removed that part. I tried to use LockWindowUpdate before menu and after. This also did not helped.
Any idies?
That's very interesting. This is what appears to be happening to me. When you click on the textbox on form1 and show the menu, you then go straight into the context menu processing. Here you show form2 as modal and you are still in the menu processing until form2 closes. This seems to be preventing the context menu in form2 from showing. You can use the classes I posted here in the updated project to do your menu processing. This seems to work fine on my system.
Thanks for the replay, It seems to be working fine.
It just correction I added to form1:
Private Sub Text3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Dim MPF2 As New PopupMenu
MPF2.MenuItems.Add "1", "Show Form 2"
MPF2.MenuItems.Add "2", "Cancel"
Dim A As String
A = MPF2.ShowMenu
If A = "1" Then
Form2.Show vbModal
ElseIf A <> 0 Then
MsgBox MPF2.MenuItems(A).Caption & " was selected"
End If
Set MPF2 = Nothing
Text3.Enabled = True
End If
End Sub
Otherways you get an error when popup menu requested but nothing selected. I'll try to implement this to my application.
Thanks
Hi,
I have implemented succesfully your code into my application. My application contains Images in the Popup menus on form. Your way to get around form menu removed imaging form textbox's poping up menu, because it is created after click. Could you help me with that?
I want just to see image in my poping up menu in the textbox also as in the form menu. I did not wrote this code for imaging poping up menus, so its hard for me to find where should I change your source code to get imaging in textbox menu.
Thanks
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.