My OS is Windows 10, I use MSVC v142 (combined with VS2019), and wxWidgets 3.1.3. I have an old Windows C++ application that uses WinAPI for its GUI features, i.e Windows message loop, using "CreateWindow", and having to "manually" create all window procedures and event handling. I want to improve this application by gradually replacing the UI using wxWidgets so I don't have to start over from scratch. I would implement new, independent UI features in wxWidgets (e.g specific dialogs), and then gradually work my way back and replace all the old UI code with a wxWidgets implementation, without having to break the app along the way.
Until I can fully replace WinAPI with wxWidgets, I need to find a way to allow the two to "coexist", with the main function and message loop being initialized by WinAPI. First of all, is this actually possible? If so, where and how should I initialize wxWidgets so that I can create custom items (e.g dialogs) at runtime? From what I could find online, I need to make a class that's derived from wxApp and use the "wxIMPLEMENT_APP_NO_MAIN" macro, but beyond that point, the explanations got rather vague.
Below is a very stripped-down skeleton of my app:
Code: Select all
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Main window procedure code...
}
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* lpCmdLine, int nCmdShow)
{
// Register main window class, etc...
// Have the window use MainWndProc
HWND mainwnd = CreateWindow(/* Parameters... */);
do
{
MSG msg = {};
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
// Main message loop, translate and dispatch messages
// ...
}
// Per-frame application logic...
} while (msg.message != WM_QUIT);
// Clean up all resources
return 0;
}