|
-
Aug 2nd, 2007, 03:56 PM
#1
Thread Starter
Junior Member
[RESOLVED] Force Window on top
I am using VB 6.0 and I have a project with 1 form. I want to force this form to come to the top when a value gets placed into a text field. I have tried the following code
Public Const SWP_SHOWWINDOW = &H3
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = True
SetWindowPos DDEPHOTO.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
DDEPHOTO.Show
This seems to work the first time but after I have the form up, if I minimize it by clicking the"-" sign in the upper right, I can never get it to come up on top of my other programs again. Any help would be great. Thanks
-
Aug 2nd, 2007, 04:56 PM
#2
Re: Force Window on top
I use this code to set the window to the foreground or to the background by means of a menu. With appropriate changes you can taylor it to your needs.
Code:
Private Sub mnuWindowVisible_Click()
Dim res As Long
If mnuWindowVisible.Checked = 0 Then
res = SetWindowPos(Me.hwnd, HWND_TOPMOST, _
0, 0, 0, 0, FLAGS)
mnuWindowVisible.Checked = 1
Else
res = SetWindowPos(Me.hwnd, HWND_NOTOPMOST, _
0, 0, 0, 0, FLAGS)
mnuWindowVisible.Checked = 0
End If
End Sub
'(In a module):
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
Global Const SWP_NOMOVE = 2
Global Const SWP_NOSIZE = 1
Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Global Const HWND_TOPMOST = -1
Global Const HWND_NOTOPMOST = -2
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Aug 3rd, 2007, 10:01 AM
#3
Thread Starter
Junior Member
Re: Force Window on top
I tries this code and that didn't work either. Does an event happen when the minimize button of a form is clicked.
What I have is a form for taking patient photos. Assume the first patient comes in, we click on a JWALK screen that passes the ACT# to a text box on the main VB form and displays that patients name and it loads the program and we take their picture. I am trying to force the form to show in the txtInput_Change routine. Everything works good, now if they want to continue to work on the screen I want them to just minimize the main window. Then another patient comes in, they go back to the JWALK screen, click the button to call my VB app, pass the new ACT# but the form stays on the bottom of the screen. Thanks
-
Aug 3rd, 2007, 10:11 AM
#4
Re: Force Window on top
 Originally Posted by crm1975
I tries this code and that didn't work either. Does an event happen when the minimize button of a form is clicked.
Thanks
It works for me. The event is Resize.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Aug 3rd, 2007, 10:40 AM
#5
Thread Starter
Junior Member
Re: Force Window on top
Ok, how do you add a menu to the form in VB 6.0. I used a checkbox on the form and was changing the value property in the Resize event.
-
Aug 3rd, 2007, 10:53 AM
#6
Re: Force Window on top
 Originally Posted by crm1975
Ok, how do you add a menu to the form in VB 6.0. I used a checkbox on the form and was changing the value property in the Resize event.
Go to Tools / Menu editor. If you've never used menus you should google around for a tutorial. It's not difficult but it's somewhat cumbersome to explain in a post.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Aug 3rd, 2007, 03:03 PM
#7
Thread Starter
Junior Member
Re: Force Window on top
I wasn't able to get it owrking using your method but thanks for your help. I found a VB program out there that I ws able to use the code from and this is working for me now. Here is the link http://www.thescarms.com/VBasic/ShowWindow.aspx
-
Aug 3rd, 2007, 03:12 PM
#8
Re: Force Window on top
Set up two menu items, mnuTop (sets the form on top) and mnuNot (sets the form not on top). Make mnuNot invisible.
Code:
Private Sub mnuNot_Click()
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
mnuTop.Visible = True
mnuNot.Visible = False
'Use the next two lines if you want to save the state
'from one use of the program to the next use.
'You'll have to read the setting at Form_Load and call SetWindowPos (and
'set the menus appropriately) based on the value you get
'OnTop = False
'SaveSetting App.Title, "Settings", "OnTop", OnTop
End Sub
Private Sub mnuTop_Click()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
mnuNot.Visible = True
mnuTop.Visible = False
'OnTop = True
'SaveSetting App.Title, "Settings", "OnTop", OnTop
End Sub
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Aug 4th, 2007, 06:50 AM
#9
Re: Force Window on top
 Originally Posted by crm1975
I wasn't able to get it owrking using your method but thanks for your help. I found a VB program out there that I ws able to use the code from and this is working for me now. Here is the link http://www.thescarms.com/VBasic/ShowWindow.aspx
This program seems to be similar to Spy++ that you can find among the Visual Studio 6 Tools.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
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
|