Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - How to enable or disable the toolbar buttons?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to enable or disable the toolbar buttons?

 Post Reply Post Reply
Author
Message
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Topic: How to enable or disable the toolbar buttons?
    Posted: 09 January 2009 at 1:43pm

How I can disable the buttons on a toolbar? then after the application completes a task to enable the buttons back?

I have tried

GetCommandBars()->GetToolBar(0)->EnableWindow(FALSE);

but the application crashes.
Product: Xtreme ToolkitPro 17.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2015)
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1070
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2009 at 3:18pm
Hi;
The easiest way is by using the ON_UPDATE_COMMAND_UI handler of the button.
When you start the task set a bool variable to false and after finishing the task reset the variable to true.
In your ON_UPDATE_COMMAND_UI handler set pCmdUI->Enable(m_bTaskFinished==true)
Thats it!
Martin

Product: Xtreme Toolkit v 15.3.1, new Projects v 18.5.0
Platform: Windows 8.1 (64bit)
Language: VC+
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2009 at 9:05pm
Hi,
  Thanks !, but this means that I need an ON_UPDATE_COMMAND_UI handler for each toolbar command/button ?
  Isn't there an easier way to disable all the toolbar buttons at once?
Product: Xtreme ToolkitPro 17.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2015)
Back to Top
tNgLoo View Drop Down
Groupie
Groupie


Joined: 21 April 2005
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote tNgLoo Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 9:16am
m_pTheToolBar->SetVisible(FALSE);
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 3:50pm

If I use this, the application crashes

GetCommandBars()->GetToolBar(0)->SetVisible(FALSE);

Also the I think that SetVisible will completly hide the toolbar which is not what I want.  I just want the buttons to be disabled.
 
Product: Xtreme ToolkitPro 17.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2015)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 8:33pm
You crashing problems related to your dirty programming style:
I am sure you have no GetCommandBars()->GetToolBar(0) at all
You don't check it before asking action:
if (GetCommandBars()->GetToolBar(0))
{
   GetCommandBars()->GetToolBar(0)->SetVisible(FALSE);

   GetCommandBars()->GetToolBar(0)->SetContextMenuPresent(FALSE);

}
 
e.g. for most app this code will works
GetCommandBars()->GetToolBar(IDR_MAINFRAME)->SetVisible(FALSE);
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 9:14pm
You can access individual toolbar button or other elements with:

CXTPControl* pBarControl = GetCommandBars()->GetToolBar(IDR_MAINFRAME)->GetControl(1);//0=New, 1=Open and so on

if (pBarControl)

pBarControl->SetEnabled(FALSE);

BUT IT WILL NOT HELP YOU as System will enable it because you don't like to use  ON_UPDATE_COMMAND_UI and by default all will be enable again
while code

void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI)

{

pCmdUI->Enable(FALSE);

}

do proper work
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 10:23pm
well I don't think that it's my dirty programming style, because even with this line it crashes
CXTPControl* pBarControl = GetCommandBars()->GetToolBar(IDR_TOOLBAR_START)->GetControl(0);//0=New, 1=Open and so on
 
It crashes in this XTP function with access violation
int CXTPCommandBar::GetControlCount() const
{
 return m_pControls->GetCount();
}
 
I will try to use ON_UPDATE_COMMAND_UI
Product: Xtreme ToolkitPro 17.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2015)
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 10:40pm

I used ON_UPDATE_COMMAND_UI, but now the problem is that the button remains disabled forever because ON_UPDATE_COMMAND_UI is called only when you press the button

(and yes, the m_bTaskRunning is set correctly to FALSE after the task is finished, but the toolbar button still remains disabled)
 
void CMainPropertySheet::OnUpdateMenuStart(CCmdUI* pCmdUI)
{
 if (m_bTaskRunning == TRUE) pCmdUI->Enable(FALSE);
 else pCmdUI->Enable(TRUE);
}
Product: Xtreme ToolkitPro 17.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2015)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 10:48pm
Same story: you don't check
if (GetCommandBars()->GetToolBar(IDR_TOOLBAR_START))
{
 
}
I guess it give NULL
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 11:36pm
void CMainPropertySheet::OnUpdateMenuStart(CCmdUI* pCmdUI)
{
   pCmdUI->Enable(!m_bTaskRunning);
}
ProperySheets - Wizards have little bit another handling - look in any sample where you have "Finish" button which disable until some condition
 
I gave you some standard ideas for SDI - MDI architecture
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2009 at 11:55pm
this is that you need:
Using ON_UPDATE_COMMAND_UI message maps in property pages is the same as in dialogs except for one extra step required.
You need to derive a class from CPropertySheet and intercept the WM_KICKIDLE messages.
1. Create a new class called CMyPropSheet with a base class of CPropertSheet.
2. In the header add the message function. afx_msg LRESULT OnIdleUpdateCmdUI(WPARAM, LPARAM);
3. In the source file #include afxpriv.h
4. Add the message map ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
5. Implement the function.
LRESULT CMyPropSheet::OnKickIdle(WPARAM, LPARAM)
{
 SendMessageToDescendants(WM_WM_KICKIDLE, 0, 0, FALSE, FALSE);
 return 0;
}
The property sheet now passes all WM_KICKIDLE message to its property pages.
 
In the property page class, just add a message map for WM_KICKIDLE and call UpdateDialogControls.
LRESULT CMyPropPage::OnKickIdle(WPARAM, LPARAM)
{
 UpdateDialogControls(this, FALSE);
 return 0L;
}
Then all you need is ON_UPDATE_COMMAND_UI message maps.
P.S. This does not work for modeless property sheets. You need to trap the WM_IDLEUPDATECMDUI message in the property sheet's owner window and send it WK_KICKIDLE messages.
 
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2009 at 10:51am
Hi,
   CXTPCommandBars* pCommandBars = GetCommandBars(); // This returns the correct pointer

   CXTPToolBar* pToolbar = pCommandBars->GetToolBar(IDR_TOOLBAR_START); // here I get NULL (I don't know why because the toolbar is created when I call this)

 CXTPToolBar* pToolbar = pCommandBars->GetAt(0); // This will return a correct pointer !
 
 
  why do I need to add OnKickIdle in the property page? because the toolbar is in the propertysheet in place of the standard wizard buttons.
   I need to modify the MFC source code afxpriv.h ?
 
Thanks !
Product: Xtreme ToolkitPro 17.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2015)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2009 at 12:17pm
CXTPToolBar* pToolbar = pCommandBars->GetToolBar(IDR_TOOLBAR_START); // here I get NULL (I don't know why because the toolbar is created when I call this) - This is very bad situation - it means that you created temporary object which disapear later (like you leave a scoop?)
I need to modify the MFC source code afxpriv.h ? - No, you just use some private MFC feature
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0.078 seconds.