Thread: How do I update an edit box?

  1. #1
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91

    How do I update an edit box?

    Well I set it:

    Code:
    SetDlgItemText(hwnd, IDC_TEXT, "I'm a textbox");
    But how do I change it's value?

  2. #2
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    What do you mean? Change what value?
    Code:
    void function(void)
     {
      function();
     }

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    The same way you set it the first time (if I understand your question correctly).
    Away.

  4. #4
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    What I meant was: After setting an edit box, how do I change it's value... Like I start an edit box with the value of "blue" how do I change it to "green"?

    Does your solution works for that?
    Last edited by lala123; 07-06-2005 at 07:05 PM.

  5. #5
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Quote Originally Posted by confuted
    The same way you set it the first time (if I understand your question correctly).
    Have you tried that? It works. I promise.
    Away.

  6. #6
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Well so why this dosen't work? It compiles and starts but the dialog dosen't show up...

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include "clock.h"
    
    SYSTEMTIME time;
    char strtime[20];
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
                while(1)
                {
                    GetLocalTime(&time);
                    sprintf(strtime, "%d:%d:%d", time.wHour, time.wMinute, time.wSecond);
    		SetDlgItemText(hwnd, IDC_TIME, strtime);
                }
    	break;
            case WM_COMMAND:
            break;
            case WM_CLOSE:
                 EndDialog(hwnd, 0);
            break;
    	default:
    	    return FALSE;
        }
        return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    }
    Last edited by lala123; 07-06-2005 at 08:34 PM.

  7. #7
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Since an EDIT box is a window wouldn't the UpdateWindow function work for your purpose? Or does UpdateWindow not affect EDIT windows in the way you want?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    UpdateWindow() bypasses the message que and sends the paint msg directly to the callback. Will not change the contents of the edit.

    WM_INITDIALOG is called before the DLG is displayed. So putting an infinite loop here will just cause problems (IMO).

    I would use a timer message. Create the timer in the init dlg msg with the required tiem interval and it will create a series of WM_TIMER msgs. In the WM_TIMER handler set the edits contents each time the timer msg arrives.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Yes. And that also leaves room for other messages to come in, meaning your window will be able to be updated, closed, etc. correctly.
    Code:
    void function(void)
     {
      function();
     }

  10. #10
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Could you please show me how I would send the WM_TIMER message? And I would handle it just as any other message like the WM_INITDIALOG?

  11. #11
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Look at SetTimer() (the timer will fire a msg until killed, not just once)

    in wm_initdlg create timer
    in wm_close kill timer
    in WM_TIMER set you edit each time (the time msg arrives)

    SetTimer()
    the HWND is that of the DLG
    the nIDEvent is a number you use to identify the timer (from other timers you create)
    elapse is the interval in millsecs (bast possible is about 15ms)
    set lpTimerFunc to NULL so the timer msg comes to your call back
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Thanks a lot for beeing so descriptive and helpfull But it still just flashes and close...

    Code:
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
         switch(Message)
        {
    	case WM_INITDIALOG:
                SetDlgItemText(hwnd, IDC_TIME, FALSE);
                SetTimer(hwnd, 1, 15, (TIMERPROC) NULL);
    	    break;
            case WM_TIMER:
                GetLocalTime(&time);
                sprintf(strtime, "%d:%d:%d", time.wHour, time.wMinute, time.wSecond);
    	    SetDlgItemText(hwnd, IDC_TIME, strtime);
            case WM_CLOSE:
                KillTimer(hwnd, 1);
                EndDialog(hwnd, 0);
            break;
    	default:
    	    return FALSE;
        }
        return TRUE;
    }
    Oh nevermind, I forgot a break; after the WM_TIMER message... It's working now
    Last edited by lala123; 07-07-2005 at 09:15 PM.

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Ahhh.....see you got it.

    Just slip the cheque into the modem......
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. edit box
    By beene in forum Windows Programming
    Replies: 3
    Last Post: 11-11-2006, 04:40 AM
  2. WS_HSCROLL in ES_READONLY edit box error
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 02-13-2006, 08:46 AM
  3. setting fixed floats in edit box
    By WaterNut in forum Windows Programming
    Replies: 4
    Last Post: 08-13-2004, 09:13 AM
  4. Update text box i a thread?
    By yoxler in forum Windows Programming
    Replies: 7
    Last Post: 01-05-2004, 01:13 PM
  5. Limiting Characters in Edit Box :: MFC
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 06-02-2002, 10:21 AM