|
-
Jul 21st, 2001, 11:26 PM
#1
Thread Starter
PowerPoster
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.
-
Jul 22nd, 2001, 12:38 AM
#2
Junior Member
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...
-
Jul 22nd, 2001, 01:32 AM
#3
Thread Starter
PowerPoster
Thanks!
I will try to play around with ie
-
Jul 22nd, 2001, 09:07 PM
#4
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|