Error in getting Handle of editBox?
-
Hi All, In my project I want to get the string value set in text box. So I write following code as CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd()) { pOpenEdit->GetWindowText(buff,256); } In the above code I did not get handle of edit box. What is wrong in this code. Please send me solution if anybody have. Thanks Om
-
Hi All, In my project I want to get the string value set in text box. So I write following code as CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd()) { pOpenEdit->GetWindowText(buff,256); } In the above code I did not get handle of edit box. What is wrong in this code. Please send me solution if anybody have. Thanks Om
What happens if you run this code?
CWnd *pwnd=GetDlgItem(IDC_FOLDER_PATH);
pwnd->GetWindowText(buff,256);Or if you declare a variable for editbox
m_Edit.GetWindowText(buff,256);
or if you use of
WM_GETTEXT
message ? -
Hi All, In my project I want to get the string value set in text box. So I write following code as CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd()) { pOpenEdit->GetWindowText(buff,256); } In the above code I did not get handle of edit box. What is wrong in this code. Please send me solution if anybody have. Thanks Om
/* I'm not sure what your having trouble with. However, I am confused what your using the handle for? Do you realize that your trying to use a pointer before you've even checked that it is valid? */ void CTest712Dlg::ShowEditText() { if (::IsWindow(m_hWnd)) { CEdit* pOpenEdit=(CEdit*)GetDlgItem(IDC_FOLDER_PATH); if (pOpenEdit) { CString sText(""); pOpenEdit->GetWindowText(sText); TRACE("%s\n",sText); } } } void CTest712Dlg::OnButton1() { // TODO: Add your control notification handler code here ShowEditText(); }
-
Hi All, In my project I want to get the string value set in text box. So I write following code as CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd()) { pOpenEdit->GetWindowText(buff,256); } In the above code I did not get handle of edit box. What is wrong in this code. Please send me solution if anybody have. Thanks Om
Use ClassWizard (Ctrl+W) to associate a
CEdit
variable with theIDC_FOLDER_PATH
control. Then use itsGetWindowText()
method.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
What happens if you run this code?
CWnd *pwnd=GetDlgItem(IDC_FOLDER_PATH);
pwnd->GetWindowText(buff,256);Or if you declare a variable for editbox
m_Edit.GetWindowText(buff,256);
or if you use of
WM_GETTEXT
message ?When I run above code I get null handle. so the code on next line is not execute. I use same code in other function of same class for Setting string value to editbox,the code is executed in that function. So why i did not get the handle od edit box in above code. Plz reply me. OM
-
When I run above code I get null handle. so the code on next line is not execute. I use same code in other function of same class for Setting string value to editbox,the code is executed in that function. So why i did not get the handle od edit box in above code. Plz reply me. OM
Are you sure id of editbox is correct and what happens if you declare a variable for it did you can values of edit control.
-
Are you sure id of editbox is correct and what happens if you declare a variable for it did you can values of edit control.
Hi Hamid, ID of Edit box is correct, because by using same ID i get the pointer for setting value to the window. CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd() ) { if( strOpenPath != "" ) pOpenEdit->SetWindowText(strOpenPath); } This code is execute well but in following code i did not get the handle. CEdit *pOpenEdit = (CEdit *)GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd() ) { char buff[500]; pOpenEdit->GetWindowText(buff,256); strOpenLocation = buff; } In this code I did not get handle so it is not entered in if block. Let me know what is wrong in this code. Thanks in Advance Om
-
Hi Hamid, ID of Edit box is correct, because by using same ID i get the pointer for setting value to the window. CEdit *pOpenEdit = (CEdit *) GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd() ) { if( strOpenPath != "" ) pOpenEdit->SetWindowText(strOpenPath); } This code is execute well but in following code i did not get the handle. CEdit *pOpenEdit = (CEdit *)GetDlgItem(IDC_FOLDER_PATH); if( NULL != pOpenEdit->GetSafeHwnd() ) { char buff[500]; pOpenEdit->GetWindowText(buff,256); strOpenLocation = buff; } In this code I did not get handle so it is not entered in if block. Let me know what is wrong in this code. Thanks in Advance Om
I have a question why you didnt declare a variable for edit control instead handle to it?