mfccwndcbitmap

Can I attach a CBitmapButton to a parent CWnd, instead of a parent CDialog?


I have inherited a project (originally written for Win95!) which has a number of buttons attached to a parent window derived from CWnd. The buttons themselves are in a user-defined class derived from CWnd, so they are not "real" buttons, but little windows that are defined by gazillions of lines of code, and have a ton of display issues that I've been sweating over for several weeks, with no resolution in sight.

We concluded the other day that CBitmapButton looked like a great alternative. Appears simple, define 4 bitmaps for the different button states. About all I need is BN_CLICKED to fire up a handler, and I'd be golden.

After messing around with this for a while, setting up a button and some bitmaps, I was able to display the CBitmapButton; didn't look great, but I can fix that... the problem NOW is that I attempted to set up a message map to capture the BN_CLICKED message, but since the parent window is derived from CWnd instead of CDialog, I get syntax errors setting up the message map. Read the MSDNs on the subject a few times over, and it appears you can only hook up a CBitmapButton to a CDialog-derived class. This seems pretty weird to me - I just want a button, and it should be able to transmit a simple "I was clicked" to whatever parent it's attached to, but apparently not destined to happen.

So, has anyone successfully attached a CBitmapButton to a CWnd-derived parent; and if so how does one set up a message map that will work with these things? Alternatively, what approach would you use to set up a button class that WOULD work with a CWnd parent, since CBitmapButton and CButton seem to require CDialog's as parents?


Solution

  • No it doesn't require that your parent window should always be CDiaglot, you can even inherit from CWnd and create a CButton/CBitmapButton inside it.

    You can override OnCommand message in your CWnd derived class and tap the button click event.