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.
Printable View
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.
To find a window call:
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).Code:hwnd=FindWindow(class, 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:
Just call FindWindowLike(class, title). Leave either NULL if you don't know it, or don't want to use it as criteria.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;
}
--------
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...
Thanks!
I will try to play around with ie
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);