Get TextBox Value and display it to messagebox in MFC

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

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


zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
15.JPG
15.JPG (131.78 KiB) Viewed 890 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
16.JPG
16.JPG (139.98 KiB) Viewed 890 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:02 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
17.JPG
17.JPG (141.83 KiB) Viewed 887 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:02 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
18.JPG
18.JPG (127.3 KiB) Viewed 884 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:03 pm

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attachments
19.JPG
19.JPG (149.81 KiB) Viewed 885 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 Departure » Thu Jun 07, 2007 10:21 pm

I did everything you said to but i got errors :O(

Code: Select all
Compiling...
myappfirst.cpp
c:\myappfirst\myappfirstdlg.h(46) : error C2275: 'CString' : illegal use of this type as an expression
        c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
c:\myappfirst\myappfirstdlg.h(46) : error C2057: expected constant expression
c:\myappfirst\myappfirstdlg.h(46) : error C2501: 'Public' : missing storage-class or type specifiers
c:\myappfirst\myappfirstdlg.h(46) : error C2146: syntax error : missing ';' before identifier 'strTextBoxValue'
c:\myappfirst\myappfirstdlg.h(46) : error C2501: 'strTextBoxValue' : missing storage-class or type specifiers
myappfirstDlg.cpp
c:\myappfirst\myappfirstdlg.h(46) : error C2275: 'CString' : illegal use of this type as an expression
        c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
c:\myappfirst\myappfirstdlg.h(46) : error C2057: expected constant expression
c:\myappfirst\myappfirstdlg.h(46) : error C2501: 'Public' : missing storage-class or type specifiers
c:\myappfirst\myappfirstdlg.h(46) : error C2146: syntax error : missing ';' before identifier 'strTextBoxValue'
c:\myappfirst\myappfirstdlg.h(46) : error C2501: 'strTextBoxValue' : missing storage-class or type specifiers
C:\myappfirst\myappfirstDlg.cpp(177) : error C2065: 'strTextBoxValue' : undeclared identifier
Generating Code...
Error executing cl.exe.

myappfirst.exe - 11 error(s), 0 warning(s)



Edit://
Problem fixed, I had a Capital P in "public" instead of a lower case p.

Danmm no room for typos in MFC
Last edited by Departure on Thu Jun 07, 2007 10:24 pm, edited 1 time in total.
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 996
Joined: Thu Mar 17, 2005 11:26 am
Location: Australia

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

are you able to make it work like pic18 :wink:
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 Departure » Thu Jun 07, 2007 10:45 pm

yes after i changed the "P" in public to "p"
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 996
Joined: Thu Mar 17, 2005 11:26 am
Location: Australia

Postby BattleStar-Galactica » Thu Jun 07, 2007 11:26 pm

that is the way to get edit control value in MFC properly but try this one, this is the way too get edit control value in c++(WIN32)


char* strTextBoxVal;
HWND hTextBox = ::GetDlgItem(this->m_hWnd,IDC_EDIT1);
int lenght=::GetWindowTextLength(hTextBox);

strTextBoxVal = new char[lenght + 1]; //allocated memory
::SendMessage(hTextBox,WM_GETTEXT,(WPARAM)lenght + 1,(LPARAM)strTextBoxVal);
::MessageBox(NULL,strTextBoxVal,strTextBoxVal,MB_OK);
delete strTextBoxVal; //clean up memory, you have to it manually in c++
Last edited by BattleStar-Galactica on Thu Jun 07, 2007 11:30 pm, edited 1 time in total.
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 » Fri Jun 08, 2007 12:43 am

two other function to get edit control value


GetDlgItemInt and GetDlgItemText

read msdn to know how to use them or ask me :D
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 » Fri Jun 08, 2007 3:53 pm

should I continue this with an other method that will get the same result but I think a little bit confusing for vb6 programmer with that method I think I will wait.

what is that method is created a class derived from CEdit class.

lets me know if it's enough for you for now :D
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 Departure » Sat Jun 09, 2007 1:09 am

thanks nano, I will be playing around with it some more today :O)

great tutorial and I look forward to seeing more :O)
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 996
Joined: Thu Mar 17, 2005 11:26 am
Location: Australia

Get TextBox Value and display it to messagebox in MFC

Postby locohacker » Sat Jun 09, 2007 8:41 am

YOOOOOO, this is a super kick asz tutorial, damn I can finnaly learn c+++ god bless ya :)
User avatar
locohacker
Site Admin
Site Admin
 
Posts: 4361
Joined: Fri Dec 31, 2004 6:59 pm

Previous

Return to C++, C# And Others Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron