Print Page | Close Window

How to enable or disable the toolbar buttons?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=13137
Printed Date: 18 April 2024 at 10:29am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to enable or disable the toolbar buttons?
Posted By: evoX
Subject: How to enable or disable the toolbar buttons?
Date 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 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)



Replies:
Posted By: mgampi
Date 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 19.0.0, new Projects v 19.1.0
Platform: Windows 10 v 1909 (64bit)
Language: VC++ 2017


Posted By: evoX
Date 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 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: tNgLoo
Date Posted: 10 January 2009 at 9:16am
m_pTheToolBar->SetVisible(FALSE);


Posted By: evoX
Date 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 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: mdoubson
Date 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);


Posted By: mdoubson
Date 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


Posted By: evoX
Date 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 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: evoX
Date 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 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: mdoubson
Date Posted: 10 January 2009 at 10:48pm
Same story: you don't check
if (GetCommandBars()->GetToolBar(IDR_TOOLBAR_START))
{
 
}
I guess it give NULL


Posted By: mdoubson
Date 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


Posted By: mdoubson
Date 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.
 


Posted By: evoX
Date 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 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: mdoubson
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net