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. Win32 GetClassName and Qt
QtWS25 Last Chance

Win32 GetClassName and Qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.9k 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.
  • N Offline
    N Offline
    nimaweb
    wrote on 12 Apr 2012, 13:14 last edited by
    #1

    Hi folks,
    I'm developing a program to use plugins which support MultiDec API. The communications made by these Plugins are done through window messaging system using the HWND of the host program. There are many applications implementing this MultiDec API but as they're not all fully compatible with each other, the plugins usually attempt to detect the program that are loading them. The code snippet below shows how this is usually done:

    @static BOOL CALLBACK DetermineDVBApp(HWND hwnd, LPARAM arg)
    {
    char str[256], str2[256];
    GetClassName(hwnd, str, sizeof(str));
    GetWindowText(hwnd, str2, sizeof(str2));
    if(strcmp(str, "Tfmain")==0 && strncmp(str2, "DVB Dream", 9)==0) {
    m_DLLInstance.SetDVBApp(m_DLLInstance.DVBAPP_DVBDREAM, hwnd);
    return FALSE;
    } else if(strcmp(str, "MoDVBOSD")==0 && strncmp(str2, "OSD", 3)==0) {
    m_DLLInstance.SetDVBApp(m_DLLInstance.DVBAPP_MODVB, hwnd);
    return FALSE;
    } else if(strcmp(str, "TSReaderMain")==0 && strncmp(str2, "TSReader", 8)==0) {
    m_DLLInstance.SetDVBApp(m_DLLInstance.DVBAPP_TSREADER, hwnd);
    return FALSE;
    } else if((strcmp(str, "ProgDvbEngineCommandWindow")==0 || strncmp(str, "Afx", 3)==0 ) && (strcmp(str2, "ProgDvbEngineCommandWindow")==0 || strcmp(str2, "ProgDVB")==0)) {
    m_DLLInstance.SetDVBApp(m_DLLInstance.DVBAPP_PROGDVB, hwnd);
    return FALSE;
    } else if(strcmp(str, "TPUtilWindow")==0 && strncmp(str2, "DVBPlus", 7)==0) {
    m_DLLInstance.SetDVBApp(m_DLLInstance.DVBAPP_DVBPLUS, hwnd);
    return FALSE;
    }
    return TRUE;
    }@

    You can see that the plugin calls "GetClassName()":http://bit.ly/IKIDKZ and "GetWindowText()":http://bit.ly/HEExCz to find out about the class name and the title of the window whose HWND has been sent to the plugin. Now, the window title can be easily changed by setWindowTitle(). But I couldn't find any way to override the value obtained by GetClassName() to mimic the function of one of those supported softwares. The python code below shows that even though I instantiated QDialog, I get "QWidget" by calling the GetClassName().

    @from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    import sys
    import win32gui

    class MyDialog(QDialog):
    def printHWND(self):
    hwnd = int(self.winId())
    print "HWND: ", hwnd
    print "Class Name", win32gui.GetClassName(hwnd)

    app = QApplication(sys.argv)
    dlg = MyDialog()
    QTimer.singleShot(0, dlg.printHWND)
    dlg.show()
    app.exec_()@

    Any help on how I'd be able to change its value is highly appreciated. BTW, QMetaObject.className() returns 'MyDialog'.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 12 Apr 2012, 18:33 last edited by
      #2

      I don't familiar with Win32 api, but if you know how to changed the register class name at run time using win32 api, you can directly do it.

      In Qt, QWidget and nerarly all its sub classes are registered as "QWidget"

      @
      #ifndef Q_WS_WINCE
      ATOM atom = RegisterClassEx(&wc);
      #else
      ATOM atom = RegisterClass(&wc);
      #endif
      @

      BTW, other ClassName registered by Qt are

      • "QGLWidget"
      • "QWidgetOwnDC"
      • "QTipLabel"
      • "QAlphaWidget"
      • "QToolTip"
      • "QTool"
      • "QPopup"
      1 Reply Last reply
      0
      • N Offline
        N Offline
        nimaweb
        wrote on 13 Apr 2012, 15:17 last edited by
        #3

        Thanks, that was helpful. I'm more of a Linux guy myself, so I'm pretty clueless when it comes to programming on Windows. Do you think there is anyway to change the className without changing the Qt code? And if I change the Qt source code to modify the className, my change doesn't break anything, does it?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on 13 Apr 2012, 15:19 last edited by
          #4

          bq. And if I change the Qt source code to modify the className, my change doesn’t break anything, does it?

          I'd venture an educated guess that anytime you change the Qt source code, you run the risk of breaking something.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0

          2/4

          12 Apr 2012, 18:33

          • Login

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