-
February 5th, 2004, 10:07 AM
#1
Text from editbox
Hi, i'm having problems getting the text from an edit box. I have a splitter window with two windows. My editbox is on one window and i want to get the text from it and send it to my second window. I have tried the option below but it gives me an error when the program starts.
CWnd* pWnd = GetDlgItem(IDD_EDIT1);
CString Tester;
pWnd->GetWindowText(Tester);
I'm using Doc/view arc , and the Editbox does not belong to the view that is calling for the text, is there another way to do this. I also tried the selection below and it gave me a blank string.
GetDlgItemText(IDD_EDIT,Tester);
-
February 5th, 2004, 10:11 AM
#2
without more code it's hard to say, but if you get an error when the program starts, perhaps the window for the control doesn't exist yet. Test for pWnd != NULL before you use it.
-
February 5th, 2004, 10:19 AM
#3
I just tested for pWnd and it did return NULL, how do i go about fixing this.
-
February 5th, 2004, 10:21 AM
#4
The easiest way would probably be to simply define a DDX member variable for the control and use it...
-
February 5th, 2004, 10:28 AM
#5
Originally posted by pa2003
I just tested for pWnd and it did return NULL, how do i go about fixing this.
Again, without knowming more about your app, it's hard to say. What happens if you just say
CWnd* pWnd = GetDlgItem(IDD_EDIT1);
CString Tester;
if(pWnd != NULL)
pWnd->GetWindowText(Tester);
-
February 5th, 2004, 10:34 AM
#6
Originally posted by GCDEF
Again, without knowming more about your app, it's hard to say. What happens if you just say
Well, he already said that GetDlgItem() returned NULL... Most probably because he tried to access the control before it was created. A simple DDX CString member variable would do. But for some reason I never understood, a lot of people prefer using the complicated way with GetDlgItem() and GetWindowText()...
-
February 5th, 2004, 10:37 AM
#7
Well, if pWnd is NULL, your test would produce an empty string...
To OP: did you create CEdit ontrol? In the window that you are trying to get to it? With ID of IDD_EDIT1? Before you access it?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 5th, 2004, 10:49 AM
#8
how do i go about "DDX member variable for the control and use it"
when i tried the code below it skipped the last line so the program came up with a blank screen where my text was suppose to be.
CWnd* pWnd = GetDlgItem(IDD_EDIT1);
CString Tester;
if(pWnd != NULL)
pWnd->GetWindowText(Tester);
My problem is that its two different view and i can't seem to send the text to the second view.
-
February 5th, 2004, 10:53 AM
#9
Originally posted by pa2003
how do i go about "DDX member variable for the control and use it"
You create them using class wizard. Search MSDN for DDX, it's all explained there.
-
February 5th, 2004, 11:05 AM
#10
Originally posted by gstercken
Well, he already said that GetDlgItem() returned NULL... Most probably because he tried to access the control before it was created. A simple DDX CString member variable would do. But for some reason I never understood, a lot of people prefer using the complicated way with GetDlgItem() and GetWindowText()...
I know. I'm assuming, perhaps incorrectly, that since he said his app crashes at the beginning, subsequent calls to the same code would work once the windows were created. It's hard to tell without knowing more about what's going on.
-
February 5th, 2004, 11:58 AM
#11
I am thinking about doing this another way but i don't know if what am asking is possible. Is it possible to make a string work similar to some think like a static int; if i can have the string declared just once i can make a function that other functions can call, the problem am having when i try this is that each call resets the string. Is it posssible to do this, i just want to store the string some where then get it when its needed. I can get the text from inside its view, i just can get it to the second view, this might be able to do the trick if its possible.
Last edited by pa2003; February 5th, 2004 at 12:05 PM.
-
February 5th, 2004, 12:24 PM
#12
Originally posted by pa2003
Is it possible to make a string work similar to some think like a static int; if i can have the string declared just once i can make a function that other functions can call, the problem am having when i try this is that each call resets the string. Is it posssible to do this, i just want to store the string some where then get it when its needed. I can get the text from inside its view, i just can get it to the second view, this might be able to do the trick if its possible.
I don't see where static variables would come in... A CString member variable is all you need. More specifically, and as already said, a DDX member variable, to have the contents automatically transferred between your CString and the edit control. All you need to do is to access that member from outside the view, so I don't understand why you are still hesitating.
-
February 5th, 2004, 12:46 PM
#13
Can you give me an example using DDX, i read the msdn documents but i could not understand it.
If i have a CString Example, how do i go about saving it with DDX and then getting it back.
-
February 5th, 2004, 01:16 PM
#14
Maybe I misunderstood, but from what I read, I believe you are trying to obtain the text from one of the splitter windows (which contains the edit box) from the other splitter window. Is this correct?
In other words, is this code
Code:
CWnd* pWnd = GetDlgItem(IDD_EDIT1);
CString Tester;
pWnd->GetWindowText(Tester);
located in the "second window" and the control exists in the first window? If so, that won't work since window "B" won't have access to window "A"s controls.
If you're using doc/view architecture, you could obtain the text within Window A and store the text in the doc. Then call the document's UpdateAllViews and handle the OnUpdate in window B to read the new value.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
February 5th, 2004, 01:32 PM
#15
Krmed you are right that is what i want to do, gstercken
told me a way to do it is using DDX, thats what i'm trying now, i am having some problems but gstercken if you see any error with it let me know, the text is still null, here is my code.
in DOExchange:
CEdit* pEditBox = (CEdit*)GetDlgItem( IDD_EDIT1 );
pEditBox->GetWindowText(m_edit1);
CFormView:: DoDataExchange( pDX );
//{{AFX_DATA_MAP(CSearchView)
DDX_Text(pDX, IDD_EDIT1, m_edit1 );
//}}AFX_DATA_MAP
In myprogram:
m_edit1=Text4;
UpdateData(FALSE);
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
|