FindWindow () does not find my window [C ++]

This is not a difficult question. I'm having trouble finding the iTunes descriptor. But although iTunes is running in the background, it continues to tell me that it cannot find the window. So I kept checking to see if I missed the window name, but spy ++ told me that I was using the correct window name and class name (see below). I am sure this is a small mistake, but I cannot find it. Somebody knows? Thanks in advance.

HWND hwnd; hwnd = FindWindow((LPCWSTR)"iTunes",(LPCWSTR)"iTunes"); if (hwnd != 0){ cout << "WINDOW FOUND" << endl; } else { cout << "WINDOW NOT FOUND" << endl; cout << hwnd << endl; } 
+4
source share
1 answer

You use ANSI strings with what looks like a Unicode version of FindWindow .

Many Win32 functions are actually a pair of functions and a macro. For example, FindWindow is defined like this:

 HWND WINAPI FindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName); HWND WINAPI FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName); #if (UNICODE) # define FindWindow FindWindowW #else # define FindWindow FindWindowA #endif 

Try explicitly calling FindWindowA or using wide strings, for example:

 HWND hwnd = FindWindow(L"iTunes", L"iTunes"); 
+5
source

Source: https://habr.com/ru/post/1415652/


All Articles