PC Review


Reply
Thread Tools Rate Thread

activate a window using a window handler in .NET

 
 
Michael Wu
Guest
Posts: n/a
 
      10th Dec 2003
I wonder if anyone know how to activate a window with a given window
handler. I used to do this with the win32 API

static native boolean SetForegroundWindow(int hwnd);

I wonder if there is native support for that within .NET, instead having to
call WIN32 API.

Regards

Michael


 
Reply With Quote
 
 
 
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      10th Dec 2003
Michael,

You can try the Form.Activate() method, but I am not sure this is the exact
equivalent to the SetForegroundWindow() API.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Michael Wu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I wonder if anyone know how to activate a window with a given window
> handler. I used to do this with the win32 API
>
> static native boolean SetForegroundWindow(int hwnd);
>
> I wonder if there is native support for that within .NET, instead having

to
> call WIN32 API.
>
> Regards
>
> Michael
>
>


 
Reply With Quote
 
smith
Guest
Posts: n/a
 
      10th Dec 2003
Still Win32.

Are you looking to just bring a window up?
Does ShowWindowAsync work for what you are doing? This will bring it to
the top of the z-order and restore it if minimized.


Public Const SW_RESTORE = 9
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1

Declare Function ShowWindowAsync Lib "user32" (ByVal hwnd As Integer, ByVal
nCmdShow As Integer) As Integer

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal
hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx
As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

ShowWindowAsync(temphwnd, SW_RESTORE)
'bring it to the top of the z-order
SetWindowPos(temphwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
'unlock it where it is
SetWindowPos(temphwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)


 
Reply With Quote
 
Michael Wu
Guest
Posts: n/a
 
      11th Dec 2003
//Win32APIs.ShowWindowAsync(whdl.ToInt32(), Win32APIs.SC_RESTORE);

doen'st work, but the following 2 lines did work. Any idea why?

Win32APIs.SetForegroundWindow(whdl.ToInt32());

Win32APIs.SendNotifyMessage(whdl.ToInt32(), Win32APIs.WM_SYSCOMMAND,
Win32APIs.SC_RESTORE, 0);



"smith" <(E-Mail Removed)> wrote in message
news:yvJBb.9093$(E-Mail Removed)...
> Still Win32.
>
> Are you looking to just bring a window up?
> Does ShowWindowAsync work for what you are doing? This will bring it to
> the top of the z-order and restore it if minimized.
>
>
> Public Const SW_RESTORE = 9
> Public Const HWND_TOP = 0
> Public Const HWND_TOPMOST = -1
> Public Const HWND_NOTOPMOST = -2
> Public Const SWP_NOMOVE = &H2
> Public Const SWP_NOSIZE = &H1
>
> Declare Function ShowWindowAsync Lib "user32" (ByVal hwnd As Integer,

ByVal
> nCmdShow As Integer) As Integer
>
> Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal
> hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal

cx
> As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
>
> ShowWindowAsync(temphwnd, SW_RESTORE)
> 'bring it to the top of the z-order
> SetWindowPos(temphwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
> 'unlock it where it is
> SetWindowPos(temphwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or

SWP_NOSIZE)
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Window Handler issue Sriman Microsoft VB .NET 1 7th Dec 2007 12:06 PM
Workbook.Activate / Window.Activate problem Tim Microsoft Excel Programming 3 3rd Feb 2006 11:38 PM
Solution: Raising an Event Handler Postback on Parent Window From Popup Child Window Dialog Box Earl Teigrob Microsoft ASP .NET 1 16th Jun 2004 05:19 PM
activate a window using a window handler in .NET Michael Wu Microsoft Dot NET Framework 4 14th Dec 2003 02:19 PM
event-handler for changes in active window(C#) John Microsoft C# .NET 0 14th Aug 2003 02:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:40 PM.