![]() |
How to enable or disable the toolbar buttons? |
Post Reply ![]() |
Author | |
evoX ![]() Senior Member ![]() ![]() Joined: 25 July 2007 Status: Offline Points: 207 |
![]() ![]() ![]() ![]() ![]() 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 triedGetCommandBars()->GetToolBar(0)->EnableWindow(FALSE); but the application crashes. |
|
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit Language: Visual C++ (VS 2019) |
|
![]() |
|
mgampi ![]() Senior Member ![]() ![]() Joined: 14 July 2003 Status: Offline Points: 1201 |
![]() ![]() ![]() ![]() ![]() |
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 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
![]() |
|
evoX ![]() Senior Member ![]() ![]() Joined: 25 July 2007 Status: Offline Points: 207 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
tNgLoo ![]() Groupie ![]() Joined: 21 April 2005 Status: Offline Points: 31 |
![]() ![]() ![]() ![]() ![]() |
m_pTheToolBar->SetVisible(FALSE);
|
|
![]() |
|
evoX ![]() Senior Member ![]() ![]() Joined: 25 July 2007 Status: Offline Points: 207 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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);
|
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
evoX ![]() Senior Member ![]() ![]() Joined: 25 July 2007 Status: Offline Points: 207 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
evoX ![]() Senior Member ![]() ![]() Joined: 25 July 2007 Status: Offline Points: 207 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
Same story: you don't check
if (GetCommandBars()->GetToolBar(IDR_TOOLBAR_START))
{
}
I guess it give NULL
|
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
evoX ![]() Senior Member ![]() ![]() Joined: 25 July 2007 Status: Offline Points: 207 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |