Get TextBox Value and display it to messagebox in MFC

Here you can talk about C++ And C# And Other languages programming.

Get TextBox Value and display it to messagebox in MFC

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:53 pm


well I'm not a good English speaker but I will try my best to show you how do that, just follow my images :)

1) when you open vc++ 6, it look like pic 1

2) click on new option from menu, it look like my pic 2

3) under project name type >>myFirstApp and click ok, after click ok, it look like pic 3

4) check the option Dialog based and click next, after click next, it look like pic 4

5) just click next, it look like pic5

6) just click next again, it look like pic6 and click on finish button

7) after click on finish button, it look like pic 7, just click on ok

8) after step 7, it look like pic8

9) drag a textbox and a button into the form, it look like pic9

our goal is when we click on button1 we get value of textbox and display it in a messagebox like vb6. to do that, follow step 10

10) double click on button1, it look like pic10 and just click ok, after click ok, it look like pic11

we need to declare a variable type string that can hold a textbox value, to do that follow step 11

11) click on FileView, it look like pic12

hmmm where can I declare my variable in global like in vb6, follow step 12 baby

12) in the file explorer, just in left, double click on myFirstAppDlg.h, it look like pic13

scroll down, after the DECLARE_MESSAGE_MAP(), enter the follow lines of code

public:
CString strTextBoxValue;

it look like pic14 if you do right

well now I have declared my variable name strTextBoxValue type CString and I want go to the event button click to write the code to put textbox value to this variable, where can I go?, follow step 13

13) in the file explorer, just in left, double click on myFirstAppDlg.ccp, it look like pic15

enter these lines of code in void CMyFirstAppDlg::OnButton1()

CWnd* TextBox1=GetDlgItem(IDC_EDIT1);
TextBox1->GetWindowText(strTextBoxValue);
::AfxMessageBox(strTextBoxValue);

if you're in the right way, it look like pic16. all the job is done now, we can test it now to see if it work. How Do I run myFirstApp, just look at pic17(Ctrl +F5 to run it), easy no? enter testing string in textbox and click on button1, the result is at pic18

if you look at this line >> CWnd* TextBox1=GetDlgItem(IDC_EDIT1);

where I found the IDC_EDIT1, it's the id associate with the textbox you added to the form(vb6), in MFC all the controls have a id to identify them like the name you name your control in vb6, MFC identify his controls with id only. well to see what is the id of your textbox or your button1, just double click on file resources.h, it look like pic19

and what is CWnd, if you want to know it, you have to read msdn from microsoft website
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:54 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
1.JPG
1.JPG (76.97 KiB) Viewed 5783 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:55 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
2.JPG
2.JPG (109.6 KiB) Viewed 5782 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:55 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
3.JPG
3.JPG (98.54 KiB) Viewed 5781 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:55 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
4.JPG
4.JPG (102.96 KiB) Viewed 5775 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:56 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
5.JPG
5.JPG (104.84 KiB) Viewed 5767 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:56 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
6.JPG
6.JPG (102.98 KiB) Viewed 5759 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:57 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
7.JPG
7.JPG (102.62 KiB) Viewed 5744 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:57 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
8.JPG
8.JPG (125.71 KiB) Viewed 5740 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:58 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
9.JPG
9.JPG (127.52 KiB) Viewed 5725 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:59 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
10.JPG
10.JPG (128.17 KiB) Viewed 5714 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 9:59 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
11.JPG
11.JPG (118.93 KiB) Viewed 5705 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 10:00 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
12.JPG
12.JPG (122.18 KiB) Viewed 5693 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 10:00 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
13.JPG
13.JPG (159.06 KiB) Viewed 5685 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Thu Jun 07, 2007 10:01 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
14.JPG
14.JPG (159.03 KiB) Viewed 5672 times
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Next

Return to C++, C# And Others Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron