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

RE: Restore Windows by ManishBafna

ManishBafna
Tue Dec 18 04:21:01 CST 2007

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" wrote:

> 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

RE: Restore Windows by ArneGarvander

ArneGarvander
Tue Dec 18 08:46:00 CST 2007

Thanks.
Now I have to try to translate the code to VB.
--
Arne Garvander
Certified Geek
Professional Data Dude


"Manish Bafna" wrote:

> 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" wrote:
>
> > 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

Works great in VB by ArneGarvander

ArneGarvander
Tue Dec 18 09:01:01 CST 2007

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


"Manish Bafna" wrote:

> 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" wrote:
>
> > 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

Re: Restore Windows by Herfried

Herfried
Tue Dec 18 08:33:56 CST 2007

"Arne Garvander" <ArneGarvander@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/>


Re: Restore Windows by ArneGarvander

ArneGarvander
Tue Dec 18 09:15:05 CST 2007

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


"Herfried K. Wagner [MVP]" wrote:

> "Arne Garvander" <ArneGarvander@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/>
>
>

RE: Restore Windows by ArneGarvander

ArneGarvander
Tue Dec 18 09:31:02 CST 2007

This works great:
WindowState = FormWindowState.Normal
--
Arne Garvander
Certified Geek
Professional Data Dude


"Arne Garvander" wrote:

> 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

Re: Restore Windows by Herfried

Herfried
Tue Dec 18 09:23:20 CST 2007

"Arne Garvander" <ArneGarvander@discussions.microsoft.com> schrieb:
> Can you supply a code example for ideas, please?

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

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


Re: Restore Windows by ArneGarvander

ArneGarvander
Tue Dec 18 10:02:01 CST 2007

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:

> "Arne Garvander" <ArneGarvander@discussions.microsoft.com> schrieb:
> > Can you supply a code example for ideas, please?
>
> <URL:http://google.com/groups?selm=%23csLmuBlDHA.3504%40TK2MSFTNGP11.phx.gbl>
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>