C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Changing the text in a menu button from within a program? Posted by katman on 20 Mar 2006 at 2:26 PM
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?

Report
Re: Changing the text in a menu button from within a program? Posted by stober on 20 Mar 2006 at 5:18 PM
: 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().
Report
Re: Changing the text in a menu button from within a program? Posted by katman on 21 Mar 2006 at 10:08 AM
Thanks! That led me to what I needed. It would speed up my understanding if you could offer an example of how this would work for a menu element (e.g., button) or point me to an example.

: : 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().
:

Report
Re: Changing the text in a menu button from within a program? Posted by stober on 21 Mar 2006 at 6:50 PM
: Thanks! That led me to what I needed. It would speed up my understanding if you could offer an example of how this would work for a menu element (e.g., button) or point me to an example.
:
: : : 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.
SetWindowText(m_hWnd,"Some Text");

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowtext.asp

Report
Re: Changing the text in a menu button from within a program? Posted by AsmGuru62 on 22 Mar 2006 at 5:20 AM
Report
Re: Changing the text in a menu button from within a program? Posted by katman on 23 Mar 2006 at 9:52 AM
Thanks, that helps a lot. I'll have to play with it some. At this point it isn't clear to me how I choose a particular button out of several that are on the menu.

: :
: : SetWindowText(m_hWnd,"Some Text");
: : 

: : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowtext.asp
: :
: :
: 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

:

Report
Re: Changing the text in a menu button from within a program? Posted by AsmGuru62 on 23 Mar 2006 at 7:50 PM
This message was edited by AsmGuru62 at 2006-3-23 19:52:40

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

Report
Re: Changing the text in a menu button from within a program? Posted by katman on 11 Apr 2006 at 3:14 PM
This message was edited by katman at 2006-4-11 15:21:8

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?

: This message was edited by AsmGuru62 at 2006-3-23 19:52:40

: 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
:

:


Report
Re: Changing the text in a menu button from within a program? Posted by stober on 11 Apr 2006 at 8:31 PM
: 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.
Report
Re: Changing the text in a menu button from within a program? Posted by katman on 12 Apr 2006 at 8:43 AM
This message was edited by katman at 2006-4-12 8:44:54

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?

: : 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.
:



Report
Re: Changing the text in a menu button from within a program? Posted by katman on 13 Apr 2006 at 10:07 AM
Yes, that was a very helpful link. Except instead of ModifyMenu I used the newer SetMenuItemInfo function. Below is the code I used for the hilite/unhilite of a menu item with the caption "Start". This code works and goes a long way toward what I'm after. But how do I change the caption itself? I tried MF_STRING but couldn't get it to work. I may be close, but I'm stuck again. Thanks for your continued help and patience.

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);

: Did you try this:
:
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/menus/menureference/menufunctions/modifymenu.asp

:

Report
Re: Changing the text in a menu button from within a program? Posted by AsmGuru62 on 14 Apr 2006 at 4:39 AM
Try this, please.
I formatted it a little - can't read non-spaced code... sorry.

:
: 	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);

: 	ModifyMenu (hmenubar, IDC_START,
: 		MF_BYCOMMAND | MF_STRING, IDC_START, "NewItemText");

: 	DrawMenuBar (hWnd);
: 


Report
Re: Changing the text in a menu button from within a program? Posted by katman on 17 Apr 2006 at 2:35 PM
That works perfectly! Thanks!

: Try this, please.
: I formatted it a little - can't read non-spaced code... sorry.

: :
: : 	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);
: 
: : 	ModifyMenu (hmenubar, IDC_START,
: : 		MF_BYCOMMAND | MF_STRING, IDC_START, "NewItemText");
: 
: : 	DrawMenuBar (hWnd);
: : 

:
:



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.