0

I am working on a Windows application (built with VS 2019) that relies heavily on MFC functionality. I have a class that is derived from the CWnd class that contains CMFCButton objects (children) which are defined dynamically within the OnCreate handler for the class. I would like for the CMFCButton objects to send the WM_PARENTNOTIFY message to its ancestors, so that they can do some additional handling of the mouse events, but they don't. I tried changing the button type to CButton class and noticed that WM_PARENTNOTIFY was sent as expected. The CMFCButton and CButton were defined/created using all the same parameters. Using CButton seems to solve the issue but I also make use of the extended CMFCButton functionality to control the buttons' appearances.

Can anyone please explain the change in behaviour of these two button types and how I can get CMFCButtons to also send the WM_PARENTNOTIFY message?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    Does your `CMFCButton` have the `WS_EX_NOPARENTNOTIFY` [extended window style](https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles) set? – IInspectable Apr 19 '21 at 20:32
  • No, it's defined using the Create method rather than CreateEx. I've only specified the following styles: WS_CHILD|WS_TABSTOP|WS_VISIBLE. My understanding is that the WS_EX_NOPARENTNOTIFY is only a default style if the button is created as part of Dialog template. – SpencerManwell Apr 20 '21 at 17:41
  • I've been using `CMFCButton` extensively and never seen such behavior. BTW, I prefer to create them as a normal button in the resources and then `DDX` them into a `CMFCButton` variable in the dialog code, because otherwise it gets human unreadable hexadecimal strings in the .rc file, and they will be a pain in ass for translations. – sergiol Apr 21 '21 at 12:07
  • Thanks for your reply. This behaviour does seem unexpected. Do you think defining the `CMFCButton` as a resource instead of in the code could have an effect on it's behaviour? – SpencerManwell Apr 21 '21 at 17:53

0 Answers0