Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error in getting Handle of editBox?

Error in getting Handle of editBox?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Atul23
    wrote on last edited by
    #1

    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

    H B D 3 Replies Last reply
    0
    • A Atul23

      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

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      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 ?

      A 1 Reply Last reply
      0
      • A Atul23

        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

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        /* 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(); }

        1 Reply Last reply
        0
        • A Atul23

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Use ClassWizard (Ctrl+W) to associate a CEdit variable with the IDC_FOLDER_PATH control. Then use its GetWindowText() 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

          1 Reply Last reply
          0
          • H Hamid Taebi

            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 ?

            A Offline
            A Offline
            Atul23
            wrote on last edited by
            #5

            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

            H 1 Reply Last reply
            0
            • A Atul23

              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

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              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.

              A 1 Reply Last reply
              0
              • H Hamid Taebi

                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.

                A Offline
                A Offline
                Atul23
                wrote on last edited by
                #7

                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

                H 1 Reply Last reply
                0
                • A Atul23

                  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

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  I have a question why you didnt declare a variable for edit control instead handle to it?

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups