?
Solved

Bring window to front on startup

Posted on 2003-03-31
13
Medium Priority
?
511 Views
Last Modified: 2013-12-26
I have an application which does not have a visible form at startup. A timer event launches the form when criteria are met. The very first time the form is launched after application startup, it does not come to the front of other windows; however, if the user clicks the taskbar bringing the window front, does required actions and closes window, every subsequent time the form is launched it is on top. It does not bring it to front the very first time it's called.

I have been able to determine that the user must click an event within the form for each subsequent launch to be forward. If the user just minimizes or closes the window, it will continue to launch in the background.

0
Comment
Question by:lizpell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 3

Expert Comment

by:DeAn
ID: 8239965
in the timer event try setting the forms focus, or a control on the form?

depending on where the timer event is...

YourForm.Visible = True
YourForm.SetFocus
0
 

Author Comment

by:lizpell
ID: 8239996
This is the code in the timer control:

            Form1.Show
            Form1.Visible = True
            Form1.SetFocus

0
 

Expert Comment

by:simon780
ID: 8240028
Form1.Show vbModeless

use show instead of visible property

Good Luck
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:lizpell
ID: 8240505
Nope, that doesn't work either. I read somewhere in a MSDN white paper that the Show method launches the window in the last state it was launched in. Since my problem is only happening the first time it's launched - where's it getting that property from? Is it being saved in the registry or something and then each subsequent time it's launched it's using the last window state which was on top? I'm grasping at straws here, I know...
0
 

Author Comment

by:lizpell
ID: 8240580
Nope, that doesn't work either. I read somewhere in a MSDN white paper that the Show method launches the window in the last state it was launched in. Since my problem is only happening the first time it's launched - where's it getting that property from? Is it being saved in the registry or something and then each subsequent time it's launched it's using the last window state which was on top? I'm grasping at straws here, I know...
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8240649
did you try setting a textbox focus?

Me.Show
Text1.SetFocus

just a thought
0
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8240840
Have you tried

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)

Const HWND_TOPMOST = -1
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_SHOWWINDOW = &H40

SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

0
 

Author Comment

by:lizpell
ID: 8240846
Okay, I've discovered it's because of a registry key
HKCU\Control Panel\Desktop\ForegroundLockTimeout

Value should be 00000000
Problem occurs if value is 00030d40

Is there a way to edit this key from my VB app?
0
 

Accepted Solution

by:
simon780 earned 800 total points
ID: 8241249
0
 
LVL 11

Expert Comment

by:supunr
ID: 8242195
private sub command1_Click()
    me.visible = true
    me.ZOrder ' bring the form to the front
End sub

' good luck!
0
 
LVL 5

Expert Comment

by:avya2k
ID: 8244729
you can write as follows
as the OK button is clicked your form will be hidden or wahtever you want to do(You should remove it's vbModal property by doing this)
and next time through timer show form in non modal state

Private Sub Command1_Click()
    Me.Hide
    Timer1.Enabled = True
End Sub

Private Sub Form_Load()
    Me.Show 1
End Sub

Private Sub Timer1_Timer()
    Me.Show
    Timer1.Enabled = False
End Sub
0
 

Author Comment

by:lizpell
ID: 8247093
It was an error with a registry key, not with the show method as I previously believed.
0
 

Expert Comment

by:simon780
ID: 8247119
To: lizpell

Thank you for the points!!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question