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. Edit Box from funtion

Edit Box from funtion

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
7 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.
  • W Offline
    W Offline
    W00dSt0ck
    wrote on last edited by
    #1

    Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified): int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR } So, the output from the function does not work. I know, I have to append something, but what?????

    A A D 3 Replies Last reply
    0
    • W W00dSt0ck

      Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified): int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR } So, the output from the function does not work. I know, I have to append something, but what?????

      A Offline
      A Offline
      Alpha Siera
      wrote on last edited by
      #2

      Try like this from function CEdit *edit; edit=(CEdit*)GetDlgItem(IDC_Output); edit->SetWindowText("From function()!!"); Regards Alpha

      W 1 Reply Last reply
      0
      • W W00dSt0ck

        Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified): int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR } So, the output from the function does not work. I know, I have to append something, but what?????

        A Offline
        A Offline
        Arsalan Malik
        wrote on last edited by
        #3

        There are two solutions to your problem: 1. Make function() a member of of your TestDlg class. or, 2. You need to pass handle of dialog window (HWND) to SetDlgItemText as first parameter, in function:

        SetDlgItemText(hWnd, IDC_Output, "From funtion()!!");

        You may pass this handle to function. This handle is member of TestDlg class with name m_hWnd. ARSALAN MALIK

        W 1 Reply Last reply
        0
        • A Alpha Siera

          Try like this from function CEdit *edit; edit=(CEdit*)GetDlgItem(IDC_Output); edit->SetWindowText("From function()!!"); Regards Alpha

          W Offline
          W Offline
          W00dSt0ck
          wrote on last edited by
          #4

          Doesnt work, GetDlgItem() asks for Window Hande (doesn't accept 1 Parameter)! How can I get this? WoodStock

          A 1 Reply Last reply
          0
          • W W00dSt0ck

            Doesnt work, GetDlgItem() asks for Window Hande (doesn't accept 1 Parameter)! How can I get this? WoodStock

            A Offline
            A Offline
            Alpha Siera
            wrote on last edited by
            #5

            Their are two versions of GetDlgItem. 1. The SDK version needs two param 2. The CWindow::GetDlgItem and CWnd::GetDlgItem needs 1 param. Are you getting some compiler errors ?. Regards Alpha

            1 Reply Last reply
            0
            • A Arsalan Malik

              There are two solutions to your problem: 1. Make function() a member of of your TestDlg class. or, 2. You need to pass handle of dialog window (HWND) to SetDlgItemText as first parameter, in function:

              SetDlgItemText(hWnd, IDC_Output, "From funtion()!!");

              You may pass this handle to function. This handle is member of TestDlg class with name m_hWnd. ARSALAN MALIK

              W Offline
              W Offline
              W00dSt0ck
              wrote on last edited by
              #6

              How can I make function() a member of my TestDlg class?????

              1 Reply Last reply
              0
              • W W00dSt0ck

                Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified): int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR } So, the output from the function does not work. I know, I have to append something, but what?????

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

                You've not shown what the error is. Although it's obvious in this example, it still doesn't hurt to be explicit. Change function() to:

                int TestDlg::function()
                {
                ...
                }

                and don't forget to add the prototype to the class. Don't use SetDlgItemText(). Use ClassWizard to create a control variable (CEdit in this case) and use the SetWindowText() method to change the text.


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                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