hi all, i was hoping that someone could explain findwindow to me and possibly give me an example on how to use it to bring a window "to front"? thanks
Printable View
hi all, i was hoping that someone could explain findwindow to me and possibly give me an example on how to use it to bring a window "to front"? thanks
top of your code window ...
to use FindWindow ...VB Code:
[COLOR=Blue]using[/COLOR] System.Runtime.InteropServices;
VB Code:
[[COLOR=Green]DllImport[/COLOR]([COLOR=Purple]"user32.dll"[/COLOR], EntryPoint = "FindWindowA")] [COLOR=Blue]private static extern[/COLOR] [COLOR=Green]IntPtr[/COLOR] FindWindow([COLOR=Blue]string[/COLOR] lpClassName, [COLOR=Blue]string[/COLOR] lpWindowName); [[COLOR=Green]DllImport[/COLOR]([COLOR=Purple]"user32.dll"[/COLOR])] [COLOR=Blue]private static extern int[/COLOR] BringWindowToTop([COLOR=Green]IntPtr[/COLOR] hwnd); [COLOR=Blue]private void[/COLOR] button1_Click([COLOR=Blue]object[/COLOR] sender, EventArgs e) { [COLOR=Green]/// in this case an open instance of Notepad in the background[/COLOR] [COLOR=Green]IntPtr[/COLOR] hwnd = FindWindow([COLOR=Purple]"Notepad"[/COLOR], [COLOR=Blue]null[/COLOR]); [COLOR=Green]/// if you have retreived a valid handle ...[/COLOR] [COLOR=Blue]if[/COLOR](!hwnd.Equals([COLOR=Green]IntPtr[/COLOR].Zero)) { BringWindowToTop(hwnd); } }
I can't get this to work with any other program but Notepad, can somebody help?
You're probably using the wrong class name. See gigemboy's signature for a tool (WinID) that will allow you to determine the class name of an open window or else use Spy++.
that was it, thanks a ton!