Using Passing wx events from winProc() Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Qasim
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 23, 2007 3:41 pm
Location: London

Using Passing wx events from winProc()

Post by Qasim » Wed Feb 27, 2008 6:20 pm

I want to pass events from within WndProc of my Win32 application to wx. I am trying to some thing like this, but dont know about pros or cons. I am not an expert, so If any one know a better way please let me know as well. Any help will be greatly appreciated.
Cheers

This is what I am doing.

Code: Select all

class MyApp : public wxApp
{
public:
    MyApp();
	virtual bool OnInit();
	void OnLButtonDown(wxMouseEvent&);
	DECLARE_EVENT_TABLE();
};

IMPLEMENT_APP_NO_MAIN(MyApp);

BEGIN_EVENT_TABLE(MyApp, wxApp)
EVT_LEFT_DOWN(MyApp::OnLButtonDown)
END_EVENT_TABLE()

void MyApp::OnLButtonDown(wxMouseEvent& e)
{
	if(e.LeftDown())
		wxMessageBox("wxMouse Clicked");
}



..winMain(...)
{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;
	//register window
	wc.lpfnWndProc = WndProc;
	...
	
	hwnd = CreateWindowEx(...);

	//WXWIDGETS INITIALIZATION CODE
	int arc = 0;
	wxEntryStart(argc, NULL);
	wxTheApp->OnInit();//


	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	
	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;

}


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

	//MY CODE TO CALL WXPROC-- ANY SUGGESTIONS
	if(wxTheApp)
	{
		wxWindowMSW* winprt = wxTheApp->GetTopWindow();
		winprt->MSWWindowProc(msg, wParam, lParam);
	}
	//-----

  switch(msg)
  {
	default:
	return DefWindowProc(...);
	}
	return 0;
   }
}
Who doubts nothing, Knows nothing

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Feb 28, 2008 8:07 am

Hi!
I'm not really sure why you would need winmain in this case. Can't you simply overload MSWWindowProc, which is a virtual method, and catch events there?
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Post Reply