473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

activate a window using a window handler in .NET

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
Jul 21 '05 #1
3 5059
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" <do**************************@my.com> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
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


Jul 21 '05 #2
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)
Jul 21 '05 #3
//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" <rc********@smithvoiceTAKEOUT.com> wrote in message
news:yv*****************@newsread2.news.pas.earthl ink.net...
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)

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Milon | last post by:
Hi all, I am new to Python, and I just wrote a simple script to launch an application from the windows's start menu's run command. (see code as follow) There is an "OK" button on the new...
3
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
5
by: SJ | last post by:
Is it possible to pop-up a window from the code-behind aspx.cs file on an OnClick event? If so, how? I've tried something like the following, but it doesnt seem to work. private void...
3
by: Michael Wu | last post by:
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...
2
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor...
3
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have window.status="Moomin"; why doesn't the statusbar change?...
1
by: pearturtle123 | last post by:
Hi, I am new to Python and I am using PAMIE to manipulate IE browser. Currently, I have IE window 1 launched, after I clicked on a link on window 1, a second IE window 2 isopened. Then, I want...
6
by: =?ISO-8859-1?Q?Une_B=E9vue?= | last post by:
i'd like to intercept the window.onload event in order to distribute it, as needed, to several methods. example : suppose i have several methods doing unlinked initialisations: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.