简体   繁体   中英

Create Child window on windows API

I'm trying to add a child window to my main window, but the function CreatWindow is throwing an exception saying that can't access address at 0x00000, but it works fine when I try to create a button, I tracked the variables and none of them are null, here it is:

WNDCLASSEX windowClass;

windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.hInstance = hInstance;
windowClass.lpfnWndProc = NULL;
windowClass.lpszClassName = className;
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.lpszMenuName = NULL;

if (!RegisterClassEx(&windowClass)){
    return;
}

window = CreateWindowEx(0,
    className,
    (LPCTSTR)NULL,
    WS_CHILD | WS_BORDER,
    0, 0, 0, 0,
    owner,
    (HMENU)ID,
    hInstance,
    NULL);

the code above giving the error, the important variables come from here:

    gl = new OpenGLContainer("hellogl", hInstance);
addChild(gl);

the first parameter is the className, the constructor only performs an attribution, the addChild method call gl->setOwner(window_handler) and gl->create() which is the first piece of code I posted.

I also saw the stack list, and the problem is after the program enter in the CreateWindow function, which is very strange because the debugger shows that none of the values(pointers) are null.

会不会因为lpfnWndProc为 NULL 而失败?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM