Home All Groups Group Topic Archive Search About

VB crash on .PopupMenu .zmnuDemo Defaultmenu

Author
29 Jan 2006 3:13 PM
vonclausowitz
Hi All,

I have used the following code to create an icon in the systray and
have a popupmenu underneath the icon. Now I want to have the
defaultmenu item in Bold but if I add the next line the whole thing
crashes:

..PopupMenu .zmnuDemo,,,,mFile(9)

Any ideas?

Public Function WindowProc(ByVal hWnd As Long, _
                           ByVal uMsg As Long, _
                           ByVal wParam As Long, _
                           ByVal lParam As Long) As Long

    On Error Resume Next

   Select Case hWnd

     'form-specific handler
      Case Main.hWnd

         Select Case uMsg
           'WM_MYHOOK was defined as
           'the .uCallbackMessage
           'message of NOTIFYICONDATA
            Case WM_MYHOOK

              'maintain focus on the app
              'window to assure the menu
              'disappears should the mouse
              'be clicked outside the menu
               'volgende uitgeschakeld is niet
nodig!!!!!!!!!!!!!!!!!!!!!!!!!!!!
               'Call SetForegroundWindow(Main.hWnd)

              'lParam is the value of the message
              'that generated the tray notification.
               Select Case lParam
                  Case WM_RBUTTONUP:

                    'show the menu
                     With Main
                        .PopupMenu .zmnuDemo
                     End With

               End Select

           'handle any other form messages by
           'passing to the default message proc
            Case Else

               WindowProc = CallWindowProc(defWindowProc, _
                                            hWnd, _
                                            uMsg, _
                                            wParam, _
                                            lParam)
               Exit Function

         End Select


     'this takes care of messages when the
     'handle specified is not that of the form
      Case Else

          WindowProc = CallWindowProc(defWindowProc, _
                                      hWnd, _
                                      uMsg, _
                                      wParam, _
                                      lParam)
   End Select

End Function

Regards
Marco
The Netherlands

Author
30 Jan 2006 3:40 PM
Ken Halter
<vonclausow***@gmail.com> wrote in message
news:1138547628.845328.242590@g49g2000cwa.googlegroups.com...
>                  Case WM_RBUTTONUP:
>
>                    'show the menu
>                     With Main
>                        .PopupMenu .zmnuDemo
>                     End With
>
>               End Select

What you're doing there is halting all message processing for the subclassed
window.

You might want to try dropping a timer on 'Main' and use this instead....

>                  Case WM_RBUTTONUP:
>
>                    'show the menu
>                     With Main
                            .Timer1.Interval = 1
                            .Timer1.Enabled = True
                       End With

'In the timer routine....
Private Sub Timer1_Timer()
   Timer1.Enabled = False
   With Main
      .PopupMenu .zmnuDemo
   End With
End Sub


--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Author
30 Jan 2006 5:45 PM
vonclausowitz
Ken,

The problem is this line:
..PopupMenu .zmnuDemo,,,,mFile(9)

to be more specific the last part: ,,,,mFile(9)
with that it crashes, without it works. Why does it do that?
I must be able to set a defaultItem in bold, aint I?

Marco
Author
30 Jan 2006 6:29 PM
Ken Halter
<vonclausow***@gmail.com> wrote in message
news:1138643140.246443.289890@f14g2000cwb.googlegroups.com...
> Ken,
>
> The problem is this line:
> .PopupMenu .zmnuDemo,,,,mFile(9)
>
> to be more specific the last part: ,,,,mFile(9)
> with that it crashes, without it works. Why does it do that?
> I must be able to set a defaultItem in bold, aint I?
>
> Marco

It "should" work. I still think it's quite a bit risky to use modal behavior
(popup menu is modal) in a message handler. Just for kicks, try the timer
method. It should work "better" for a couple of reasons. First of all (and
most importantly), it allows the messages to keep flowing through your
message handler and secondly, the code is where it belongs... in the main
form. The last reason to try it is.... it'll only take a minute <g>

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Author
30 Jan 2006 7:24 PM
vonclausowitz
You mean getting rit of this whole function:

Public Function WindowProc?

and use the timer instead?

Marco