|
-
Jul 1st, 2008, 10:46 AM
#1
[RESOLVED] MsgBox focus question
I have a project that the user works two windows at once split so they are visible on the same screen.. Form1 is the main VBP project and works in junction with an OCX that controls a third party viewer. When the user clicks save on Form1 it has the focus. Then it calls the OCX which displays a msgbox which is under form1. The reverse happens when the user makes selections on the viewer. It has focus and when control passes back to form1 and displays a message it is under the viewer. How can I make the message box stay in front of both forms? I tried me.setfocus in the OCX and it doesn’t seem to support it. Someone pointed me at an API that is called SetWindowPos but it doesn’t seem to work. “Using MsgBox "test", vbMsgBoxSetForeground” seems to set it in front but I need to check for a yes no response.
Any suggestions?
-
Jul 1st, 2008, 10:58 AM
#2
Re: MsgBox focus question
Is your form1 set as the topmost form perhaps? Otherwise a msgbox should display above its parent form.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 1st, 2008, 10:58 AM
#3
Re: MsgBox focus question
It depends on message box instance. Here is a Unicode aware API version of the standard messagebox:
Code:
Option Explicit
Private Declare Function MessageBoxIndirectW Lib "user32" (lpMsgBoxParams As MsgBoxParams) As Long
Private Const MB_USERICON = &H80&
Private Type MsgBoxParams
cbSize As Long
hWndOwner As Long
hInstance As Long
lpszText As Long
lpszCaption As Long
dwStyle As Long
lpszIcon As Long
dwContextHelpId As Long
lpfnMsgBoxCallback As Long
dwLanguageId As Long
End Type
' note: I didn't bother to go ahead and start hacking with HelpFile and Context
Public Function MsgBox(ByVal Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal Title As String, Optional ResourceIcon As String, Optional hWndOwner As Long) As VbMsgBoxResult
Dim udtMsgBox As MsgBoxParams
' if no owner is specified, try to use the active form
If hWndOwner = 0 Then If Not Screen.ActiveForm Is Nothing Then hWndOwner = Screen.ActiveForm.hWnd
With udtMsgBox
.cbSize = Len(udtMsgBox)
' important to set owner to get behavior similar to the native MsgBox
.hWndOwner = hWndOwner
.hInstance = App.hInstance
' set the message
.lpszText = StrPtr(Prompt)
' if no title is given, use the application title like the native MsgBox
If LenB(Title) = 0 Then Title = App.Title
.lpszCaption = StrPtr(Title)
' thought this would be a nice feature addition
If LenB(ResourceIcon) = 0& Then
.dwStyle = Buttons
Else
.dwStyle = (Buttons Or MB_USERICON) And Not (&H70&)
.lpszIcon = StrPtr(ResourceIcon)
End If
End With
' show the message box
MsgBox = MessageBoxIndirectW(udtMsgBox)
End Function
The things of interest for you are hInstance and hWndOwner. As long as you set the the same owner and instance in each call, you get the same kind of behavior.
-
Jul 1st, 2008, 11:04 AM
#4
Re: MsgBox focus question
 Originally Posted by RobDog888
Is your form1 set as the topmost form perhaps? Otherwise a msgbox should display above its parent form.
I probably should have been clearer. Form1 is the project. The first of the two forms the user is working with is a dll. The dll calls the ocx. Those two are what's sharing the screen and hiding each others message boxes.
So...the main screen is up, the user calls the dll display and the form1 goes to the tool bar. Clicking on the dll calls the ocx display which is now side by side with the dll display Working between the two is where they are blocking each others messages.
-
Jul 1st, 2008, 12:20 PM
#5
Re: MsgBox focus question
This seems to work fine:
MsgBox "text", vbInformation + vbMsgBoxSetForeground, "text"
-
Jul 1st, 2008, 01:48 PM
#6
Re: MsgBox focus question
 Originally Posted by TysonLPrice
This seems to work fine:
MsgBox "text", vbInformation + vbMsgBoxSetForeground, "text"
But, that doesn't seem to satisfy this requirement.
 Originally Posted by TysonLPrice
I need to check for a yes no response.
Don't you need to add a vbYesNo in there?
-
Jul 2nd, 2008, 04:36 AM
#7
Re: MsgBox focus question
 Originally Posted by Hack
But, that doesn't seem to satisfy this requirement.Don't you need to add a vbYesNo in there?
Yes...What I posted was from the form load of a simple project to test and to show what works for keeping the msgbox on top in case someone searches in the future. This is what I actually used:
Code:
Select Case MsgBox("Do you want to index the remaining pages after the split?" & vbCrLf & _
"Clicking 'No' will delete the remaining pages", vbYesNoCancel + vbMsgBoxSetForeground, "Confirm Keep Pages.")
Case vbYes
bKeepRemainingPages = True
Case vbNo
bKeepRemainingPages = False
Case vbCancel
Exit Function
End Select
Last edited by TysonLPrice; Jul 2nd, 2008 at 04:50 AM.
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
|