I am creating a windows application. I am trying to set up an Application class and handle events in a member function inside it, and have an instance of the class declared beforehand to be called inside the windows procedure.
I expect seeing a white unresponsive window but the window creation returns nullptr. This is the main.cpp
#include <windows.h>
#include "WinApplication.h"
WinApplication* app;
LRESULT CALLBACK windowCallback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//return DefWindowProc(hwnd, uMsg, wParam, lParam);
return app->appCallback(uMsg, wParam, lParam);
}
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
app = new WinApplication();
WNDCLASS window_class = {};
window_class.style = CS_HREDRAW | CS_VREDRAW;
window_class.lpszClassName = TEXT("Window Class");
window_class.lpfnWndProc = windowCallback;
// Register Class
if (!RegisterClass(&window_class))
return 1;
// Create Window
HWND window = CreateWindow(window_class.lpszClassName, TEXT("MyApp"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, DEF_WIDTH, DEF_HEIGHT, 0, 0, hInstance, 0);
app->init(window);
while (true) { }
return 0;
}
and this is the member callback:
LRESULT WinApplication::appCallback(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
Any help would be appreciated
New contributor
Daniel Hamzany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.