PreTranslateMessage in MFC Rhino PlugIn

rhino5

(Peter Salzmann) #1

Hi, one question: If I want my C++ MFC PlugIn want to receive Windows messages, I need to add a PreTranslateMessage function to my PlugInApp.cpp. But unfortunately it is never called… Do I need to do something aditional (e.g. a message hook) ? many thanks Peter


(Dale Fugier) #2

For modeless dialogs, this is true.

https://msdn.microsoft.com/en-us/library/30c674tx.aspx

What are you working on?

– Dale


(Peter Salzmann) #3

Hi Dale, thanks for the quick answer.
My Plugin has no dialog, but wants to bring something up like a 3D handle. To modify this, I need access to Mouse Move, Mouse key events etc.

I remember in earlier software we did this using PreTranslateMessage, but maybe there was a trick. I tried already to use the macro

AFX_MANAGE_STATE( AfxGetStaticModuleState() );

but my local PreTranslateMessage function is still ot called.

Thanks

Peter


(Dale Fugier) #4

Hi Peter,

Overriding PreTranslate on your CWinApp-derived object is the wrong location. First, a CWinApp, in DLL, has no hWnd. CWinApp does contains a message pump. But you are running in a DLL so the main message pump is in Rhino.

You’ll need to create hidden window and send messages to that window. Make it a child of the main Rhino window.

Let me know if you need an example. :wink:

– Dale


(Peter Salzmann) #5

Many thanks.
And yes, a small example would be great!


(Peter Salzmann) #6

Dale,
I think I got it! I added a dummy dialog (see below), now I receive messages.

many thanks


 m_TranslateMessage_dlg = new CRhinoUiDialog();
  if (!m_TranslateMessage_dlg->Create(IDD_DUMMY_DIALOG))
  {
     delete m_TranslateMessage_dlg;
     m_TranslateMessage_dlg = NULL;
     return false;
  }
.
.
.


(Dale Fugier) #7

@Peter_Salzman, attached is an example that ‘should’ work.

– Dale

MessageOnlyWnd.zip (1.0 KB)