Results 1 to 4 of 4

Thread: Find a window

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Find a window

    How do get the hwnd of a window like notepad, internet explorer (even if the programs are not running)

    Actually, I want to change the menu of ie. So I need the hwnd of ie even if it is running at that time or not.
    Baaaaaaaaah

  2. #2
    Junior Member
    Join Date
    Jun 2001
    Posts
    22
    To find a window call:
    Code:
    hwnd=FindWindow(class, title);
    the class and/or the title has to match exactly; you can leave one of them NULL if you don't know or if it changes (ie: Notepad title).
    The Notepad class is 'Notepad'; the IE class is 'IEFrame'. You can use Spy++ to find any window's handle or title.

    To find a window with a string within its title, use the following code:
    Code:
    HWND FindWindowLike(const char szClass[], const char szTitle[])
    {
    
    	if( !(szTitle || szClass) )
    		return NULL;
    
    	HWND hwnd;
    	char buffer[255];
    	
    	HWND hParent = GetDesktopWindow();
    
    	hwnd = GetWindow(GetWindow(hParent, GW_CHILD), GW_HWNDFIRST);
    
    	while(hwnd)
    	{
    		if(szClass)
    		{
    			GetClassName(hwnd, buffer, 255);
    			if(strstr(buffer, szClass))
    				return hwnd;
    		}
    		if(szTitle)
    		{
    			SendMessage(hwnd, WM_GETTEXT, 255, (LPARAM) buffer);
    			if(strstr(buffer, szTitle))
    				return hwnd;
    		}
    		hwnd = GetWindow(hwnd, GW_HWNDNEXT);
    	}
    
    	return hwnd;
    }
    Just call FindWindowLike(class, title). Leave either NULL if you don't know it, or don't want to use it as criteria.

    --------
    You can not find the handle of a window that doesn't exist. If you want to modify the IE menu (efficiently), you'll need to write a plugin for IE. I don't have code available right now, but it is fully explained in MSDN, though I forget what the interface is called.

    Hope that helps...

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Thanks!

    I will try to play around with ie
    Baaaaaaaaah

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    If you don't know the class, you still can get the window handle by passing a NULL into the lpClassName and the window name into the lpWindowName like below:

    PHP Code:
        fhWnd FindWindow(NULL"Untitled - Notepad");
        if (
    fhWnd != NULL)
            
    SetForegroundWindow(fhWnd); 

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