Solved

Disable Toolbar.

Posted on 2004-04-27
5
882 Views
Last Modified: 2013-11-20
I am working with the document view architecture's tool bars. How can I disable (gray-out) all the buttons in a tool bar? The tool bar is a CToolBar MFC object.

Thanks.
0
Comment
Question by:pcssecure
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10926157
Change the code in your mainframe.cpp as follow
//WS_DISABLED will disable your toolbar

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |WS_DISABLED| CBRS_TOP
            | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
            !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))


0
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10926209
use of ON_UPDATE_COMMAND_UI  wil not only disable toolbar but will grayed particular item also.
0
 

Author Comment

by:pcssecure
ID: 10926221
Can you show me how to use
ON_UPDATE_COMMAND_UI ? Thanks.
0
 

Author Comment

by:pcssecure
ID: 10926238
I tried to use CWnd.EnableWindow(0). The toolbar is disabled but not grayed.
0
 
LVL 7

Accepted Solution

by:
vijay_visana earned 500 total points
ID: 10926365
IN mainframe.cpp

Add following entry in message map
      ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_NEW,ID_APP_ABOUT, OnUpdateToolbar)

here ID_FILE_NEW and ID_APP_ABOUT is range for my toolbar (created by class wizard ) . If you have different id range subsitute them here

//add following to mainframe.cpp
void CMainFrame::OnUpdateToolbar(CCmdUI *pCmdUI)
{
    pCmdUI->Enable (FALSE);//<<=== here you can take variable /class member
                                          //set it true anywhere and your toolbar will be enable set it false to make
                                         // make toolbar disable
}

//add following to header file for mainframe class


      //{{AFX_MSG(CMainFrame)
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
            // NOTE - the ClassWizard will add and remove member functions here.
      afx_msg void OnUpdateToolbar(CCmdUI *pCmdUI);     //add this line<<=========
            //    DO NOT EDIT what you see in these blocks of generated code!
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()

good luck
Vijay
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 35
ORA-01403: no data found 43 105
Define unique primary key 9 95
modThree challenge 4 96
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question