Restore Windows

A

Arne Garvander

I have a window that is waiting for an event to occur. While waiting the
operator may minimize the window.
When the event occur I would like to restore the window and bring it into
focus. How can I do that programmtically?
 
H

Herfried K. Wagner [MVP]

Arne Garvander said:
I have a window that is waiting for an event to occur. While waiting the
operator may minimize the window.
When the event occur I would like to restore the window and bring it into
focus. How can I do that programmtically?

Take a look at the form's 'WindowState' property. In order to make your
application the active one, you'll have to use p/invoke with
'SetForegroundWindow' + 'AttachThreadInput'.

Note that changing the foreground window programmatically may cause
confusion for the user because the input (keyboard, mouse) will be directed
to another window immediately.
 
A

Arne Garvander

Public Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer,
ByRef lpvParam As Object, ByVal fuWinIni As Integer) As Integer
Public Declare Function SetForegroundWindow Lib "user32" Alias
"SetForegroundWindow" (ByVal hwnd As Integer) As Integer
Public Declare Function ShowWindowAsync Lib "user32" Alias
"ShowWindowAsync" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As
Integer
Public Const WS_SHOWNORMAL As Integer = 1
SystemParametersInfo(8193, 0, 0, 3)
ShowWindowAsync(Me.Handle, WS_SHOWNORMAL)
SetForegroundWindow(Me.Handle)
SystemParametersInfo(8193, 200000, 200000, 3)
 
A

Arne Garvander

Herr Wagner,
Can you supply a code example for ideas, please?
--
Arne Garvander
Certified Geek
Professional Data Dude
 
A

Arne Garvander

Thanks,
but that example does not compile. The code makes a call to
GetForegroundWindow(), which is not defined.
--
Arne Garvander
Certified Geek
Professional Data Dude
 
B

BiGFoot

Hi Herfried, Manish Bhai, Arne

Apologies for re-awakenign a long dormant thread but this is exactly the issue
that i`m trying to solve right now in my code.
The query i had was if theres any alternate way to bring ur window to
foregorund with focus without using the " AttachThreadInput -
SetForegroudnWindow" calls, since that seems risky - for example if the I end
up attaching to a foreground window (can be any window in the system !) and
it happens to be hanging ?

I saw the link which suggests changing SystemParametersInfo value for
SetForegroundLockout, will try it out and update regarding the same.

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top