Click to See Complete Forum and Search --> : c++ Winapi - Find Window


zaryk
June 4th, 2009, 11:59 PM
I'm trying to find a window of a program I installed, a dialog window. I've used EnumChildWindows on the main program, and it only enumerates the direct child windows, not the dialog. Right now I have:


im = FindWindow(NULL, "Palringo");
if(im != NULL)
{
ShowWindow(im, 1);
BringWindowToTop(im);
HWND imChatBox = FindWindowEx(im, NULL, MAKEINTATOM(2), NULL);
if(imChatBox != NULL)
{
BringWindowToTop(imChatBox);
}
}


and Here is the information displayed by Winspector:


ClassName: SB_CHATWINDOW
Styles:
WS_OVERLAPPED
WS_VISIBLE
WS_CLIPSIBLINGS
WS_BORDER
WS_SYSMENU
WS_THICKFRAME
WS_MINIMIZEBOX
WS_MAXIMIZEBOX
0x04194304

StylesEx:
WS_EX_WINDOWEDGE
WS_EX_LEFT
WS_EX_LTRREADING
WS_EX_RIGHTSCROLLBAR

Properties: Atom: #43287 0x00000002 (2)

Class Specific: Window is Ansi


Also, it also displays ID and WindowText, but those aren't always the same. And location of Palringo.

Any ideas?

davidpmp
June 5th, 2009, 02:18 PM
if the child window is Disabled or is a label WindowFromPoint does not work and Enum windows works under xp and above.you can change GetWindow Second parameter to resolve your needs.

below code work perfectly on VERSION >= 98.it's my library and I use for personal usage ONLY.ASK FROM DOCTOR GOOGLE TOO.

HWND HWNDHelper::GetWindowFromPoint( POINT& point )
{
HWND hwndWindow = ::WindowFromPoint(point);

HWND hwndChild = GetChildControlFromPoint(hwndWindow, point);

if (hwndChild) return hwndChild;

return hwndWindow;
}

HWND HWNDHelper::GetChildControlFromPoint( HWND hwnd, POINT& point )
{
HWND hwndChild = ::GetWindow( hwnd, GW_CHILD | GW_HWNDFIRST );
hwndChild = ::GetWindow( hwndChild, GW_HWNDNEXT );

while( hwndChild )
{
RECT rectWindow;
::GetWindowRect(hwndChild, &rectWindow);

if (::PtInRect(&rectWindow, point) && IsWindow(hwndChild))
{
return hwndChild;
}
hwndChild = ::GetWindow( hwndChild, GW_HWNDNEXT );
}
return NULL;
}

Best Regards,

davidpmp
June 6th, 2009, 09:00 AM
please tell me about code and your problem to help much more

zaryk
June 6th, 2009, 09:29 AM
I used EnumWindows, and then compared it to the classname. Thanks.


BOOL CALLBACK EnumFunc(HWND child, LPARAM lParam)
{
char buffer[2000];
GetClassName(child, buffer, sizeof(buffer));
if(_tcsicmp(buffer,"SB_CHATWINDOW")==0)
{
GetWindowText(child, buffer, sizeof(buffer));
printf("Window Name: %s \r\n", buffer);
}
}