zoukankan      html  css  js  c++  java
  • 使用CreateWindowEx创建子窗口的注意事项

    比如: 

    使用 HWND child = CreateWindowEx(0,L"childclass",NULL,WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,100, 100, 500, 500,hWnd,(HMENU)(1),hInst,NULL);创建子窗口时会出现1407的错误提示,然后返回空句柄

    这是因为没有注册子窗口,所以你必须先注册:

     WNDCLASS mywndclass;
    
     mywndclass.style        = CS_HREDRAW | CS_VREDRAW;
     mywndclass.lpfnWndProc = HelloWndProc;
     mywndclass.cbClsExtra   = 0;
     mywndclass.cbWndExtra = sizeof(long);
     mywndclass.hInstance    = hInstance;
     mywndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION);
     mywndclass.hCursor  = LoadCursor (NULL, IDC_ARROW);
     mywndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
     mywndclass.lpszMenuName = NULL;
     mywndclass.lpszClassName = L"childclass";
    
    if (!RegisterClass (&mywndclass))
        {
            MessageBox (NULL, TEXT ("RegisterClass  failed"),
                        NULL, MB_ICONERROR);
            return 0;
        }

    再创建回调函数HelloWndProc, 这样就可以了。

    如果你想使用系统定义的注册类,比如静态控件,按钮之类的,可以这样写:

    HWND child = CreateWindowEx(0,L"static",NULL,WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,100, 100, 500, 500,hWnd,(HMENU)(1),hInst,NULL);

    如果你想自定义控件,就是控件里的内容都是自己设计,那么你可以使用SetWindowSubClass,具体案例可以参考:使用更安全的方法去子类化控件

  • 相关阅读:
    MySQL 元数据
    MySQL 复制表
    MySQL 临时表
    MySQL 索引
    MySQL ALTER
    MySQL 事务
    MySQL 正则表达式
    Mysql Join
    Python(数据库之表操作)
    Python知识点复习之__call__
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12035260.html
Copyright © 2011-2022 走看看