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

  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



Comments

  • button problem

    Posted by ning's on 04/18/2013 05:57am

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

    Reply
  • Thanks a million!

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

    Originally 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:00am

    Originally posted by: Edward King

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

    Reply
  • thanks a lot!

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

    Originally posted by: trt

    thanks a lot!

    Reply
  • It is a good job!

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

    Originally 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:00am

    Originally posted by: Albert Silvestre

    Hello,
    
    

    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!

    Reply
  • Thanks for the simple solution

    Posted by Legacy on 10/04/2002 12: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.

    Reply
  • Thank you.....

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

    Originally posted by: eakkung

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

    Reply
  • If you are just enabling and disabling...

    Posted by Legacy on 10/10/2001 12: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.

    CD

    Reply
  • thanks

    Posted by Legacy on 07/25/2001 12: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!

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

Most Popular Programming Stories

More for Developers

RSS Feeds