Results 1 to 9 of 9

Thread: VB6 App opens up "behind" other apps [SOLVED!]

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Resolved VB6 App opens up "behind" other apps [SOLVED!]

    HI,

    I have a nice VB program that works on a majority of computers, but recently a few users have complained that when the program opens up, it opens up "behind" other applications running on their computer. I have seen it on occasion, but If I shut the computer down and reboot, the problem goes away. The customers complaining say a reboot does not fix the problem.

    I have the window state set to MAXIMIZED, and it does open maximuzed, but behind other applications when this problem occurrs. I have tried the AppActivate command to bring my application to the front, but apparently you cannot activate the program that is running from itself.

    Please help.

    Thanks!
    Last edited by Hack; Aug 25th, 2006 at 12:05 PM. Reason: Added green "resolved" checkmark

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: VB6 App opens up "behind" other apps

    This should do it - I will try this. Sorry to "post prematurely".....


    visual basic code:--------------------------------------------------------------------------------
    'Put following in a module
    Public 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

    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2

    'Following code is to be on a Form...

    'Place this in the Form_load:
    SetWindowPos hwnd, HWND_TOPMOST, _
    0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE


    'Place this in the Form_QueryUnload:
    SetWindowPos hwnd, HWND_NOTOPMOST, _
    0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: VB6 App opens up "behind" other apps

    You can use SetWindowPos to make your start window to be the topmost:
    VB Code:
    1. Const HWND_TOPMOST = -1
    2. Const HWND_NOTOPMOST = -2
    3. Const SWP_NOSIZE = &H1
    4. Const SWP_NOMOVE = &H2
    5. Const SWP_NOACTIVATE = &H10
    6. Const SWP_SHOWWINDOW = &H40
    7.  
    8. Private Declare Sub SetWindowPos Lib "User32" _
    9.     (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
    10.     ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
    11.  
    12. Private Sub Form_Activate()
    13.     'KPD-Team 1998
    14.     'URL: [url]http://www.allapi.net/[/url]
    15.     'E-Mail: [email][email protected][/email]
    16.     'Set the window position to topmost
    17.     SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
    18.     SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    19. End Sub
    OR ... simply force thread that creates your app into the foreground (this would probably be better):
    VB Code:
    1. Private Declare Function SetForegroundWindow Lib "user32" _
    2.     (ByVal hwnd As Long) As Long
    3.  
    4. Private Sub Form_Load()
    5.     lHandle = SetForegroundWindow(Me.hWnd)
    6. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Unhappy Re: VB6 App opens up "behind" other apps

    Thanks, RhinoBull!

    I got it working, but now I have a new problem.....

    The

    SetWindowPos hwnd, HWND_TOPMOST,0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

    command works great!


    HOWEVER,

    My application calls other applications and opens new forms, which are now opening BEHIND my form1, which is the first form where I put the SerWindowPos command.

    Is there a line I can put in that after a button is pressed that it "turns off" the properties of the window being forced to the front?

    Thanks again!

  5. #5

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Unhappy Re: VB6 App opens up "behind" other apps

    Hi,

    I have tried the SetForegroundWindow as RhinoBull suggested, and it had no effect on the computers that will not bring the application to the front.

    Besides minimizing the first form, which is "Stuck" front with the SetWindowPos command, are there any other options? Minimizing would cause other problems for me....

    Help........

    Any idea why this is an intermittent problem?

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: VB6 App opens up "behind" other apps

    I didn't see your post #2...

    Anyway, using SetWindowPos you can do little trick on form activate to make the form not the topmost:
    VB Code:
    1. Private Sub Form_[B]Activate[/B]()
    2.     SetWindowPos Me.hWnd, _
    3.                  [B]HWND_NOTOPMOST[/B], 0, 0, 0, 0, _
    4.                  SWP_NOACTIVATE Or SWP_SHOWWINDOW Or _
    5.                  SWP_NOMOVE Or SWP_NOSIZE
    6. End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Talking Re: VB6 App opens up "behind" other apps

    THANKS FOR ALL YOUR HELP, RhinoBull!

    I got it fixed.. Here's what I did. I used the

    SetWindowPos hwnd, HWND_TOPMOST, _
    0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE


    in my form load and then used the

    SetWindowPos Me.hwnd, _
    HWND_NOTOPMOST, 0, 0, 0, 0, _
    SWP_NOACTIVATE Or SWP_SHOWWINDOW Or _
    SWP_NOMOVE Or SWP_NOSIZE

    in each of the buttons that call other programs for forms.

    I sincerely thank you! YOU ROCK!

  9. #9

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