15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Toolbar Button Status

Alun -- alun@des.co.uk
Friday, October 11, 1996

Environment: VC++ 1.52, Win 3.1x

Hi All

I have a test application which has a toolbar to 'simplify' its use, if I
disable a menu item as a result of some action the user takes, this doesn't
seem to affect the toolbar buttons in any way.

Can anyone tell me how I can change the status of the toolbar buttons.

Thanks in advance
The Loon



Michael Patterson -- patterso@sprynet.com
Saturday, October 12, 1996

[Mini-digest: 2 responses]

Hi,
Forgive me if I haven't given enough.  I think this should work.  You
can change the non-MFC stuff to MFC (if you wish).
Take care,
Mike


ON_UPDATE_COMMAND_UI(IDM_MENUITEM, OnUpdateButton1)  // put in message map

afx_msg void OnUpdateButton1(CCmdUI* pCmdUI) // mainfrm.h file
{
        UpdateToolbarBtn(IDM_MENUITEM, pCmdUI);
}

// if I am not mistaken, you will have to implement
// the above for each button - there could be a better way???

void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file

void CMainFrame::UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI) // mainfrm.cpp file
{
	UINT nFlags;
	HMENU hMainMenu = ::GetMenu(m_hWnd);
	///
	nFlags = ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
	//
	pCmdUI->Enable(nFlags == MF_ENABLED); // TRUE or FALSE
}


At 04:39 PM 10/11/96 +0100, you wrote:
>Environment: VC++ 1.52, Win 3.1x
>
>Hi All
>
>I have a test application which has a toolbar to 'simplify' its use, if I
>disable a menu item as a result of some action the user takes, this doesn't
>seem to affect the toolbar buttons in any way.
>
>Can anyone tell me how I can change the status of the toolbar buttons.
>
>Thanks in advance
>The Loon
>
********************
Michael Patterson
patterso@sprynet.com
********************
Phoenix, Arizona, USA

-----From: ppbillc@srv2.sj.ablecom.net

Each toolbar button should be asociated with a menu item via a
Command ID.  So if you "disable" a menu item the toolbar item should 
also be diabled.
 
What I suspect is wrong is that you directly disabled the menu item 
and didnt use the **OnUpdateCmdUI** function that should be
associated with each menu item.

  Follow these steps :

   Go to your resources and select the menu
  Hold down CTRL and double click the menu 
  item you wish to work with

  This will bring you to class wizard

  You will see two functions
 COMMAND
 UPDATE_COMMAND_UI

 Double click these to create 2 functions in your source code that 
will handle this menu item.

 Hope this helps

Bill

  






 
 /    \
 *    *
\ _,-._/



Mike Morel -- mmorel@mushroomsoft.com
Sunday, October 13, 1996

>ON_UPDATE_COMMAND_UI(IDM_MENUITEM, OnUpdateButton1)  // put in message =
map
>
>afx_msg void OnUpdateButton1(CCmdUI* pCmdUI) // mainfrm.h file
>{
>        UpdateToolbarBtn(IDM_MENUITEM, pCmdUI);
>}
>
>// if I am not mistaken, you will have to implement
>// the above for each button - there could be a better way???
>
>void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file
>
>void CMainFrame::UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI) // =
mainfrm.cpp file
>{
>	UINT nFlags;
>	HMENU hMainMenu =3D ::GetMenu(m_hWnd);
>	///
>	nFlags =3D ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
>	//
>	pCmdUI->Enable(nFlags =3D=3D MF_ENABLED); // TRUE or FALSE
>}

Yes, I think there is a better way.  You can use =
ON_UPDATE_COMMAND_UI_RANGE instead of ON_UPDATE_COMMAND_UI.  I think it =
would then look something like this:

ON_UPDATE_COMMAND_UI_RANGE( IDM_MENUITEMFIRST, IDM_MENUITEMLAST, =
UpdateToolbarBtn )
void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file

void CMainFrame::UpdateToolbarBtn(CCmdUI *pCmdUI, UINT nID) // =
mainfrm.cpp file
{
	UINT nFlags;
	HMENU hMainMenu =3D ::GetMenu(m_hWnd);
	///
	nFlags =3D ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
	//
	pCmdUI->Enable(nFlags =3D=3D MF_ENABLED); // TRUE or FALSE
}

Mike Morel
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com/mushroom






----------
From: 	Michael Patterson[SMTP:patterso@sprynet.com]
Sent: 	Saturday, October 12, 1996 5:22 PM
To: 	mfc-l@netcom.com
Subject: 	Re: Toolbar Button Status

[Mini-digest: 2 responses]

Hi,
Forgive me if I haven't given enough.  I think this should work.  You
can change the non-MFC stuff to MFC (if you wish).
Take care,
Mike


ON_UPDATE_COMMAND_UI(IDM_MENUITEM, OnUpdateButton1)  // put in message =
map

afx_msg void OnUpdateButton1(CCmdUI* pCmdUI) // mainfrm.h file
{
        UpdateToolbarBtn(IDM_MENUITEM, pCmdUI);
}

// if I am not mistaken, you will have to implement
// the above for each button - there could be a better way???

void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file

void CMainFrame::UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI) // =
mainfrm.cpp file
{
	UINT nFlags;
	HMENU hMainMenu =3D ::GetMenu(m_hWnd);
	///
	nFlags =3D ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
	//
	pCmdUI->Enable(nFlags =3D=3D MF_ENABLED); // TRUE or FALSE
}


At 04:39 PM 10/11/96 +0100, you wrote:
>Environment: VC++ 1.52, Win 3.1x
>
>Hi All
>
>I have a test application which has a toolbar to 'simplify' its use, if =
I
>disable a menu item as a result of some action the user takes, this =
doesn't
>seem to affect the toolbar buttons in any way.
>
>Can anyone tell me how I can change the status of the toolbar buttons.
>
>Thanks in advance
>The Loon
>
********************
Michael Patterson
patterso@sprynet.com
********************
Phoenix, Arizona, USA

-----From: ppbillc@srv2.sj.ablecom.net

Each toolbar button should be asociated with a menu item via a
Command ID.  So if you "disable" a menu item the toolbar item should=20
also be diabled.
=20
What I suspect is wrong is that you directly disabled the menu item=20
and didnt use the **OnUpdateCmdUI** function that should be
associated with each menu item.

  Follow these steps :

   Go to your resources and select the menu
  Hold down CTRL and double click the menu=20
  item you wish to work with

  This will bring you to class wizard

  You will see two functions
 COMMAND
 UPDATE_COMMAND_UI

 Double click these to create 2 functions in your source code that=20
will handle this menu item.

 Hope this helps

Bill

 =20






=20
 /    \
 *    *
\ _,-._/







DFPav@aol.com
Monday, October 14, 1996

>>I have a test application which has a toolbar to 'simplify' its use, if I
>>disable a menu item as a result of some action the user takes, this doesn't
>>seem to affect the toolbar buttons in any way.

>>Can anyone tell me how I can change the status of the toolbar buttons.

Toolbars:
1. Make sure your button id matches your menu id
2. Handle the enable/disable in an OnUpdateUI handler.  Use the Class Wizard
to add this.  This handler gets called for both the toolbar and menu item.





Alun -- alun@des.co.uk
Tuesday, October 15, 1996

======== Original Message ========
>ON_UPDATE_COMMAND_UI(IDM_MENUITEM, OnUpdateButton1)  // put in message map
>
>afx_msg void OnUpdateButton1(CCmdUI* pCmdUI) // mainfrm.h file
>{
>        UpdateToolbarBtn(IDM_MENUITEM, pCmdUI);
>}
>
>// if I am not mistaken, you will have to implement
>// the above for each button - there could be a better way???
>
>void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file
>
>void CMainFrame::UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI) // mainfrm.cpp
file
>{
>	UINT nFlags;
>	HMENU hMainMenu = ::GetMenu(m_hWnd);
>	///
>	nFlags = ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
>	//
>	pCmdUI->Enable(nFlags == MF_ENABLED); // TRUE or FALSE
>}

Yes, I think there is a better way.  You can use ON_UPDATE_COMMAND_UI_RANGE
instead of ON_UPDATE_COMMAND_UI.  I think it would then look something like
this:

ON_UPDATE_COMMAND_UI_RANGE( IDM_MENUITEMFIRST, IDM_MENUITEMLAST,
UpdateToolbarBtn )
void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file

void CMainFrame::UpdateToolbarBtn(CCmdUI *pCmdUI, UINT nID) // mainfrm.cpp
file
{
	UINT nFlags;
	HMENU hMainMenu = ::GetMenu(m_hWnd);
	///
	nFlags = ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
	//
	pCmdUI->Enable(nFlags == MF_ENABLED); // TRUE or FALSE
}

Mike Morel
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com/mushroom






----------
From: 	Michael Patterson[SMTP:patterso@sprynet.com]
Sent: 	Saturday, October 12, 1996 5:22 PM
To: 	mfc-l@netcom.com
Subject: 	Re: Toolbar Button Status

[Mini-digest: 2 responses]

Hi,
Forgive me if I haven't given enough.  I think this should work.  You
can change the non-MFC stuff to MFC (if you wish).
Take care,
Mike


ON_UPDATE_COMMAND_UI(IDM_MENUITEM, OnUpdateButton1)  // put in message map

afx_msg void OnUpdateButton1(CCmdUI* pCmdUI) // mainfrm.h file
{
        UpdateToolbarBtn(IDM_MENUITEM, pCmdUI);
}

// if I am not mistaken, you will have to implement
// the above for each button - there could be a better way???

void UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI); // mainfrm.h file

void CMainFrame::UpdateToolbarBtn(UINT nID, CCmdUI *pCmdUI) // mainfrm.cpp
file
{
	UINT nFlags;
	HMENU hMainMenu = ::GetMenu(m_hWnd);
	///
	nFlags = ::GetMenuState(hMainMenu, nID, MF_BYCOMMAND);
	//
	pCmdUI->Enable(nFlags == MF_ENABLED); // TRUE or FALSE
}


At 04:39 PM 10/11/96 +0100, you wrote:
>Environment: VC++ 1.52, Win 3.1x
>
>Hi All
>
>I have a test application which has a toolbar to 'simplify' its use, if I
>disable a menu item as a result of some action the user takes, this doesn't
>seem to affect the toolbar buttons in any way.
>
>Can anyone tell me how I can change the status of the toolbar buttons.
>
>Thanks in advance
>The Loon
>
********************
Michael Patterson
patterso@sprynet.com
********************
Phoenix, Arizona, USA

-----From: ppbillc@srv2.sj.ablecom.net

Each toolbar button should be asociated with a menu item via a
Command ID.  So if you "disable" a menu item the toolbar item should 
also be diabled.
 
What I suspect is wrong is that you directly disabled the menu item 
and didnt use the **OnUpdateCmdUI** function that should be
associated with each menu item.

  Follow these steps :

   Go to your resources and select the menu
  Hold down CTRL and double click the menu 
  item you wish to work with

  This will bring you to class wizard

  You will see two functions
 COMMAND
 UPDATE_COMMAND_UI

 Double click these to create 2 functions in your source code that 
will handle this menu item.

 Hope this helps

Bill

  






 
 /    \
 *    *
\ _,-._/
======== Fwd by: Alun ========
Thanks all for your help, I now have toolbar buttons which enable and
disable with their menu items.

One thing I would suggest is that when submitting suggestions. help, etc. is
that you check your suggestion is viable for the environment being used.

If I didn't have MSDN available it would have taken a while to discover why
ON_UPDATE_COMMAND_UI_RANGE is not available in VC++ 1.52, its a 32 bit MFC
macro not 16 bit, if I ever convert from 16 to 32 bit the information will
prove useful but when using 16 bit it proved an inconvenience.

I have it implemented with a UI handler for each menu item that has an
associated button that needs state changing.

A similar line is used in each handler:

void CMainWnd::OnUpdateTestsetup(CCmdUI* pCmdUI)
{
    pCmdUI->Enable(GetMenu()->GetMenuState(IDC_TESTSETUP,MF_BYCOMMAND) ==
MF_ENABLED);
}

Once again thanks to you all.




| Вернуться в корень Архива |