I'm still an extreme noob when it comes to C++. And one of the things (as of now) I currently hate, is the 1,000,000,000 different types of variables in winAPI. This small program I made to check if a window exists was made really quickly. But what's the hardest part? Simply comparing "strings" together to see if it's the match. The simplest part is the hardest!
Anyways, to my question: How can I compare a to toFind, to see if they match?
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam){
TCHAR a[260];
string toFind = "Google Chrome";
hwnd = GetParent(hwnd);
GetWindowText(hwnd, a, sizeof(a));
if(strcmp(a,toFind) == 0){ //doesn't work
cout << "found the window";
}
return TRUE;
}
The easiest way is probably not to use c-style arrays to begin with and since you are compiling with UNICODE
to use std::wstring
:
std::wstring a;
a.resize(260);
std::wstring toFind = L"Google Chrome";
hwnd = GetParent(hwnd);
int size = GetWindowText(hwnd, &a[0], a.size());
a.resize(size);
Then it is simple as:
if(a == toFind)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With