Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disabling toolbar-button

0 views
Skip to first unread message

Ųyvind Riise

unread,
Sep 21, 2000, 3:00:00 AM9/21/00
to
Hi,

I trying to disable one of my toolbar-buttons with the following
code:

CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
CToolBar* pToolBar = pMainFrame->GetToolBar();
CToolBarCtrl* pToolBarCtrl = &(pToolBar->GetToolBarCtrl());
pToolBarCtrl->EnableButton(ID_VIEW_SHOWATTRIBUTES, FALSE);

But the button does not get disabled. Anyone know why? I have put these
lines of code into the method OnInitialUpdate of my view.

Thanks,
Ųyvind

MussolTrek

unread,
Sep 21, 2000, 3:00:00 AM9/21/00
to
I don't konw exactly, but you can use this method. You can use a global
bool variable, button enabled or button disabled, and after use the
on_command_ui function and use pCmd param for each button of toolbar
(one on_commmand_ui for each button ).

pCmd->Enable(1) ..... i don't remember if the method Enable its
correct, but its very similar

I do the same, but with chekbutton as style of buttons of tool bar

> Øyvind

Joseph M. Newcomer

unread,
Sep 21, 2000, 3:00:00 AM9/21/00
to
The problem is that you are changing the button state, but the
ON_UPDATE_COMMAND_UI handler is always there changing it out from
under you. The major difference between MFC and pure C programming is
that in MFC you rarely "take control" in this way; instead, you use
the built-in MFC mechanisms. If you don't use them, they are there
anyway and undo the explicit menu/toolbar enabling you may be doing.
joe

On Thu, 21 Sep 2000 10:34:53 +0200, "Ųyvind Riise"
<oyvind...@telenor.com> wrote:

>Hi,
>
>I trying to disable one of my toolbar-buttons with the following
>code:
>
> CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
> CToolBar* pToolBar = pMainFrame->GetToolBar();
> CToolBarCtrl* pToolBarCtrl = &(pToolBar->GetToolBarCtrl());
> pToolBarCtrl->EnableButton(ID_VIEW_SHOWATTRIBUTES, FALSE);
>
>But the button does not get disabled. Anyone know why? I have put these
>lines of code into the method OnInitialUpdate of my view.
>
>Thanks,

>Ųyvind
>

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

0 new messages