Cant use my program when "special chars" are in name.
-
Ok then..
User can expand list with currently opened windowNames. User choose windowName where my program have to work (click). Choosen windowName is converted to windowID to create hwnd of this window (hwnd is used in PostMessage function).
Now I have problem, because Window Name in target process had been changed, and have special chars (tbh idk what char).
Now I'm trying to use EnumWindows and get hwnd of this "broken" window. "If windowTitle contains (1some of this broken title && 2some of this broken title).
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam); WINBOOL Conf::EnumWindowsProc(HWND hwnd, LPARAM lParam) { int length = GetWindowTextLength(hwnd); char* buffer = new char[length + 1]; GetWindowTextA(hwnd, buffer, length + 1); std::string windowTitle(buffer); // List visible windows with a non-empty title if (IsWindowVisible(hwnd) && length != 0) { std::cout << hwnd << ": " << windowTitle << std::endl; if(windowTitle.find("Minecraft") != std::string::npos && windowTitle.find("Pack.pl") != std::string::npos){ g_hwnd = hwnd; } } return TRUE; }And if I trying to use
EnumWindows(EnumWindowsProc, NULL);in other function, I got error:reference to non-static member function must be calledBut when I changed this function to static, I have to change
g_hwndto static too, and if it's static idk how to use it here:void Clicking::leftClick(){ PostMessage(config->g_hwnd, WM_LBUTTONDOWN, 0, 0); PostMessage(config->g_hwnd, WM_LBUTTONUP, 0, 0); }It's probably a temp 'fix' and looking for some more universal.
-
I don't see anything in there which has something to do with Qt...
-
Ok then..
User can expand list with currently opened windowNames. User choose windowName where my program have to work (click). Choosen windowName is converted to windowID to create hwnd of this window (hwnd is used in PostMessage function).
Now I have problem, because Window Name in target process had been changed, and have special chars (tbh idk what char).
Now I'm trying to use EnumWindows and get hwnd of this "broken" window. "If windowTitle contains (1some of this broken title && 2some of this broken title).
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam); WINBOOL Conf::EnumWindowsProc(HWND hwnd, LPARAM lParam) { int length = GetWindowTextLength(hwnd); char* buffer = new char[length + 1]; GetWindowTextA(hwnd, buffer, length + 1); std::string windowTitle(buffer); // List visible windows with a non-empty title if (IsWindowVisible(hwnd) && length != 0) { std::cout << hwnd << ": " << windowTitle << std::endl; if(windowTitle.find("Minecraft") != std::string::npos && windowTitle.find("Pack.pl") != std::string::npos){ g_hwnd = hwnd; } } return TRUE; }And if I trying to use
EnumWindows(EnumWindowsProc, NULL);in other function, I got error:reference to non-static member function must be calledBut when I changed this function to static, I have to change
g_hwndto static too, and if it's static idk how to use it here:void Clicking::leftClick(){ PostMessage(config->g_hwnd, WM_LBUTTONDOWN, 0, 0); PostMessage(config->g_hwnd, WM_LBUTTONUP, 0, 0); }It's probably a temp 'fix' and looking for some more universal.
-
GetWindowTextA
That is the ASCII version, which fails on Unicode chars. Try GetWindowTextW for the wide character version...
Regards
When I just change
GetWindowTextAtoGetWindowTextWI got errors:C:\Users\BD9a\Downloads\Minecraft-Clicker-master\Conf\conf.cpp:-1: In member function 'QStringList Conf::bumpNames()': C:\Users\BD9a\Downloads\Minecraft-Clicker-master\Conf\conf.cpp:18: error: cannot convert 'char*' to 'LPWSTR {aka wchar_t*}' for argument '2' to 'int GetWindowTextW(HWND, LPWSTR, int)' GetWindowTextW(hwnd, title, length+1); ^ C:\Users\BD9a\Downloads\Minecraft-Clicker-master\Conf\conf.cpp:18: error: no matching function for call to 'GetWindowTextW' C:\Qt\Tools\mingw730_32\i686-w64-mingw32\include\winuser.h:3491: candidate function not viable: no known conversion from 'char *' to 'LPWSTR' (aka 'wchar_t *') for 2nd argumentWhen I add
GetWindowTextW(hwnd, (LPWSTR)title, length+1);In QML I got only one char per window. -
When I just change
GetWindowTextAtoGetWindowTextWI got errors:C:\Users\BD9a\Downloads\Minecraft-Clicker-master\Conf\conf.cpp:-1: In member function 'QStringList Conf::bumpNames()': C:\Users\BD9a\Downloads\Minecraft-Clicker-master\Conf\conf.cpp:18: error: cannot convert 'char*' to 'LPWSTR {aka wchar_t*}' for argument '2' to 'int GetWindowTextW(HWND, LPWSTR, int)' GetWindowTextW(hwnd, title, length+1); ^ C:\Users\BD9a\Downloads\Minecraft-Clicker-master\Conf\conf.cpp:18: error: no matching function for call to 'GetWindowTextW' C:\Qt\Tools\mingw730_32\i686-w64-mingw32\include\winuser.h:3491: candidate function not viable: no known conversion from 'char *' to 'LPWSTR' (aka 'wchar_t *') for 2nd argumentWhen I add
GetWindowTextW(hwnd, (LPWSTR)title, length+1);In QML I got only one char per window.@BD9a
Looks like you need to sort out yourtitledefinition/type? You can't just coerce toLPWSTR, it needs to bewchar_tin the first place....Going back to your original code, now that you're going to call
GetWindowTextWyou can't stick with:char* buffer = new char[length + 1];:)
-
@BD9a
Looks like you need to sort out yourtitledefinition/type? You can't just coerce toLPWSTR, it needs to bewchar_tin the first place....Going back to your original code, now that you're going to call
GetWindowTextWyou can't stick with:char* buffer = new char[length + 1];:)