专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > GIS

RegisterClass跟RegisterClassEx有什么区别

发布时间:2010-06-06 17:02:10 文章来源:www.iduyao.cn 采编人员:星星草
RegisterClass和RegisterClassEx有什么区别?

引言


继上篇文章“VC CreateWindow 找不到窗口类”中将RegisterClassEx改为RegisterClass问题就解决了,究竟是什么原因,RegisterClass和RegisterClassEx有什么区别呢?
经过一番查找和测试,终于找到了答案:

不同之处:


The RegisterClass function has been superseded by the RegisterClassEx function. You can still use RegisterClass, however, if you do not need to set the class small icon. In addition,their parameters are different.
E文看不太懂,经过测试就是一个参数的区别,如果使用RegisterClassEx 则WNDCLASSEX的hIconSm参数是必须设置的。

相关代码片:


//函数:MyRegisterClass
//作用:注册窗口类
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wndclass;
    wndclass.cbSize = sizeof(wndclass);
    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = szAppName;
    //将下面这条语句注释,“CreateWindow”时就会出现“找不到窗口类”的错误;
    wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    return RegisterClassEx(&wndclass);
}
//函数:InitInstance
//作用:初始化应用程序
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hwnd = NULL;
    hwnd = CreateWindow(szAppName, _T("按钮设计"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, NULL, hInstance, NULL);
    if (hwnd == NULL)
    {
        TCHAR szBuf[128];
        LPVOID lpMsgBuf;
        DWORD dw = GetLastError();
        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
            NULL,
            dw,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR) &lpMsgBuf,
            0, NULL );
        MessageBox(NULL, (LPTSTR)lpMsgBuf, "hwnd", MB_OK);
    }
    BOOL ret = ShowWindow(hwnd, SW_SHOWNORMAL);
    UpdateWindow(hwnd);
    return TRUE;
}

这里写图片描述

1楼qq_242782052小时前
感谢你的帮助。
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: