Sign in to follow this  
Greycrow

Help with SetWindowText() function

Recommended Posts

Greycrow    122
All I need to do is this.. (MFC) void CRandomDlg::OnBnClickedRoll() { int number = 21; GetDlgItem(IDC_DIE1)->SetWindowText(number); } But of course my Visual C++ compiler won't let me .... seems I can't convert the number to anything this function would accept. any ideas?

Share this post


Link to post
Share on other sites
keen    122
SetWindowText takes a string as an argument.
To convert a number to a string either use

sprintf(str,"%i",number);

or

CString str;
str.Format("%i",number);

or

itoa(...)

There are many other ways to do this, Im just giving you a few pointers.

Good luck!
//keen

Share this post


Link to post
Share on other sites
Greycrow    122
Unfortunately using CString seems to leave me with the problem
of converting it (CString) to a wide char (Unicode)....

itoa() converts to a standard char[] and again ... same problem.

A wstring will work (using c_str()) but how do you convert and int to wstring?

kinda stuck here .......???

Share this post


Link to post
Share on other sites
keen    122
Hmm, I would recommend you to turn of unicode string since it will complicate things when you're learning and turn it on when you get a feel for the language.
You can do this in the project settings in visual studio (ALT-F7) under Character set.
To answer your question:
Anyways prefix "" with L so in the CString example do this:
CString str;
str.Format(L"%i",number);

itoa has an itow counterpart that operates on wchars.
sprintf -> swprintf

//kreca



Share this post


Link to post
Share on other sites
Greycrow    122
[quote]Original post by keen
Anyways prefix "" with L so in the CString example do this:
CString str;
str.Format(L"%i",number);

Love the "str.Format(L"%i",number);" idea that worked great :)

... so does turning off unicode still allow mw to program and
use MFC?? with just standard strings? .. that would be great..



Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Yes. Unless you need to deploy to a PC using a language that needs unicode.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this