Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2020
  • Last Modified:

Change a button's caption in VC++ MFC?

How can I make a program that once a start button is clicked, the same button's caption
changes to stop. I need to work in VC++ MFC.
Thanks!
0
TMM
Asked:
TMM
1 Solution
 
keitha1Commented:
call the buttons SetWindowText member function.
0
 
Leo71Commented:
Can you tell me more aobut the button?

I didn't test it, but I would just try making an OnUpdate_ButtonName((CCmdUI* pCmdUI)) function with the Classwizard.
And than a simple
{
   pCmdUI->SetText (desired_text_string);
}

and in OnButton() you have somthing like
{
static bool  started =! started;  //or global with defined init state :)
if (started) strcpy(desired_text_string,"Stop");
else strcpy(desired_text_string,"Start");
}
with desired_text_string being a global.
Feel free to use CString instead of *char, if you want.

I don't bet it works (I only used it with menus, neverwith buttons), but it's worth a try if noone has a better solution.



Regards
Leo
0
 
Leo71Commented:
keithas approach seems a little bit less complicated ;-).
(As I only say: Only what's easy is good)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
gotenksCommented:
you can also go to the microsoft msdn to read about button controls

http://msdn.microsoft.com/library/?url=/library/en-us/shellcc/platform/commctls/indivcontrol.asp

basically, the method suggested by keithas, SetWindowText, should work well.
0
 
JoeisanerdCommented:
Use the following function

SetDlgItemText(hDlg, IDC_BUTTON1, "Stop");

hDlg is the Window Handle to the Dialog box, IDC_BUTTON1 is the id for the button control and "Stop" is the new text. You can also use GetDlgItemText to determine what is the current text on the button to see what action to take.

The details are below.

BOOL SetDlgItemText(
HWND hDlg,
int nIDDlgItem,
LPCTSTR lpString);

Microsoft MSDN article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/htm/_wcesdk_Win32_SetDlgItemText.asp

//Get Dialog Item Text
UINT GetDlgItemText(
HWND hDlg,
int nIDDlgItem,
LPTSTR lpString,
int nMaxCount);
0
 
Leo71Commented:
That's the reason I asked for more info on the button, because noone said, that the button is part of a dialog... ;-)
0
 
TMMAuthor Commented:
Ok. Thanks you too! :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now