|
-
Jan 4th, 2001, 11:06 AM
#1
Thread Starter
Frenzied Member
Hi,
I'm trying to implement a very simple function using VC++ in response to a user hitting a command button on a dialog box.
Everytime the user hits the button, I want a counter to increment and popup a message box to inform the user how many times the button has been pressed.
I defined an int as iCnt and then in the code I have:
...
iCnt=1;
MessageBox(hDlg,iCnt,"Info",MB_OK);
//implement counter incrementer here..
...
When running the above code, I get the following error:
'MessageBoxA' cannot convert parameter 2 from int to const char * bla bla bla...
I'm assuming the message box wants a string rather than an int. Also, how would I increment the counter after MessageBox()?
Thanks,
Dan
-
Jan 4th, 2001, 11:34 AM
#2
Lively Member
Add this code to the Form class that MFC Appwizard created for you:
class Form
{
public:
private:
int NumHits;
}
//Constructor
void Form::Form()
{
NUmHits=1;
}
void Form::OnButton()
{
CString str=NumHits;
AfxMessageBox(str);
NumHits++;
}
If you drop a blond and a UNIX box out a window, which one lands first?
-
Jan 4th, 2001, 12:35 PM
#3
Thread Starter
Frenzied Member
Actually, I'm not using MFC but I think I can figure out how to implement your example into my code.. If I can't, I will post a reply..
Thanks,
Dan
-
Jan 4th, 2001, 01:54 PM
#4
Thread Starter
Frenzied Member
Is CString only available using MFC? In another post, I asked about converting an int to a string and the reply I got was:
char buf[40];
int iCnt;
int radix = 10;
itoa(iCnt,buf,radix);
That works fine, but seems a little much to just convert from an int to a string.. I tried the CString but it doesn't recognize it. How can I use CString without using MFC?
Thanks,
Dan
-
Jan 4th, 2001, 02:07 PM
#5
Frenzied Member
I think if you #include <string> (note no .h, it's the standard library not Microsoft's) you can use the String data type, which is basically the same as CString I think.
Using the basic data types char* and int, you would use the code you gave (more or less). In your code, all you would have to do is something like this:
Code:
char buf[40];
MessageBox(hDlg, itoa(iCnt, buf, 10), "Info", MB_OK);
The itoa() function puts the string value in buf, and also returns it as the function's return value.
Harry.
"From one thing, know ten thousand things."
-
Jan 4th, 2001, 03:12 PM
#6
Lively Member
If you drop a blond and a UNIX box out a window, which one lands first?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|