-
Nov 6th, 2019, 06:54 PM
#1
Thread Starter
Frenzied Member
Keep On Top when Shelled
I'm shelling to a VB6 program from Excel. If (when) Excel is clicked on the VB6 Form
goes into the task bar. Is there anyway I can avoid that and keep the VB6 Form on top
of Excel regardless, until it's closed?
-
Nov 6th, 2019, 07:15 PM
#2
Re: Keep On Top when Shelled
-
Nov 7th, 2019, 11:59 AM
#3
Re: Keep On Top when Shelled
Code:
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private 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
Call SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
You can run this on a timer to restore any window to the forefront. See the link below for an implementation.
http://www.vbforums.com/showthread.p...on-quot-0-quot
J.A. Coutts
-
Nov 7th, 2019, 12:04 PM
#4
Re: Keep On Top when Shelled
Setting the VB6 Form always on top isn't really the most ideal solution (the Form will remain on top of every other non-topmost window even when Excel is behind other windows or is minimized). What you should do is make the VB6 Form owned by the Excel window. This example shows how you might achieve that (if you don't want the VB6 Form to be modal to the Excel window, simply omit the EnableWindow calls).
-
Nov 7th, 2019, 12:18 PM
#5
Re: Keep On Top when Shelled
Originally Posted by Victor Bravo VI
Setting the VB6 Form always on top isn't really the most ideal solution (the Form will remain on top of every other non-topmost window even when Excel is behind other windows or is minimized). What you should do is make the VB6 Form owned by the Excel window. This example shows how you might achieve that (if you don't want the VB6 Form to be modal to the Excel window, simply omit the EnableWindow calls).
The hWnd of the C# form is hardcoded??
-
Nov 7th, 2019, 01:33 PM
#6
Re: Keep On Top when Shelled
Originally Posted by Eduardo-
The hWnd of the C# form is hardcoded??
Well, it was just a simple example. Obviously, for those who are aware that hWnds are dynamically assigned (the &H12345678 value is a hint that it's just a dummy hWnd), they will need to supply the code that retrieves that other window's hWnd. For those who aren't (and I'm sure you're not one of them), welcome to Windows programming! (where handles like hWnd aren't set in stone)
-
Nov 7th, 2019, 03:50 PM
#7
Re: Keep On Top when Shelled
Originally Posted by Victor Bravo VI
Well, it was just a simple example. Obviously, for those who are aware that hWnds are dynamically assigned (the &H12345678 value is a hint that it's just a dummy hWnd), they will need to supply the code that retrieves that other window's hWnd. For those who aren't (and I'm sure you're not one of them), welcome to Windows programming! (where handles like hWnd aren't set in stone)
Yes, I know.
For the OP: here there is code to get the hWnd of the main window of the shelled program.
That's one, the other one is the hWnd of Excel, perhaps Application.hWnd.
Those are ment to be used along with the code linked by Victor.
-
Nov 7th, 2019, 04:04 PM
#8
Fanatic Member
Re: Keep On Top when Shelled
I would shell the application with command line option supplying Excel hWnd, it's less code, and it accounts for the possibility that there might be multiple Excel instances running.
Shell "C:\VB6App.exe 12345678"
The VB6 app would use the Command() function to retrieve it. Example:
Debug.Print Command()
-
Nov 7th, 2019, 04:06 PM
#9
Re: Keep On Top when Shelled
One question for the OP: are you going to program in Excel VBA or in the VB6 shelled program?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|