Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get a form to get focus

Status
Not open for further replies.

fenris

Programmer
May 20, 1999
824
CA
I have a program that has a splash screen that loads the main form frmMain. In frmMain's load event, it checks to see if there are some settings that it requires in the registry. If it doesn't find these settings then it loads up the settings form, frmSettings. The problem that I am have is that frmMain is ontop of frmSettings. What I want is frmSettings to be on top of frmMain. I have tried:

Load frmSettings
frmSettings.Show

but this doesn't work, I have tried

frmMain.windowstate = vbminimized
Load frmSettings
frmSettings.Show

This leaves frmSettings up but not focused. I even tried

frmMain.windowstate = vbminimized
Load frmSettings
frmSettings.Show
frmSettings.setFocus

But that did not give the form focus.

Any ideas.... I would like to stay away from api calls if possible.

Troy Williams B.Eng.
fenris@hotmail.com

 
I don't think you can stay away from the API for too long. Here's an easy one designed to do exactly what you are trying to do:
[tt]
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

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
[/tt]

Then in the frmSettings Load, Activate and Resize events add:
[tt]
Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
[/tt]

It should produce the desired effect. Let us know if it doesn't.


VCA.gif

Alt255@Vorpalcom.Intranets.com
 
I started a new program with 3 forms and a command button on form 1. Placed this code on form 1. Form2 shows up on top with focus. Don't know why it won't work for you.

Private Sub Command1_Click()
Form2.Show
Form3.Show
Form2.SetFocus
End Sub


David Paulson


 
Thanks for the replies, I appreciate it....

Troy Williams B.Eng.
fenris@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top