Getting CDialogBar to actually work

Well while writing my MFC application tonight, (5am, whew!) and trying to transition out of the Dialog box state of mind (or somewhat anyway) I found a useful MFC class called CDialogBar. Sounded too good to be true, and it was. Partially because it's not supported by ClassWizard which makes things interesting.

After struggling with getting CDialogBar in the app, the buttons were permanently greyed out (unless I hacked something). I also wanted to change the button text. I eventually stumbled on a nice discussion in a couple of places... here on codeguru and in the VisualStudio6 help: HOWTO: How to Initialize Child Controls in a Derived CDialogBar.

Since this took me awhile to solve such a seemingly simple problem, I figure I'll post my code. Read the codeguru explanation first (version I clipped off the page here) then you can take a look at my files and they should make some sense. I hope. I fixed the few modifications that several posters made to the original posted code, so it's sort-of new and improved. Almost.

AvatarDialogBar is my name for CMainDialogBar, and IDD_Button1 is the only control I had on the dialog box. It's dockable, and the button is enabled, and it works! InitDialogBar is the code from the website (the base class) and AvatarDialogBar is the derived class that I made.

Heres the code: Enjoy!

Have a great day