Sign in to follow this  

A message handler for a custom control on a dialog

This topic is 4299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a custom control, derived from CWnd - it does D3D rendering in the control so let's call it CD3DWnd. Then I have the dialog on which this is placed - CMyDlg. The control on the dialog has ID IDC_D3DPANE. What I want is to have a message handler CMyDlg::OnD3DPaneXXX which is called when something happens to the custom control, like I click on it with the mouse. I can't get anything to work although the dialog is rendered just fine. I'd also like the control to be able to respond to events - like I click on IDC_D3DPANE and both CD3DWnd::OnClick and CMyDlg::OnD3DPaneClick are called. What must I do - I have never had this problem before with normal controls...

Share this post


Link to post
Share on other sites
Hey d000hg,

I would assume that your D3D rendering captures the mouse events and does not send them back to its parent. What is your D3D windowproc like ? Have you tried taking a look at WM_PARENTNOTIFY ?
My two cents
StratBoy61

Share this post


Link to post
Share on other sites
Standard HWNDs do not send a notify message to their parents. Only "derived" windows controls do (and not even all of them, think static without SS_NOTIFY).

You created your own control, you need to do your own notifying. This is not that difficult, just build a WM_NOTIFY message with the correct parameters and send it to your parent. If you don't want to modify your CD3DWnd you can subclass it and add the notification calls there.

Share this post


Link to post
Share on other sites
Ah, got that part I think.

The main thing I want from my control is the ability to respond to a mouse-click. I could build this up from button down/up events, but it seems in theory nicer to perhaps derive from CButton instead of CWnd and get this for free.

This sort of works. Problem is when I click the d3d control, it turns back into a button on button down, until button up. How is the button redrawn without calling OnPaint? I tried calling OnPaint in the LbuttonDown/Up calls and this almost works but it flickers. What am I needing to do better?

Share this post


Link to post
Share on other sites
If you want to keep it a button:

A) Make it an ownerdraw button. This way you and only you do the drawing

B) This changes the drawing to the parents WM_DRAWITEM

I usually use a ownerdraw static (use SS_OWNERDRAW, it does exist). Add on SS_NOTIFY. This way the static will send notification messages and can be updated in WM_DRAWITEM as well. You can also leave out the SS_OWNERDRAW and only process WM_ERASEBKGND and WM_PAINT (return TRUE in WM_ERASEBKGND and only do the drawing in WM_PAINT is the easier solution).
You may have to return DLGC_WANTALLKEYS on receiving WM_GETDLGCODE to get all key presses as well as the mouse messages.

Share this post


Link to post
Share on other sites

This topic is 4299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this