When I compile my code, a window should be opened but it does not. I have created a class, HWND, and application handlers; still nothing.
I am kinda new, sorry about the question.
The application runs fine without errors, but the window does not seem to appear.
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
LRESULT CALLBACK myCallBack(HWND regularWnd, UINT message, WPARAM wparam, LPARAM lparam){
switch(message){
case 0x0201:
printf("left Click");
MessageBox(regularWnd, "Left Click", "event handler", MB_OK);
break;
case WM_CLOSE:
DestroyWindow(regularWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(regularWnd, message, wparam, lparam);
break;
}
return 0;
}
int WINAPI WinMain(HINSTANCE newHInstance, HINSTANCE prevHINSTANCE, LPSTR lpCmdLine, int cmdShow){
WNDCLASSEX regularWndClass;
regularWndClass.cbSize = sizeof(WNDCLASSEX);
regularWndClass.cbWndExtra = 0;
regularWndClass.cbClsExtra = 0;
regularWndClass.style = 0;
regularWndClass.lpszClassName = "regularWindowClass";
regularWndClass.lpszMenuName = NULL;
regularWndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
regularWndClass.lpfnWndProc = myCallBack;
regularWndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
regularWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
regularWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
regularWndClass.hInstance = newHInstance;
if(!RegisterClassEx(®ularWndClass) < 0){
perror("Error Wnd class: ");
exit(0);
}
HWND regularWnd;
regularWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "regularWindowClass", "The title of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, NULL, NULL, newHInstance, NULL);
if(regularWnd < 0){
perror("window error : ");
exit(0);
}
ShowWindow(regularWnd, cmdShow);
UpdateWindow(regularWnd);
MSG message;
while(GetMessage(&message, NULL, 0, 0) > 0){
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
CreateWindowEx()will seterrno. Change this to useGetLastError()andFormatMessage()-- but that's just a hint ;) - user2371524ShowWindowfunction on MSDN: msdn.microsoft.com/en-us/library/windows/desktop/… - 303perror, because that checkserrno, which isn't used by Win32 - Edward Karak