HWND hwnd;
wchar_t* szTitle;
// TODO ::
}HwndTitle;
void FindWindowByTitle(HWND hWnd, wchar_t* szTitle)
{
HwndTitle* strHwndTitle = new HwndTitle;
strHwndTitle -> hwnd = hWnd;
strHwndTitle -> szTitle = new wchar_t[wcslen(szTitle)];
strHwndTitle -> szTitle = szTitle;
EnumWindows(EnumWindowsProc, (LPARAM)strHwndTitle);
// todo
}
INT_PTR CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
int iTitleLen = GetWindowTextLength(hWnd);
wchar_t* szWndTitle = new wchar_t[iTitleLen + 1];
if (iTitleLen > 0)
{
GetWindowText(hWnd, szWndTitle, iTitleLen + 1);
if (wcsstr(szWndTitle, ( ((HwndTitle *)lParam)->szTitle ) )!= NULL)
{
((HwndTitle*)lParam) ->hwnd = hWnd;
((HwndTitle*)lParam)->szTitle = szWndTitle;
return false;
}
}
return TRUE;
}