Make msgbox appear ontop of a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Maiapu
    Contributor
    • Feb 2010
    • 259

    #1

    Make msgbox appear ontop of a form

    Hi everyone,
    I have just created a form and made it to stay on top of non-Microsoft Access forms and windows using examples modules here: http://support.microsoft.com/kb/210500. Which works fine.

    But the problem occurs when a message box is populated on the form; it appears at the back of the active form.
    Can one genius tell how to make the msg box appear on top of the active form as usual.
    I know that this is a result of the modules making active form to stay on top of the msgbox but can one smart person know any way around this to make the msgbox stay on top of the form?

    For those who are interested in the code module:
    This is how I did it.

    I created a module called FormsOnTop:

    Code:
    Option Compare Database
    Option Explicit
    '.........................................................................
    
    Declare Function 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) As Long
                        
    
    Global Const HWND_TOPMOST = -1
    Global Const SWP_NOSIZE = &H1
    Global Const SWP_NOMOVE = &H2
                
    Function TopMost(F As Form)
       Call SetWindowPos(F.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
                         SWP_NOMOVE Or SWP_NOSIZE)
    End Function
    Then on the OnTimer event of the formI set the following properties:
    Popup: Yes
    OnTimer: =TopMost(Form)
    TimerInterval: 50



    I have absolutely know idea on how to make the msgbox appear ontop of the form.

    Hope someone helps..


    Thanks

    Jerry
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Why not surround your message box call with code to turn off these form properties (before the call) and reset them after the msgbox call?

    Jim

    Comment

    • Jerry Maiapu
      Contributor
      • Feb 2010
      • 259

      #3
      Can you give an hint on how to do this please

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Unfortunately Jerry, I'm not familar with the function you are using so I'm not sure how to turn it off. But Jim is right in that it's the only way to achieve this. Your code is actually overwriting the normal behavior of the msgbox which is in itself a popup dialog box that would normally have total focus until the user actions it. Someone more familar with the code you are using may know the code for reversing it.

        Comment

        • Jerry Maiapu
          Contributor
          • Feb 2010
          • 259

          #5
          Originally posted by msquared
          Unfortunately Jerry, I'm not familar with the funtion you are using so I'm not sure how to turn it off. But Jim is right in that it's the only way to achieve this. Your code is actually overwriting the normal behavior of the msgbox which is in itself a popup dialog box that would normally have total focus until the user actions it. Someone more familar with the code you are using may know the code for reversing it.
          If any smart person knows how to go around this like
          Originally posted by msquared
          .
          says, please do so as this is like Banging my Head against the Brickwall. I would very much appreciate.

          Thanks

          Comment

          • jimatqsi
            Moderator Top Contributor
            • Oct 2006
            • 1293

            #6
            Okay, so you've got this function called TopMost that makes a form stay on top. I suppose the parameter value HWND_TOPMOST is the one controlling the behavior that keeps this window on top.

            So how do you reverse that setting? I see that HWND_TOPMOST has a value of True/-1. So do you put a False/zero in place of that HWND_TOPMOST value that goes to the SetWindowPos API call? I don't know, but let's say that's how you do it. What you need to do is make another function called
            NotTopMost

            This function will call the SetWindowPos API call with the parameter values that will turn off this feature. Once you have created NotTopMost, then you will change your code for the msgbox so it is like this ...

            Code:
            Call NotTopMost  ' turn off the always on top setting
            Msgbox "whatever that message is"
            Call TopMost   ' turn the always on top setting back on
            That will solve your problem.

            Jim
            Last edited by jimatqsi; Jun 15 '10, 01:13 AM. Reason: wrap the lines of code

            Comment

            • Jerry Maiapu
              Contributor
              • Feb 2010
              • 259

              #7
              Originally posted by jimatqsi
              Okay, so you've got this function called TopMost that makes a form stay on top. I suppose the parameter value HWND_TOPMOST is the one controlling the behavior that keeps this window on top.

              So how do you reverse that setting? I see that HWND_TOPMOST has a value of True/-1. So do you put a False/zero in place of that HWND_TOPMOST value that goes to the SetWindowPos API call? I don't know, but let's say that's how you do it. What you need to do is make another function called
              NotTopMost

              This function will call the SetWindowPos API call with the parameter values that will turn off this feature. Once you have created NotTopMost, then you will change your code for the msgbox so it is like this ...

              Code:
              Call NotTopMost  ' turn off the always on top setting
              Msgbox "whatever that message is"
              Call TopMost   ' turn the always on top setting back on
              That will solve your problem.

              Jim
              Honestly you're smart I'll try and get around this and see what happens

              Comment

              • jimatqsi
                Moderator Top Contributor
                • Oct 2006
                • 1293

                #8
                Jerry, you thing I'm smart? You should see some of the solves the experts here at Bytes come up with. We have a lot of geniuses here. :)

                Please tag the best reply. I don't know why, but I know they request that be done.

                Jim

                Comment

                • Jerry Maiapu
                  Contributor
                  • Feb 2010
                  • 259

                  #9
                  Well, thank you ladies and gents you're all smart. I very much appreciate this community.
                  I'll tag the best answer as soon as am done.
                  Thanks.

                  Comment

                  Working...