Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cant use my program when "special chars" are in name.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

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

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BD9a
      wrote on last edited by BD9a
      #3

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

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

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

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • B Offline
          B Offline
          BD9a
          wrote on last edited by BD9a
          #5

          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 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.

          aha_1980A 1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

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

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • B BD9a

              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 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.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @BD9a

              GetWindowTextA

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

              Regards

              Qt has to stay free or it will die.

              B 1 Reply Last reply
              3
              • aha_1980A aha_1980

                @BD9a

                GetWindowTextA

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

                Regards

                B Offline
                B Offline
                BD9a
                wrote on last edited by
                #8

                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.

                JonBJ 1 Reply Last reply
                0
                • B BD9a

                  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.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #9

                  @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];
                  

                  :)

                  aha_1980A 1 Reply Last reply
                  4
                  • JonBJ JonB

                    @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];
                    

                    :)

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

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

                    Regards

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    3
                    • B Offline
                      B Offline
                      BD9a
                      wrote on last edited by
                      #11

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

                      JonBJ 1 Reply Last reply
                      0
                      • B BD9a

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

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #12

                        @BD9a
                        What about https://doc.qt.io/qt-5/qstring.html#fromWCharArray ?

                        1 Reply Last reply
                        3
                        • B Offline
                          B Offline
                          BD9a
                          wrote on last edited by
                          #13

                          Oh thanks, it working now.

                          aha_1980A 1 Reply Last reply
                          1
                          • B BD9a

                            Oh thanks, it working now.

                            aha_1980A Offline
                            aha_1980A Offline
                            aha_1980
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            Hi @BD9a,

                            then please mark this topic as SOLVED. Thanks.

                            Qt has to stay free or it will die.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved