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. problem with setwindowtext()

problem with setwindowtext()

Scheduled Pinned Locked Moved C / C++ / MFC
help
9 Posts 3 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.
  • S Offline
    S Offline
    swatgodjr
    wrote on last edited by
    #1

    hi, i am writing a program that stores data into a text file i specify in the form of a class object. when i initialize the window where i can edit this data, i have a combo box that reads the file and inserts part of the object(the name of each class object) into the combo box. than i select the name and when i hit the button to edit the data for that particular object i am trying to have my program insert each part of the class into its own text box but when i try to do this my program completely crashes without any information as to why. i tried to push the values of the variables into a buffer and than use setwindowtext but it would still crash which i have done else where in my program without any bit of trouble.

    H 1 Reply Last reply
    0
    • S swatgodjr

      hi, i am writing a program that stores data into a text file i specify in the form of a class object. when i initialize the window where i can edit this data, i have a combo box that reads the file and inserts part of the object(the name of each class object) into the combo box. than i select the name and when i hit the button to edit the data for that particular object i am trying to have my program insert each part of the class into its own text box but when i try to do this my program completely crashes without any information as to why. i tried to push the values of the variables into a buffer and than use setwindowtext but it would still crash which i have done else where in my program without any bit of trouble.

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

      Can you show your code that has error_**


      **_

      whitesky


      S 1 Reply Last reply
      0
      • H Hamid Taebi

        Can you show your code that has error_**


        **_

        whitesky


        S Offline
        S Offline
        swatgodjr
        wrote on last edited by
        #3

        sure not a problem, i will post the whole function, hope that will be enough to help solve the issue. afx_msg void CEditDialog::OnEdit() { elements s; int size = sizeof(elements); bool found = false; //MessageBox(" This Area is Still under Construction", "Debug", MB_ICONINFORMATION); CComboBox *pSelection; pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION); CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); CEdit *pSymbolText; pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL); CEdit *pAtomicText; pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC); CEdit *pPeriodText; pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD); CEdit *pGroupText; pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP); CEdit *pElectronText; pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON); int iCurSel = pSelection->GetCurSel(); if(iCurSel == CB_ERR) { MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING); return; } char lpszText[32]; pSelection->GetLBText(iCurSel, lpszText); access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); do{ access.Read(reinterpret_cast< char * > (&s), sizeof(elements)); MessageBox(lpszText, "debug", MB_ICONINFORMATION); if(strcmp(s.element, lpszText) == 0) { access.Seek(-(long)size, CFile::current); MessageBox("Found", "debug", MB_ICONINFORMATION); found = true; pNameText->SetWindowText("test"); } }while(found != true); access.Close(); } all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code).

        Steve EcholsS H 2 Replies Last reply
        0
        • S swatgodjr

          sure not a problem, i will post the whole function, hope that will be enough to help solve the issue. afx_msg void CEditDialog::OnEdit() { elements s; int size = sizeof(elements); bool found = false; //MessageBox(" This Area is Still under Construction", "Debug", MB_ICONINFORMATION); CComboBox *pSelection; pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION); CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); CEdit *pSymbolText; pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL); CEdit *pAtomicText; pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC); CEdit *pPeriodText; pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD); CEdit *pGroupText; pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP); CEdit *pElectronText; pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON); int iCurSel = pSelection->GetCurSel(); if(iCurSel == CB_ERR) { MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING); return; } char lpszText[32]; pSelection->GetLBText(iCurSel, lpszText); access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); do{ access.Read(reinterpret_cast< char * > (&s), sizeof(elements)); MessageBox(lpszText, "debug", MB_ICONINFORMATION); if(strcmp(s.element, lpszText) == 0) { access.Seek(-(long)size, CFile::current); MessageBox("Found", "debug", MB_ICONINFORMATION); found = true; pNameText->SetWindowText("test"); } }while(found != true); access.Close(); } all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code).

          Steve EcholsS Offline
          Steve EcholsS Offline
          Steve Echols
          wrote on last edited by
          #4

          You might try putting a breakpoint on this line and see if pNameText is NULL (which it probably is): CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); GetDlgItem will return NULL if it can't find the control with the specified ID. The symbol might exist in your resource file, so no compile time error, but check the specific control in the resource editor and make sure it is assigned an ID of IDC_ENAME.


          - S 50 cups of coffee and you know it's on!

          • S
            50 cups of coffee and you know it's on!
            Code, follow, or get out of the way.
          H 1 Reply Last reply
          0
          • S swatgodjr

            sure not a problem, i will post the whole function, hope that will be enough to help solve the issue. afx_msg void CEditDialog::OnEdit() { elements s; int size = sizeof(elements); bool found = false; //MessageBox(" This Area is Still under Construction", "Debug", MB_ICONINFORMATION); CComboBox *pSelection; pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION); CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); CEdit *pSymbolText; pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL); CEdit *pAtomicText; pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC); CEdit *pPeriodText; pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD); CEdit *pGroupText; pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP); CEdit *pElectronText; pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON); int iCurSel = pSelection->GetCurSel(); if(iCurSel == CB_ERR) { MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING); return; } char lpszText[32]; pSelection->GetLBText(iCurSel, lpszText); access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); do{ access.Read(reinterpret_cast< char * > (&s), sizeof(elements)); MessageBox(lpszText, "debug", MB_ICONINFORMATION); if(strcmp(s.element, lpszText) == 0) { access.Seek(-(long)size, CFile::current); MessageBox("Found", "debug", MB_ICONINFORMATION); found = true; pNameText->SetWindowText("test"); } }while(found != true); access.Close(); } all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code).

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

            you said this code has problem CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); pNameText->SetWindowText("test"); Do you have IDC_ENAME in your program and is this CEdit_**


            **_

            whitesky


            S 1 Reply Last reply
            0
            • Steve EcholsS Steve Echols

              You might try putting a breakpoint on this line and see if pNameText is NULL (which it probably is): CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); GetDlgItem will return NULL if it can't find the control with the specified ID. The symbol might exist in your resource file, so no compile time error, but check the specific control in the resource editor and make sure it is assigned an ID of IDC_ENAME.


              - S 50 cups of coffee and you know it's on!

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

              or maybe i guess IDC_ENAME isnt CEdit_**


              **_

              whitesky


              Steve EcholsS 1 Reply Last reply
              0
              • H Hamid Taebi

                you said this code has problem CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); pNameText->SetWindowText("test"); Do you have IDC_ENAME in your program and is this CEdit_**


                **_

                whitesky


                S Offline
                S Offline
                swatgodjr
                wrote on last edited by
                #7

                you know...i went back to check the ids and names of controls as you said to do...noticed that some how the names of controls in another window were being used in that window so i changed them to what they needed to be and well it works fine, now to see if i can get it to do what i need(which should be no problem at all.) thank you so much :).

                1 Reply Last reply
                0
                • H Hamid Taebi

                  or maybe i guess IDC_ENAME isnt CEdit_**


                  **_

                  whitesky


                  Steve EcholsS Offline
                  Steve EcholsS Offline
                  Steve Echols
                  wrote on last edited by
                  #8

                  That's possible, although every CWnd derived object supports SetWindowText, so my best guess is GetDlgItem is returning null.


                  - S 50 cups of coffee and you know it's on!

                  • S
                    50 cups of coffee and you know it's on!
                    Code, follow, or get out of the way.
                  H 1 Reply Last reply
                  0
                  • Steve EcholsS Steve Echols

                    That's possible, although every CWnd derived object supports SetWindowText, so my best guess is GetDlgItem is returning null.


                    - S 50 cups of coffee and you know it's on!

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

                    you right(of course in this thread it seems that my guess is ture)and i think he find problem.:)and i agree with GetDlgItem is returning null_**


                    **_

                    whitesky


                    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