Custom Buttons Using CDialogBar, CButton, and CControlBar :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

I am trying to implement a basic static toolbar. Here is the design.

- create a dialog box
- add a button (just consider one button for now)
- use CDialogBar to create the dialogbar at construction
- use GetDlgItem(IDC_Button) to get a pointer to the button

Okay. The design above works well. I have two major problems. First, the button does not look like a normal button. The button looks flat and is out of focus. Secondly, I am not sure where to add the message handler for the button.

What I have done is difficult to explain. I hope the brief explanation above is enough. Here is a simple code for it.

-----
CDialogBar m_MyDlgBar;
CButton *m_pButton;

int CMainFrame::eek:nCreate()
{
...
if (!m_MyDlgBar.Create(this, IDD_MYDLG, CBRS_BOTTOM, IDD_MYDLG))
{
TRACE0("Panel creation failed");
return -1;
}

m_pButton = reinterpret_cast<CButton *>(m_MyDlgBar.GetDlgItem(IDC_BUTTON));

ShowControlBar(&m_MyDlgBar, TRUE, FALSE);
-----

So basically, I need to somehow set the button to look like a normal button. Secondly, I need to know where to add a message handler for the button.

Thanks,
Kuphryn
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Button message routing is to the parent, so you would sublclass CDialogBar and put a handler there (which could use PostMessage to pass the message on somewhere else if necessary)

Look in the myapp.RC file (open "as text") to see what window/button styles you should be creating the button with (look at any dialog template that has buttons, including IDD_ABOUT).