Important: Please read the Qt Code of Conduct -

Win32 GetClassName and Qt

  • 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()": and "GetWindowText()": 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)

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

  • 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);
    ATOM atom = RegisterClass(&wc);

    BTW, other ClassName registered by Qt are

    • "QGLWidget"
    • "QWidgetOwnDC"
    • "QTipLabel"
    • "QAlphaWidget"
    • "QToolTip"
    • "QTool"
    • "QPopup"

  • 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?

  • Moderators

    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.

Log in to reply