|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Overcoming a MsgBox's shynessI am working on an app in which, after all too long, I realized that the app
appeared to be hanging because a Msgbox that was likely hiding behind a Form that uses SetWindowPos to keep the Form on top. Looking at the constants for MsgBox, is vbMsgBoxSetForeground the right way to handle this? Or will the Form still hide the Msgbox? Hi Howard,
It depends on what value is used with SetWindowPos. If the form is set as topmost, then yes I'm pretty sure (untested) that it can be in front of a message box from another form. Show quoteHide quote "Howard Kaikow" <kai***@standards.com> wrote in message news:%23KiT$N$6JHA.5932@TK2MSFTNGP03.phx.gbl... >I am working on an app in which, after all too long, I realized that the >app > appeared to be hanging because a Msgbox that was likely hiding behind a > Form > that uses SetWindowPos to keep the Form on top. > > Looking at the constants for MsgBox, is vbMsgBoxSetForeground the right > way > to handle this? > Or will the Form still hide the Msgbox? > > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message In this case, it's more complex.news:eY$ikAA7JHA.4376@TK2MSFTNGP06.phx.gbl... > Hi Howard, > > It depends on what value is used with SetWindowPos. If the form is set as > topmost, then yes I'm pretty sure (untested) that it can be in front of a > message box from another form. The VB 6 program is dynamically creating an Excel workbook, and creating the code modules i nthe Excel workbook. one of which is the Workbook_BeforeClose event. I finally figured out that when the VB 6 program causes Excel to CLOSE the workbook just created, the code is hanging in the Workbook_BeforeClose event. After creation, the Excel workbook code works as expected. Problem only occurs when VB 6 is first creating the workbok via Excel. Fortunately, the MsgBox was only used to test the events, so I could just delete the Msgbox, but I then noticed the vbMsgBoxSetForeground constant. Testing that constant in a particular circumstance does not answer the general question. I asked here to get the experience of others.
Show quote
Hide quote
"Howard Kaikow" <kai***@standards.com> wrote... As long as you're testing you might also test vbSystemModal. It's not system > > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote... >> Hi Howard, >> >> It depends on what value is used with SetWindowPos. If the form is set >> as >> topmost, then yes I'm pretty sure (untested) that it can be in front of a >> message box from another form. > > In this case, it's more complex. > > The VB 6 program is dynamically creating an Excel workbook, and creating > the > code modules i nthe Excel workbook. one of which is the > Workbook_BeforeClose > event. > > I finally figured out that when the VB 6 program causes Excel to CLOSE the > workbook just created, the code is hanging in the Workbook_BeforeClose > event. > > After creation, the Excel workbook code works as expected. Problem only > occurs when VB 6 is first creating the workbok via Excel. > > Fortunately, the MsgBox was only used to test the events, so I could just > delete the Msgbox, but I then noticed the vbMsgBoxSetForeground constant. > > Testing that constant in a particular circumstance does not answer the > general question. > I asked here to get the experience of others. modal as described in help, but in my limited experience, it does bring the msgbox to the top of all applications. Similar to setting topmost. David "David Youngblood" <d**@flash.net> wrote in message I would rarely desire to have all other applications suspended.news:uSNRATB7JHA.1764@TK2MSFTNGP06.phx.gbl... > > "Howard Kaikow" <kai***@standards.com> wrote... > As long as you're testing you might also test vbSystemModal. It's not system > modal as described in help, but in my limited experience, it does bring the > msgbox to the top of all applications. Similar to setting topmost. If vbMsgBoxSetForeground does the deed, then the question becomes, why not always use vbMsgBoxSetForeground? "Howard Kaikow" <kai***@standards.com> wrote in message vbMsgBoxSetForeground does not do the deed, the VB 6 Form remains on top.news:uZmkfuD7JHA.5780@TK2MSFTNGP04.phx.gbl... > I would rarely desire to have all other applications suspended. > > If vbMsgBoxSetForeground does the deed, then the question becomes, why not > always use vbMsgBoxSetForeground? I guess that the workaround would be to use another Form, instead of a MsgBox, and hope that it goes on top of the main Form.
Show quote
Hide quote
"Howard Kaikow" <kai***@standards.com> wrote in message I just saw a note in the VB & VBA in a Nutshell book.news:uZmkfuD7JHA.5780@TK2MSFTNGP04.phx.gbl... > "David Youngblood" <d**@flash.net> wrote in message > news:uSNRATB7JHA.1764@TK2MSFTNGP06.phx.gbl... > > > > "Howard Kaikow" <kai***@standards.com> wrote... > > As long as you're testing you might also test vbSystemModal. It's not > system > > modal as described in help, but in my limited experience, it does bring > the > > msgbox to the top of all applications. Similar to setting topmost. > > I would rarely desire to have all other applications suspended. > > If vbMsgBoxSetForeground does the deed, then the question becomes, why not > always use vbMsgBoxSetForeground? On multitasking OS, vbSystemModal only has the effect of being on top. So vbSystemModal does do the deed, It would have been nice if MSFT had mentioned this in the Help for MsgBox. "Howard Kaikow" <kai***@standards.com> wrote in message > In 16 bit windows I beleive it was system modal. This was changed with 32 > I just saw a note in the VB & VBA in a Nutshell book. > > On multitasking OS, vbSystemModal only has the effect of being on top. > So vbSystemModal does do the deed, > > It would have been nice if MSFT had mentioned this in the Help for MsgBox. bit windows, but the vb help was not updated. David "Howard Kaikow" <kai***@standards.com> wrote in message This may or may not work: Use MessageBox() API function, and set the hWnd to news:%23KiT$N$6JHA.5932@TK2MSFTNGP03.phx.gbl... >I am working on an app in which, after all too long, I realized that the >app > appeared to be hanging because a Msgbox that was likely hiding behind a > Form > that uses SetWindowPos to keep the Form on top. > > Looking at the constants for MsgBox, is vbMsgBoxSetForeground the right > way > to handle this? > Or will the Form still hide the Msgbox? the owner form. MsgBox() doesn't have that option. "Nobody" <nob***@nobody.com> wrote in message That likely would work, but I now see that vbSystemModal does the deed.news:ubdmF5D7JHA.4376@TK2MSFTNGP06.phx.gbl... > This may or may not work: Use MessageBox() API function, and set the hWnd to > the owner form. MsgBox() doesn't have that option. On a multitasking OS, why would one not want to use vbSystemModal ALL the time? "Howard Kaikow" <kai***@standards.com> wrote in message Because if the user was working on app1, and app2 decided to show a message, news:%23s5C99D7JHA.5780@TK2MSFTNGP04.phx.gbl... > "Nobody" <nob***@nobody.com> wrote in message > news:ubdmF5D7JHA.4376@TK2MSFTNGP06.phx.gbl... >> This may or may not work: Use MessageBox() API function, and set the hWnd > to >> the owner form. MsgBox() doesn't have that option. > > That likely would work, but I now see that vbSystemModal does the deed. > > On a multitasking OS, why would one not want to use vbSystemModal ALL the > time? the user's work is not interrupted, and app2 window and taskbar button flashes. "Nobody" <nob***@nobody.com> wrote in message In this case, the prog is automatically run right after the install of anews:OflsNCE7JHA.1196@TK2MSFTNGP03.phx.gbl... > Because if the user was working on app1, and app2 decided to show a message, > the user's work is not interrupted, and app2 window and taskbar button > flashes. DLL. If the user wishes, the program could be run anytime after the install. But, in this case, I was using the Msgbox only to test the Workbook_BeforeClose event, so this particular MsgBox will not be in the final code. Perhaps, I should use the MessageBox API whenever I use a topmost Form? "Howard Kaikow" <kai***@standards.com> wrote in message I don't know, however, if you need to use MessageBox, make a wrapper for it news:e3LmFQE7JHA.1420@TK2MSFTNGP04.phx.gbl... > Perhaps, I should use the MessageBox API whenever I use a topmost Form? to make things easier. Here is an example: Public Sub ShowMsgBox(Prompt As String, _ Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, _ Optional ByVal Title As String = "") ' Add code here End Sub So all you need is to change MsgBox to ShowMsgBox. I used "VbMsgBoxStyle" so button names would show in intellisense.
Show quote
Hide quote
"Nobody" <nob***@nobody.com> wrote in message I've got code using MessageBox and MessageBoxEx. I'd use a wrapper if Inews:OpmAWVE7JHA.1432@TK2MSFTNGP02.phx.gbl... > "Howard Kaikow" <kai***@standards.com> wrote in message > news:e3LmFQE7JHA.1420@TK2MSFTNGP04.phx.gbl... > > Perhaps, I should use the MessageBox API whenever I use a topmost Form? > > I don't know, however, if you need to use MessageBox, make a wrapper for it > to make things easier. Here is an example: > > Public Sub ShowMsgBox(Prompt As String, _ > Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, _ > Optional ByVal Title As String = "") > > ' Add code here > > End Sub > > So all you need is to change MsgBox to ShowMsgBox. I used "VbMsgBoxStyle" so > button names would show in intellisense. decided to oft use the critter. Option Explicit Private Const HWND_TOPMOST = -1 Private Const SWP_NOACTIVATE = &H10 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const SWP_SHOWWINDOW = &H40 Private Const MB_DEFBUTTON1 = &H0& Private Const MB_DEFBUTTON2 = &H100& Private Const MB_DEFBUTTON3 = &H200& Private Const MB_ICONASTERISK = &H40& Private Const MB_ICONEXCLAMATION = &H30& Private Const MB_ICONHAND = &H10& Private Const MB_ICONINFORMATION = MB_ICONASTERISK Private Const MB_ICONQUESTION = &H20& Private Const MB_IConstOP = MB_ICONHAND Private Const MB_OK = &H0& Private Const MB_OKCANCEL = &H1& Private Const MB_YESNO = &H4& Private Const MB_YESNOCANCEL = &H3& Private Const MB_ABORTRETRYIGNORE = &H2& Private Const MB_RETRYCANCEL = &H5& Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" _ (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long Private Declare Sub SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _ ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) Private Sub btnExit_Click() Unload Me End Sub Private Sub btnRunMe_Click() MessageBox Me.hWnd, "At the tone the time WAS" & vbCrLf & vbCrLf & Now, App.Title, MB_OK End Sub Private Sub Form_Activate() MakeFormTopmost Me End Sub Private Sub MakeFormTopmost(frm As Form) SetWindowPos frm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _ SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE End Sub |
|||||||||||||||||||||||