I'm using MSVisual C++. In my program, I have a main window with a menu bar across the top. Alternate clicks of a button on the menu initiates or terminates a soundcard playing a pure tone. But there is a delay before the soundcard plays the tone, during which I would like to tell the user that the button click was processed (so it isn't clicked again). Is there a way to change the text label of the menu button from within the program to display the current state of either that the soundcard is going to play or instead that the program is waiting for a mouse click?
Comments
:
:
get the HWND of the button then call SetWindowText().
: : I'm using MSVisual C++. In my program, I have a main window with a menu bar across the top. Alternate clicks of a button on the menu initiates or terminates a soundcard playing a pure tone. But there is a delay before the soundcard plays the tone, during which I would like to tell the user that the button click was processed (so it isn't clicked again). Is there a way to change the text label of the menu button from within the program to display the current state of either that the soundcard is going to play or instead that the program is waiting for a mouse click?
: :
: :
:
: get the HWND of the button then call SetWindowText().
:
:
: : : I'm using MSVisual C++. In my program, I have a main window with a menu bar across the top. Alternate clicks of a button on the menu initiates or terminates a soundcard playing a pure tone. But there is a delay before the soundcard plays the tone, during which I would like to tell the user that the button click was processed (so it isn't clicked again). Is there a way to change the text label of the menu button from within the program to display the current state of either that the soundcard is going to play or instead that the program is waiting for a mouse click?
: : :
: : :
: :
: : get the HWND of the button then call SetWindowText().
: :
:
:
since your program has already created the button then it must also know the HWND handle. Then just simply call SetWindowText() -- see MSDN for description of the function.
[code]
SetWindowText(m_hWnd,"Some Text");
[/code]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowtext.asp
: SetWindowText(m_hWnd,"Some Text");
: [/code]
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowtext.asp
:
:
[blue]Since menu element is not a button - it will not work for menu element. You need to use this one:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus/menureference/menufunctions/modifymenu.asp[/blue]
: : [code]
: : SetWindowText(m_hWnd,"Some Text");
: : [/code]
: : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowtext.asp
: :
: :
: [blue]Since menu element is not a button - it will not work for menu element. You need to use this one:
:
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus/menureference/menufunctions/modifymenu.asp[/blue]
:
[blue]Here is function list to work with menus. Basically, you need to get the menu handle and find the item by its text or command ID.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus.asp
[/blue]
This helped me a lot, thanks. But I'm still having a problem. I was able to control HILITE/UNHILITE of the menu button, so that gives me more-or-less what I wanted in that I can indicate the state of the program. But what I really wanted was to change the button caption, and I couldn't figure out how to do that. I tried the MIIM_STRING, but that didn't work. Do I need to change the menu item to bitmap to change the caption? Or is there some other way to change the button caption? Or can it be done at all?
: [b][red]This message was edited by AsmGuru62 at 2006-3-23 19:52:40[/red][/b][hr]
: [blue]Here is function list to work with menus. Basically, you need to get the menu handle and find the item by its text or command ID.
:
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus.asp
: [/blue]
:
:
you are right -- I thought he was talking about a button, not a menu item.
Sorry if I wasn't clear, and thanks for your help. And just to clarify, I mean an element in the top menu bar of the main window (File, View, Help, and my custom options). Do you have any advice on changing the caption on one the menu elements? For example, if I have an elemen with the caption "On" and I want to change it on-the-fly to "Off." Is there a way to do that?
: : [blue]Since menu element is not a button - it will not work for menu element. You need to use this one:
: :
:
: you are right -- I thought he was talking about a button, not a menu item.
:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus/menureference/menufunctions/modifymenu.asp[/blue]
HMENU hmenubar;
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
HWND hWnd = AfxGetMainWnd()->GetSafeHwnd();
hmenubar = GetMenu(hWnd);
mii.fMask = MIIM_STATE;
if (Start)
{ mii.fState = MFS_HILITE; } // hilite the "Start" button
else { mii.fState = MFS_UNHILITE; } // unhilite the "Start" button
SetMenuItemInfo(hmenubar, IDC_START, FALSE, &mii);
DrawMenuBar(hWnd);
: [blue]Did you try this:
:
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus/menureference/menufunctions/modifymenu.asp[/blue]
:
I formatted it a little - can't read non-spaced code... sorry.[/blue]
: [code]
: HWND hWnd = AfxGetMainWnd ()->GetSafeHwnd ();
: HMENU hmenubar = GetMenu (hWnd);
: MENUITEMINFO mii;
: mii.fMask = MIIM_STATE;
: mii.cbSize = sizeof (MENUITEMINFO);
: if (Start)
: {
: mii.fState = MFS_HILITE;
: }
: else
: {
: mii.fState = MFS_UNHILITE;
: }
: SetMenuItemInfo (hmenubar, IDC_START, FALSE, &mii);
: [red]ModifyMenu (hmenubar, IDC_START,
: MF_BYCOMMAND | MF_STRING, IDC_START, "NewItemText");[/red]
: DrawMenuBar (hWnd);
: [/code]
: [blue]Try this, please.
: I formatted it a little - can't read non-spaced code... sorry.[/blue]
: : [code]
: : HWND hWnd = AfxGetMainWnd ()->GetSafeHwnd ();
: : HMENU hmenubar = GetMenu (hWnd);
: : MENUITEMINFO mii;
:
: : mii.fMask = MIIM_STATE;
: : mii.cbSize = sizeof (MENUITEMINFO);
:
: : if (Start)
: : {
: : mii.fState = MFS_HILITE;
: : }
: : else
: : {
: : mii.fState = MFS_UNHILITE;
: : }
:
: : SetMenuItemInfo (hmenubar, IDC_START, FALSE, &mii);
:
: : [red]ModifyMenu (hmenubar, IDC_START,
: : MF_BYCOMMAND | MF_STRING, IDC_START, "NewItemText");[/red]
:
: : DrawMenuBar (hWnd);
: : [/code]
:
: