• 使用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,具体案例可以参考:使用更安全的方法去子类化控件

  • 相关阅读:
    ASP.NET学习笔记(1)
    vs2005新建项目中没有ASP.NET WEB应用程序
    IE无法安装Activex控件
    【Android】SDK工具学习
    【英语】Bingo口语笔记(22)
    【Python】实践笔记
    【学习】纪录片笔记
    【英语】Bingo口语笔记(20)
    【英文】20141027 生词
    【英文】Bingo口语笔记(18)
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12035260.html
Copyright © 2020-2023  润新知