AnsweredAssumed Answered

System modal messagebox causing problems with RMB context menu

Question asked by Steven Soeder on Nov 5, 2014
Latest reply on Nov 10, 2014 by Steven Soeder

I've written a VBA 7.0 program which automates some things in Solidworks.  One of the things I have to do is check for typos in a few areas within the Solidworks document.  What I've done is use an API call to MessageBoxW to display a system modal message box so they have the opportunity to fix the typo before continuing, or cancel.

The messagebox displays fine, and I can go into the running Solidworks application and work within it, but when I right-click within the program and try to use the RMB context menu, some weird stuff starts happening.

1) The mouse buttons no longer work within the program or on the messagebox window.  Other application windows continue to respond just fine, but any mouse clicks (RMB or LMB) anywhere within the Solidworks application window or in the messagebox window do nothing. The windows are not frozen - I can hit escape key to exit the context menu and then everything works fine.  The mouse button clicks just seem to not register while the context menu is up.


2) The RMB context menu "becomes system modal".  I'm not sure if that's what is happening, but best way I could think to describe it.  Essentially the context menu will keep displayed on top of all other application windows.  I can still work within other windows though with no negative effects other than the context menu being in the way.

Not sure if this is an issue with Solidworks, the MessageBoxW function, or a combination of both.



I'm calling the API functions like this:

lngReply=WinMsgBox(Prompt:="Can you do this thing for me? blah blah",Title:="Action required",Buttons:=vbOkCancel + vbInformation + vbSystemModal



Option Explicit
Private Declare PtrSafe Function MessageBoxW Lib "User32" _
                                       (Optional ByVal hWnd As Long, _
                                        Optional ByVal Prompt As LongPtr, _
                                        Optional ByVal Title As LongPtr, _
                                        Optional ByVal Buttons As Long) _
                                    As Long
Public Function WinMsgBox(Optional ByRef hWnd As Long, _
                        Optional ByRef Prompt As String, _
                        Optional ByRef Title As String, _
                        Optional ByRef Buttons As Long) _
                    As Long
WinMsgBox = MessageBoxW(hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
End Function