Using Buttons on a Dialog Bar with CCmdUI
I am a Korean and not a native english speacker. Please, forgive my poor english.
I was very happy after finding Alger Pike's article, which is "A CDialogBar with OnInitDialog() and DDX Support".
I wanted to make floating dialog bar but MFC did not support for class wizard for dialog bar. To worse, MFC did not support DDX for dialog bar.
I struggled so long time to solve the problem. At last I found www.codeguru.com and Alger Pike's article! Can you imagine my shout with greatest pleasure?
But I have an another problem. According to Alger Pike's explanation, I made my dialog bar. But every buttons on that bar don't work! Oopse....what can I do?
I asked Alger Pike that problem via email. He gave me a hint. It is that use CmdUI!
I have some confusions how I can use CmdUI in dialog bar. Probably you make sense already that I'm a novice to MFC. Yes, I am. But at last I soved the quiz.
I'll give my solution to you. Don't waste time for same problem with me.
Thanks again to Alger Pike and www.codeguru.com. Good luck for you and Alger Pike and www.codeguru.com.
Below is breif explanation about my solution. You can find complete source code at header file and source file for CMyDialogBar. CInitDialog is Alger Pike's class.

Instructions
- Make Dialog Resource for your dialog bar
- Use resource editor provided by Visual C++
- Change style to child
- Change border to none (or as you wish)
- Make Dialog Class for your dialob bar
- Double click your dialog resource in resource editor
- then class wizard will ask if you will make new class, answer yes
- give name for your own dialog class
- go to class header file and change parent class from CDialog to CInitDialogBar
- Don't forget #include "InitDialogBar.h"
- go to class source file and replase all "CDialog" with "CInitDialogBar"
- Add below to header file for your dialog bar
Of coursely, you must change OnButton1() to your own function
-
protected:
void OnUpdateButton1(CCmdUI *pCmdUI);
//{{AFX_MSG(CMyDialogBar)
afx_msg void OnButton1();
//}}AFX_MSG
- Add below to your source file for your dialog bar
In OnUpdateButton1(), I set button enable always.
But you can enable and disable according to your need.
-
BEGIN_MESSAGE_MAP(CMyDialogBar, CInitDialogBar)
//{{AFX_MSG_MAP(CMyDialogBar)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CMyDialogBar::OnButton1()
{
// TODO: Add your control notification handler code here
}
void CMyDialogBar::OnUpdateButton1(CCmdUI *pCmdUI)
{
pCmdUI->Enable(TRUE);
}
- Don't forget to make InitDialogBar() function.
Below is my example.
In header file
In source file-
protected:
virtual BOOL OnInitDialogBar();
-
BOOL CMyDialogBar::OnInitDialogBar()
{
CInitDialogBar::OnInitDialogBar();
return TRUE;
}

Comments
button problem
Posted by ning's on 04/18/2013 05:57amthanks but sorry. it's easy.but when i click that active button some operation should be done. it's simply enabling button window!!!!!
ReplyThanks a million!
Posted by Legacy on 02/13/2004 12:00amOriginally posted by: Per Franck
You saved me tons of grief! thanks thanks thanks!
Reply
Thank you very much
Posted by Legacy on 10/19/2003 12:00amOriginally posted by: Edward King
Thanks very much for that solution. MFC can be a pain in the arse sometimes !
Replythanks a lot!
Posted by Legacy on 07/01/2003 12:00amOriginally posted by: trt
thanks a lot!
ReplyIt is a good job!
Posted by Legacy on 03/28/2003 12:00amOriginally posted by: cutedeer
It is a good job!
Reply
ActiveX don't work in a Dialog Bar ... lost the messages ????
Posted by Legacy on 11/02/2002 12:00amOriginally posted by: Albert Silvestre
ReplyThanks for the simple solution
Posted by Legacy on 10/04/2002 12:00amOriginally posted by: Fei LIU
I meet the same problem as you.
ReplyThe solution is simple, but it really works.
Thank you very much for the solution.
Thank you.....
Posted by Legacy on 06/27/2002 12:00amOriginally posted by: eakkung
you're awesome..... thank you very much for your solution
ReplyIf you are just enabling and disabling...
Posted by Legacy on 10/10/2001 12:00amOriginally posted by: Chris Dickens
There isn't really any reason to use a custom dialog bar class. Just make the dialog bar resource part of the CMainFrame class and add ON_UPDATE_COMMAND_UI handlers for the objects.
Dialog Items will be disabled by default if there are no UPDATE_COMMAND_UI or COMMAND functions described for the object.
CD
Replythanks
Posted by Legacy on 07/25/2001 12:00amOriginally posted by: Cheese Hong
thank you.. thank you..
Replynone of the books i read shows me the answer..
but now i got it...
thanks again!
Loading, Please Wait ...