So, how can I still have control over my own main loop, and also init/pump/unit wx widgets at the same time? Heres a little test program, (which seems to work for the wxInit/Uninit part), but I have no idea how to run/pump the main wx event loop).
Code: Select all
//main.cpp
#include <wx/wxprec.h>
#include "windows.h"
#include "main.h"
//do i need this?
//IMPLEMENT_APP_NO_MAIN(MyApp)
//=========
//WinMain()
//=========
int WINAPI WinMain( HINSTANCE hI, HINSTANCE hPrevI, LPSTR lpCmdLine, int nCmdShow ) {
wxInitialize();
//my main loop
bool mainQuit = false;
while ( !mainQuit ) {
//wx widgets main loop goes here
}
wxUninitialize();
return 0;
}
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( "Hello World", wxPoint(50,50), wxSize(450,340));
frame->Show(TRUE);
return TRUE;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_About, "&About..." );
menuFile->Append( ID_Quit, "E&xit" );
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, "&File" );
wxFrame::SetMenuBar( menuBar );
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
Close(TRUE);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("Hello World!");
}
Code: Select all
//main.h
#pragma once
enum
{
ID_Quit = 100,
ID_About = 200,
};
class MyApp: public wxApp
{
virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};