Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Restore Windows

3 views
Skip to first unread message

Arne Garvander

unread,
Dec 17, 2007, 5:28:54 PM12/17/07
to
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?
--
Arne Garvander
Certified Geek
Professional Data Dude

Manish Bafna

unread,
Dec 18, 2007, 5:21:01 AM12/18/07
to
Hi,
I have tested solution shown in below link is working perfectly well.Instead
of window.Handle you need to write yourminimizedform.Handle.
http://www.redbugtech.com/forums/viewtopic.php?t=74
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

Arne Garvander

unread,
Dec 18, 2007, 9:46:00 AM12/18/07
to
Thanks.
Now I have to try to translate the code to VB.

--
Arne Garvander
Certified Geek
Professional Data Dude

Arne Garvander

unread,
Dec 18, 2007, 10:01:01 AM12/18/07
to
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)

--
Arne Garvander
Certified Geek
Professional Data Dude

Herfried K. Wagner [MVP]

unread,
Dec 18, 2007, 9:33:56 AM12/18/07
to
"Arne Garvander" <ArneGa...@discussions.microsoft.com> schrieb:

>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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Arne Garvander

unread,
Dec 18, 2007, 10:15:05 AM12/18/07
to
Herr Wagner,
Can you supply a code example for ideas, please?

--
Arne Garvander
Certified Geek
Professional Data Dude

Arne Garvander

unread,
Dec 18, 2007, 10:31:02 AM12/18/07
to
This works great:
WindowState = FormWindowState.Normal

--
Arne Garvander
Certified Geek
Professional Data Dude

Herfried K. Wagner [MVP]

unread,
Dec 18, 2007, 10:23:20 AM12/18/07
to
"Arne Garvander" <ArneGa...@discussions.microsoft.com> schrieb:

> Can you supply a code example for ideas, please?

<URL:http://google.com/groups?selm=%23csLmuBlDHA.3504%40TK2MSFTNGP11.phx.gbl>

Arne Garvander

unread,
Dec 18, 2007, 11:02:01 AM12/18/07
to
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


"Herfried K. Wagner [MVP]" wrote:

BiGFoot

unread,
Nov 10, 2009, 10:14:04 AM11/10/09
to
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.

"Herfried K. Wagner [MVP]" wrote:

0 new messages