Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

Bring window to front on startup

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
lizpell
Asked:
lizpell
  • 5
  • 3
  • 2
  • +3
1 Solution
 
DeAnCommented:
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
 
lizpellAuthor Commented:
This is the code in the timer control:

            Form1.Show
            Form1.Visible = True
            Form1.SetFocus

0
 
simon780Commented:
Form1.Show vbModeless

use show instead of visible property

Good Luck
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lizpellAuthor Commented:
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
 
lizpellAuthor Commented:
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
 
DeAnCommented:
did you try setting a textbox focus?

Me.Show
Text1.SetFocus

just a thought
0
 
JohnMcCannCommented:
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
 
lizpellAuthor Commented:
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
 
simon780Commented:
0
 
supunrCommented:
private sub command1_Click()
    me.visible = true
    me.ZOrder ' bring the form to the front
End sub

' good luck!
0
 
avya2kCommented:
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
 
lizpellAuthor Commented:
It was an error with a registry key, not with the show method as I previously believed.
0
 
simon780Commented:
To: lizpell

Thank you for the points!!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now