Results 1 to 9 of 9

Thread: MsgBox does not come to foreground

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    79

    MsgBox does not come to foreground

    There is an application that calls an EXE that I developped in VB.NET
    This EXE opens a word application:

    Code:
    objWordInstance = GetObject(, "Word.Application")
    
    If objWordInstance Is Nothing Then
        objWordInstance = CreateObject("Word.Application")
    End If
    After that I try to show a MessageBox but it is always hidden behind my word application. Any idea what to do?

  2. #2
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    That happends alot in my apps too, but I couldn't fiqure it out.

  3. #3
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Question

    Try this: objWordInstance.Visible = False

    It might be the solution you're looking for.
    ~Peter


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    79
    Thanks, but I found another solution:
    Now I use the optional parameter owner (type IWin32Window) to specify the application/window the messagebox belongs to.

  5. #5
    Member
    Join Date
    Feb 2000
    Location
    South Africa
    Posts
    40
    Hi Heike

    How do you find the IWin32Window value to send as parameter. I have got the same problem, with with Visio. Visio has a WindowHandle32 property, an integer. What do I send through as parameter to make the form / messagebox modal to Visio.

    Thanks in advance,

    Linda

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    79
    Hi Linda,

    first I built a new class

    VB Code:
    1. Public Class ActiveWindow
    2.     Implements IWin32Window
    3.  
    4.     Private Declare Function GetForegroundWindow Lib "user32.dll" () As Integer
    5.  
    6.     Private Sub New()
    7.     End Sub
    8.  
    9.     Private Shared _window As ActiveWindow = New ActiveWindow()
    10.  
    11.     'Properties
    12.     Public Shared ReadOnly Property Active() As IWin32Window
    13.         Get
    14.             Return _window
    15.         End Get
    16.     End Property
    17.  
    18.     Public ReadOnly Property Handle() As IntPtr Implements System.Windows.Forms.IWin32Window.Handle
    19.         Get
    20.             Return New System.IntPtr(GetForegroundWindow())
    21.         End Get
    22.     End Property
    23. End Class

    Then I wrote the following sub

    VB Code:
    1. Public Function ShowMessageBox(ByVal strMessage As String, Optional ByVal strTitle As String = "", _
    2. Optional ByVal objButtons As MessageBoxButtons = MessageBoxButtons.OK, _
    3. Optional ByVal objIcon As MessageBoxIcon = MessageBoxIcon.Exclamation, _
    4. Optional ByVal objDefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1) As DialogResult
    5.  
    6.     Dim udtActiveWindow As ActiveWindow
    7.     Dim drReturn As DialogResult
    8.  
    9.     Try
    10.         drReturn = MessageBox.Show(udtActiveWindow.Active, strMessage, strTitle, objButtons, objIcon, objDefaultButton)
    11.     Catch
    12.         ErrorMessage(Err.GetException.TargetSite.GetCurrentMethod.ReflectedType.Name, Err.GetException.TargetSite.GetCurrentMethod.Name)
    13.     End Try
    14.  
    15.     Return drReturn
    16. End Function

    Hope that helps.

  7. #7
    Member
    Join Date
    Feb 2000
    Location
    South Africa
    Posts
    40
    Hi Heike,

    Thanks for the code, it cleared up a lot. The problem I have now, is that I can't minimize Visio while the modal form / message box is open. Do you have the same problem? That bothers a bit, because I would like my form to act the same way as Visio's modal forms.

    If you have any suggestions or ideas, please ...

    Linda

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    79
    Linda,

    indeed I do have the same problem or at least I would call it effect. But in my application I do find it senseful because if a message box is open, there is something the user must be informed of and I don't want him/her to do anything until the message was being read.

    Unfortunately I have no idea. I would have thought that there might be an optional parameter or something like that to switch between modal and not modal but I can't find anything. Sorry....
    But if you find something, please could you tell me?! (Maybe one day I need it, too)

    Heike

  9. #9
    Member
    Join Date
    Feb 2000
    Location
    South Africa
    Posts
    40
    Hi Heike,

    Thanks for the reply. I will let you know if I find anything that will solve this. Once again, thanks for your help and good luck with your app.

    Linda

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width