• 8352阅读
  • 5回复

用QT写的程序的类名都是QWidget,能不能修改,最好是运行时动态修改 [复制链接]

上一主题 下一主题
离线hcaihao
 

只看楼主 倒序阅读 楼主  发表于: 2010-09-10
— 本帖被 XChinux 执行加亮操作(2010-09-10) —
用SPY++看到的结果

离线beaujolais
只看该作者 1楼 发表于: 2010-09-10
从QWidget继承来的类也是如此么?

这个参数是不是Win API FindWindow(  LPCTSTR lpClassName,   LPCTSTR lpWindowName);的第一个参数呢??

这个不是很清楚了~~
离线hcaihao

只看该作者 2楼 发表于: 2010-09-10
继承不继承我没测试过,是FindWindow的第一个参数,MFC的我知道怎么改,QT不清楚啊
离线hcaihao

只看该作者 3楼 发表于: 2010-09-10
刚才测试了一下继承的窗口,也是QWidget
离线dbzhang800

只看该作者 4楼 发表于: 2010-09-11
个人对 win32 编程不了解,也不清楚怎么样动态改变类名。至于为什么你看到的类名都是QWidget,大致知道一点

代码来源 qapplication_win.cpp

const QString qt_reg_winclass(QWidget *w)        // register window class
{
    int flags = w->windowFlags();
    int type = flags & Qt::WindowType_Mask;
    uint style;
    bool icon;
    QString cname;
    if (qt_widget_private(w)->isGLWidget) {
        cname = QLatin1String("QGLWidget");
        style = CS_DBLCLKS;
#ifndef Q_WS_WINCE
        style |= CS_OWNDC;
#endif
        icon  = true;
    } else if (flags & Qt::MSWindowsOwnDC) {
        cname = QLatin1String("QWidgetOwnDC");
        style = CS_DBLCLKS;
#ifndef Q_WS_WINCE
        style |= CS_OWNDC;
#endif
        icon  = true;
    } else if (type == Qt::Tool || type == Qt::ToolTip){
        style = CS_DBLCLKS;
        if (w->inherits("QTipLabel") || w->inherits("QAlphaWidget")) {
            if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
                && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) {
                style |= CS_DROPSHADOW;
            }
            cname = QLatin1String("QToolTip");
        } else {
            cname = QLatin1String("QTool");
        }
#ifndef Q_WS_WINCE
        style |= CS_SAVEBITS;
#endif
        icon = false;
    } else if (type == Qt::Popup) {
        cname = QLatin1String("QPopup");
        style = CS_DBLCLKS;
#ifndef Q_WS_WINCE
        style |= CS_SAVEBITS;
#endif
        if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
            && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
            style |= CS_DROPSHADOW;
        icon = false;
    } else {
        cname = QLatin1String("QWidget");
        style = CS_DBLCLKS;
        icon  = true;
    }
#ifndef Q_WS_WINCE
    // force CS_OWNDC when the GL graphics system is
    // used as the default renderer
    if (qt_win_owndc_required)
        style |= CS_OWNDC;
#endif
#ifdef Q_OS_WINCE
    // We need to register the classes with the
    // unique ID on WinCE to make sure we can
    // move the windows to the front when starting
    // a second instance.
    wchar_t uniqueAppID[MAX_PATH];
    GetModuleFileName(0, uniqueAppID, MAX_PATH);
    cname = QString::number(RegisterWindowMessage(
              (const wchar_t *) QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1Char('\\'),
              QLatin1Char('_')).utf16()));
#endif
    // since multiple Qt versions can be used in one process
    // each one has to have window class names with a unique name
    // The first instance gets the unmodified name; if the class
    // has already been registered by another instance of Qt then
    // add an instance-specific ID, the address of the window proc.
    static int classExists = -1;
    if (classExists == -1) {
        WNDCLASS wcinfo;
        classExists = GetClassInfo((HINSTANCE)qWinAppInst(), (wchar_t*)cname.utf16(), &wcinfo);
        classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
    }
    if (classExists)
        cname += QString::number((quintptr)QtWndProc);
    if (winclassNames()->contains(cname))        // already registered in our list
        return cname;
    WNDCLASS wc;
    wc.style        = style;
    wc.lpfnWndProc  = (WNDPROC)QtWndProc;
    wc.cbClsExtra   = 0;
    wc.cbWndExtra   = 0;
    wc.hInstance    = qWinAppInst();
    if (icon) {
        wc.hIcon = (HICON)LoadImage(qWinAppInst(), L"IDI_ICON1", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
#ifndef Q_WS_WINCE
        if (!wc.hIcon)
            wc.hIcon = (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
#endif
    } else {
        wc.hIcon    = 0;
    }
    wc.hCursor      = 0;
#ifndef Q_WS_WINCE
    wc.hbrBackground = qt_widget_private(w)->isGLWidget ? 0 : (HBRUSH)GetSysColorBrush(COLOR_WINDOW);
#else
    wc.hbrBackground = 0;
#endif
    wc.lpszMenuName  = 0;
    wc.lpszClassName = (wchar_t*)cname.utf16();
    ATOM atom = RegisterClass(&wc);
#ifndef QT_NO_DEBUG
    if (!atom)
        qErrnoWarning("QApplication::regClass: Registering window class failed.");
#else
    Q_UNUSED(atom);
#endif
    winclassNames()->insert(cname, 1);
    return cname;
}
离线hcaihao

只看该作者 5楼 发表于: 2010-09-11
一开始我想获取到qt_reg_winclass函数的地址,不过没成功

(DWORD)qt_reg_winclass

提示函数没有链接库

谁知到如何获取?
快速回复
限100 字节
 
上一个 下一个