Important: Please read the Qt Code of Conduct -

Cant use my program when "special chars" are in name.

  • Hello, I can not use my program in for example Game, when it have special chars in Window Name.

    The diffrence between own typed windowName and copied windowName is "e2 80 8b" in "utf8 to hex" between chars. This name looks normal when it's in "name bar" (top bar where window name is) but in some apps (including my app) it shown as "?".

    How can I beat it?
    How can I recognise what charset is it?

    Code is here:

    For addition You can give me some opinions / "tips&tricks" about my code lol.

  • Lifetime Qt Champion

    Hi @BD9a,

    then please mark this topic as SOLVED. Thanks.

  • Lifetime Qt Champion

    What exactly are you trying to achieve / what are you doing?

  • I just trying to fix my macro/clicker. It dont work with games where windowname have special chars.

  • Lifetime Qt Champion

    You still not explain what you're doing...

  • 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("") != 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 called

    But when I changed this function to static, I have to change g_hwnd to 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.

  • Lifetime Qt Champion

    I don't see anything in there which has something to do with Qt...

  • Lifetime Qt Champion



    That is the ASCII version, which fails on Unicode chars. Try GetWindowTextW for the wide character version...


  • When I just change GetWindowTextA to GetWindowTextW I 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 argument

    When 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 your title definition/type? You can't just coerce to LPWSTR, it needs to be wchar_t in the first place....

    Going back to your original code, now that you're going to call GetWindowTextW you can't stick with:

    char* buffer = new char[length + 1];


  • Lifetime Qt Champion

    @JonB is fully right. The good thing is, that Windows wchar_t converts perfectly to QChar and from there to QString.


  • But how to convert wchar_t* to QChar and next to QString?
    I can only convert normal wchar_t

  • Oh thanks, it working now.

  • Lifetime Qt Champion

    Hi @BD9a,

    then please mark this topic as SOLVED. Thanks.

Log in to reply