Results 1 to 5 of 5

Thread: [resolved] [2.0] findwindow explanation

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    307

    [resolved] [2.0] findwindow explanation

    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
    Last edited by cdubb07; May 11th, 2006 at 01:11 AM.
    "Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2.0] findwindow explanation

    top of your code window ...
    VB Code:
    1. [COLOR=Blue]using[/COLOR] System.Runtime.InteropServices;
    to use FindWindow ...
    VB Code:
    1. [[COLOR=Green]DllImport[/COLOR]([COLOR=Purple]"user32.dll"[/COLOR], EntryPoint = "FindWindowA")]
    2.         [COLOR=Blue]private static extern[/COLOR] [COLOR=Green]IntPtr[/COLOR] FindWindow([COLOR=Blue]string[/COLOR] lpClassName, [COLOR=Blue]string[/COLOR] lpWindowName);
    3.         [[COLOR=Green]DllImport[/COLOR]([COLOR=Purple]"user32.dll"[/COLOR])]
    4.         [COLOR=Blue]private static extern int[/COLOR] BringWindowToTop([COLOR=Green]IntPtr[/COLOR] hwnd);
    5.  
    6.         [COLOR=Blue]private void[/COLOR] button1_Click([COLOR=Blue]object[/COLOR] sender, EventArgs e)
    7.         {
    8.             [COLOR=Green]/// in this case an open instance of Notepad in the background[/COLOR]
    9.             [COLOR=Green]IntPtr[/COLOR] hwnd = FindWindow([COLOR=Purple]"Notepad"[/COLOR], [COLOR=Blue]null[/COLOR]);
    10.             [COLOR=Green]/// if you have retreived a valid handle ...[/COLOR]
    11.             [COLOR=Blue]if[/COLOR](!hwnd.Equals([COLOR=Green]IntPtr[/COLOR].Zero))
    12.             {
    13.                 BringWindowToTop(hwnd);
    14.             }
    15.         }
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    307

    Re: [2.0] findwindow explanation

    I can't get this to work with any other program but Notepad, can somebody help?
    "Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,461

    Re: [2.0] findwindow explanation

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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    307

    Re: [2.0] findwindow explanation

    that was it, thanks a ton!
    "Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width