TCanvas->ProcessedEvent() not works with Visual Studio 2008

Dear Root experts,

I am developing a program with ROOT Framework using Visual Studio 2008. Everything works fine, except TCanvas->ProcessedEvent().

I try to use TCanvas->Connect(“ProcessedEvent()”, … ) to handle mouse events. However, it seems that VS 2008 doesn’t allow me to do that. ProcessedEvent() couldn’t catch any event. If I want to handle mouse events, I can only use MFC Windows Messages, such as ON_WM_LBUTTONDOWN.

Could anyone give me some advice on how to do this?

Thank you very much!

Have you checked root.cern.ch/download/doc/25WritingGUI.pdf (see section ‘A Standalone Version’). Another option might(?) be to create a new class inherited from TCanvas and override ProcessedEvent.

Thank you so much for your suggestion!

It is a good idea to create TCanvas in MyMainFrame class. But in my program, I am trying to embed the TCanvas in CWnd class. Is it possible to override the Windows Message handler with TCanvas->ProcessedEvent()?

Thanks.

I’m not quite sure whether I understand you correctly in “override the Windows Message handler with TCanvas->ProcessedEvent()”. What comes to the use of signals&slots, I’m not familiar with that area and the link to the documentation likely gives more information on that subject than what I can provide.

And regarding the TCanvas::ProcessedEvent, I made a little test app to verify that the ProcessedEvent does indeed gets triggered on events such as mouse move and mouse click at least in the case that canvas is not embedded in CWnd(see Buttons.h for definition of the event ID’s). If this does not work in the CWnd embedded case and this seems likely based on a quick glimpse on the code, I’m out of ideas easier than manual passing of the messages as pointed out in http://root.cern.ch/drupal/content/how/how-embed-tcanvas-external-applications

class Canvas : public TCanvas
{
public:
	Canvas(const char* const name, const char* const title, const Int_t width, const Int_t height) :
		TCanvas(pszName, pszTitle, width, height)
		{
		}
	void ProcessedEvent(Int_t event, Int_t x, Int_t y, TObject* selected)
	{
		if (event == kButton1Down)
			std::cout << "received kButton1Down" << std::endl;
		else if (event == kMouseMotion)
			std::cout << "received kMouseMotion" << std::endl;
		else
			std::cout << "received event " << event << std::endl;
	}
};

int main(int argc, char* argv[])
{
	TApplication app("app", &argc, argv);
	Canvas* pCanvas = new Canvas("c", "title", 400, 300);
	TF1 tf1("a", "sin(x)", -10, 10);
	tf1.Draw();
	gPad->Update();
	app.Run();
	return 0;
}