Make a program open to the front of the screen.....

Smoblikat

Diamond Member
Nov 19, 2011
5,184
107
106
Hey guys, im writing a program in VB and I have a button that opens a program, but when the program launches its behind everything else. Can someone tell me what code to use to get the program to open to the front of the screen? I tried adding .bringtofront after the file path, but no dice.

Thanks!
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
This should help

Code:
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long 
 
Public Sub Jay() 
    Set jayobj= GetObject(, "Demo.Application") 'get the currently open program
    SetForegroundWindow jayobj.hWndAccessApp 'set it to be the active window
End Sub
 

Smoblikat

Diamond Member
Nov 19, 2011
5,184
107
106
This should help

Code:
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long 
 
Public Sub Jay() 
    Set jayobj= GetObject(, "Demo.Application") 'get the currently open program
    SetForegroundWindow jayobj.hWndAccessApp 'set it to be the active window
End Sub

Perfect, thats what I was looking for. Thank you!
 

Graze

Senior member
Nov 27, 2012
468
1
0
This thread could have been a post in your original thread about your program OP!




backseat mod here
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
This thread could have been a post in your original thread about your program OP!




backseat mod here

Hey, we don't get _that_ many threads here. Sometimes I actually split them in two just to make more.

/jk mode off
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
What happened (behind the scenes) is that the program that had the button was considered the focus/front window because you had utilized a control on it. The program that you launched fell into the Z order behind your program.

by running the subroutine/method/what ever; you are telling the OS to make that defined application now the current/foreground