Virtual Developer Workshop: Containerized Development with Docker

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.


  1. 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)

  2. 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"

  3. 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
  4. 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); }
  5. Don't forget to make InitDialogBar() function. Below is my example.

    In header file

      protected: virtual BOOL OnInitDialogBar();
    In source file
      BOOL CMyDialogBar::OnInitDialogBar() { CInitDialogBar::OnInitDialogBar(); return TRUE; }

Download demo project - 50 KB


  • button problem

    Posted by ning's on 04/18/2013 12:57pm

    thanks but sorry. it's easy.but when i click that active button some operation should be done. it's simply enabling button window!!!!!

  • Thanks a million!

    Posted by Legacy on 02/13/2004 08:00am

    Originally posted by: Per Franck

    You saved me tons of grief! thanks thanks thanks!

  • Thank you very much

    Posted by Legacy on 10/19/2003 07:00am

    Originally posted by: Edward King

    Thanks very much for that solution. MFC can be a pain in the arse sometimes !

  • thanks a lot!

    Posted by Legacy on 07/01/2003 07:00am

    Originally posted by: trt

    thanks a lot!

  • It is a good job!

    Posted by Legacy on 03/28/2003 08:00am

    Originally posted by: cutedeer

    It is a good job!

  • ActiveX don't work in a Dialog Bar ... lost the messages ????

    Posted by Legacy on 11/02/2002 08:00am

    Originally posted by: Albert Silvestre


    I can't work with an ActiveX button pasted in a Dialog Bar, lost the message...,
    If I put the same ActiveX in a FormView all is OK any problem, but in the fist case when i try to do the same in a DialogBar its not work...

    Why? I haven't idea ...

    Any body ca help me?

    Thank's you very much!

  • Thanks for the simple solution

    Posted by Legacy on 10/04/2002 07:00am

    Originally posted by: Fei LIU

    I meet the same problem as you.
    The solution is simple, but it really works.
    Thank you very much for the solution.

  • Thank you.....

    Posted by Legacy on 06/27/2002 07:00am

    Originally posted by: eakkung

    you're awesome..... thank you very much for your solution

  • If you are just enabling and disabling...

    Posted by Legacy on 10/10/2001 07:00am

    Originally 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.


  • thanks

    Posted by Legacy on 07/25/2001 07:00am

    Originally posted by: Cheese Hong

    thank you.. thank you..
    none of the books i read shows me the answer..
    but now i got it...
    thanks again!

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date