Results 1 to 12 of 12

Thread: msgBox to front

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    msgBox to front

    How can I set a msgBox (or the main form) to de front of the screen after an other program is started?
    The form (my program) is in the taskbar, when I click on it is right there where I want it !

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: msgBox to front

    Quote Originally Posted by Kars Lensen View Post
    How can I set a msgBox (or the main form) to de front of the screen after an other program is started?
    The form (my program) is in the taskbar, when I click on it is right there where I want it !
    Since many years ago Windows has taken measures to avoid just that: that a program can steal the focus.
    The reason is because it is very anoying to the user when she/he is working on something on some program, suppose she is pressing keys because she is writing a letter in Word, and when she look at the Screen she finds that she didn't write anything, because there is a popup window there.

    Then, what Windows currently does, is to make the program that is requiring attention to blink in the taskbar.

    Another option is to show a balloon tooltip at the system tray.

    The question is, what other program is started? Why your program is not on focus?

    It is still possible to steal the focus, but it is not so easy and not recomended anyway for the reason stated above.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: msgBox to front

    There is a vbSystemModal flag that can be used with the MsgBox. But, as Eduardo says, it's not very polite.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: msgBox to front

    I understand your answers. The program chooses a printer (to pdf) and then shows the file, then the question is whether the user wants to email the file, but the question is then invisible.

    I don't now how to use the vbSystemModal flag; I am a hobby programmer and still VB6
    Last edited by Kars Lensen; Feb 9th, 2018 at 05:22 PM.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: msgBox to front

    The vbSystemModal is just added to (or OR'd) with your other MsgBox flags, like vbYesNo, vbInformation, vbOkCancel, etc.

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
        MsgBox "This is a message", vbInformation + vbOKOnly + vbSystemModal
    End Sub
    
    
    EDIT1: Just to be complete, here's the MSDN on it.
    Last edited by Elroy; Feb 9th, 2018 at 05:27 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: msgBox to front

    Quote Originally Posted by Kars Lensen View Post
    I understand your answers. The program chooses a printer (to pdf) and then shows the file, then the question is whether the user wants to email the file, but the question is then invisible.

    I don't now how to use the vbSystemModal flag; I am a hobby programmer and still VB6
    Code:
        If MsgBox("Do you want to email the file?", vbYesNo Or vbSystemModal) = vbYes Then
            ' email the file
        End If
    I'm surprised, in XP that works (steals the focus).

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: msgBox to front

    I'm on Win10-64 and it works here too.

    EDIT1: I've never done it but I feel certain I could do this to any form with the correct SendMessage call.
    EDIT2: I suppose it's actually not that different from using the HWND_TOPMOST flag with SetWindowPos.
    Last edited by Elroy; Feb 9th, 2018 at 05:38 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: msgBox to front

    Thanks to all, I'l give it try (tomorrow) !

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: msgBox to front

    Quote Originally Posted by Elroy View Post
    I'm on Win10-64 and it works here too.

    EDIT1: I've never done it but I feel certain I could do this to any form with the correct SendMessage call.
    What I remember is that SetForeGroundWindow doesn't work anymore as in old times it used to do.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: msgBox to front

    Eduard, it works fantastic, thanks a lot!

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: msgBox to front

    @Eduardo:
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: msgBox to front

    Quote Originally Posted by Elroy View Post
    @Eduardo:
    Stealing the focus... and I stealing the credits

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