Find Window in C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Find Window in C#

  1. #1
    Join Date
    Jan 2003
    Posts
    33

    Find Window in C#

    Is there a way to do a FindWindow(className, windowTitle) in C#?

    Or is there a way that I can enumerate through the open windows so that can extract the window title?

    Thx.
    Last edited by mamo; June 20th, 2003 at 06:09 PM.

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    you can do use Win32 APIs , who is telling you no to that

    FindWindow("myprogram",null); // win32 API

    it will return 32 bit value.

    using interops define following,

    [DllImport("user32.dll",EntryPoint="FindWindow")]
    private static extern int FindWindow(string sClass, string sWindow);

    int nWinHandle = FindWindow("yourwindow",null);

    if(nWinHandle == 0)
    {
    // handle the error message
    }

    hope this helps

    Paresh
    - Software Architect

  3. #3
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    263
    this is exactly correct
    here's another example , using GetClassName also.
    Code:
            [DllImport("User32.Dll")]
    		public static extern int FindWindow (string lpClassName, string lpWindowName);
            
    		[DllImport("User32.Dll")]
    		public static extern int GetClassName (int hwnd, StringBuilder lpClassName, int nMaxCount);
    ///// under windows generated code.
    ////////
    
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    		StringBuilder r=new System.Text.StringBuilder();
    
            int i=FindWindow(null,null);
            int x=GetClassName(i,r,r.Capacity);
    		MessageBox.Show(r.ToString());/// show our found classname.
    		}
    string Signature = Censored;

  4. #4
    Join Date
    Jan 2003
    Posts
    33
    Thanks guys! That worked.

  5. #5
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890

    Thumbs up Find A Window C#

    hey mamo,
    i found a great article for your use,
    even i can make this as a reference in future.


    Find Window
    - Software Architect

  6. #6
    Join Date
    Oct 2017
    Posts
    1

    Re: Find Window in C#

    Could you please provide complete c# sharp script of this solution that worked for you.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,575

    Re: Find Window in C#

    Quote Originally Posted by Tanmaydixit View Post
    Could you please provide complete c# sharp script of this solution that worked for you.
    Please don't reopen old threads - this one is 14 years old plus the code you've ask for is in post #3.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)