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!
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
Re: VB6 App opens up "behind" other apps
You can use SetWindowPos to make your start window to be the topmost:
VB Code:
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)
Private Sub Form_Activate()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
'Set the window position to topmost
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
OR ... simply force thread that creates your app into the foreground (this would probably be better):
VB Code:
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Sub Form_Load()
lHandle = SetForegroundWindow(Me.hWnd)
End Sub
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!
Re: VB6 App opens up "behind" other apps
As I said SetForegroundWindow() may for you best.
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?
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:
Private Sub Form_[B]Activate[/B]()
SetWindowPos Me.hWnd, _
[B]HWND_NOTOPMOST[/B], 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or _
SWP_NOMOVE Or SWP_NOSIZE
End Sub
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!
Re: VB6 App opens up "behind" other apps
As long as it works... You're welcome. :thumb: