I'm trying to avoid C++ code and only use C.
The window procedure does not contain any code.
CreateWindow returns NULL
Thema
21
Reputation points
The Windows function CreateWindow fails and returns NULL.
Here is the code:
WNDCLASS *tmpwindow;
HWND windowhandle;
tmpwindow = (WNDCLASS*)calloc(1, sizeof(WNDCLASS));
tmpwindow->style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
tmpwindow->lpfnWndProc = winProc;
tmpwindow->hInstance = hinstance;
tmpwindow->lpszMenuName = NULL;
tmpwindow->hbrBackground = COLOR_WINDOW;
tmpwindow->lpszClassName = "WINCLASS1";
ret = RegisterClassA(tmpwindow);
if(ret == 0){
MessageBox(NULL, "RegisterClass failed", \
"DrawSection results", MB_OK);
}
windowhandle = CreateWindowA("WINCLASS1", \
"DrawSection Test1", \
WS_VISIBLE | WS_OVERLAPPEDWINDOW, \
CW_USEDEFAULT, CW_USEDEFAULT, \
CW_USEDEFAULT, CW_USEDEFAULT, \
NULL, \
NULL, \
hinstance, \
NULL);
if(windowhandle == NULL){
MessageBox(NULL, "CreateWindow failed", \
"DrawSection results", MB_OK);
return 0;
}
2 answers
Sort by: Most helpful
-
Thema 21 Reputation points
2021-04-20T13:22:40.77+00:00 -
Viorel 112.5K Reputation points
2021-04-20T13:33:50.347+00:00 Make sure that the Windows Procedure (winProc) has the correct signature and at least returns the value of DefWindowProc according to documentation and samples.