dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: How to update Edit Box from a for loop

  1. #1
    Join Date
    Oct 2004
    Posts
    2

    Angry How to update Edit Box from a for loop

    I thought it'd be simple to update an edit item as followed within a loop. But it does work. Please help.

    CMyView::Calculate()
    {
    for (int i = 0; i < 100; i++)
    {
    . . . . .
    . . . . .
    // displaying the result in an edit box
    CString str;
    str.Format("%f", somevalue);
    SetDlgItemText(IDC_ED_RESULT, str); // HERE IS THE PROBLEM

    // other process
    . . . . . . .
    }

    }

    The edit item IDC_ED_RESULT will not display the "str " within the loop. When the loop is done, it'll display the last value. I need to display the result with the loop (it's a slow process inside loop )

    Any advices are greatly appreciated. Thanks in advance
    Newbie79

  2. #2
    Join Date
    Oct 2003
    Posts
    9

    Re: How to update Edit Box from a for loop

    It seems, you must create new thread for you loop:

    in your code WM_SETTEXT messages don't handled until your function
    returns

  3. #3
    Join Date
    Oct 2004
    Location
    Romania
    Posts
    45

    Re: How to update Edit Box from a for loop

    Code:
    SetDlgItemText(IDC_ED_RESULT, str);
    GetDlgItem(IDC_ED_RESULT)->RedrawWindow();
    Try T H I S

    Mick

  4. #4
    Join Date
    Oct 2004
    Posts
    2

    Thumbs up Thank you thank you thank you

    Now Mick showed me how to do it, it's so simple. I tried many routes but nothing worked. Thank you. You saved my sunday.
    Newbie79

  5. #5
    Join Date
    Oct 2004
    Location
    Romania
    Posts
    45

    Re: Thank you thank you thank you

    Quote Originally Posted by newbie79
    Now Mick showed me how to do it, it's so simple. I tried many routes but nothing worked. Thank you. You saved my sunday.
    Newbie79
    You are welcome.

    Have a nice weekend!
    Try T H I S

    Mick

  6. #6
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: Thank you thank you thank you

    Quote Originally Posted by newbie79
    Now Mick showed me how to do it, it's so simple.
    Note however that while in your loop, your app won't respond to user interactions. If you can live with that drawback , that approach could be acceptable. Note however, that a well-behaved Win32 app should always be responsive - for example, when a longer task is being performed, the user should have the possibility to interrupt or cancel the task. Furthermore, note that with your tight loop updating the edit control, you will have problems when another window covers and uncovers your window: The contents will not be redrawn correctly while your loop is being executed.

  7. #7
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: How to update Edit Box from a for loop

    The solution is to pump messages in your loop.
    Here's how to implement this:

    Code:
    for (int i = 0; i < 100; i++)
    {
    MSG msg;
    while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);  
    }
    // your code
    .......
    .......
    }
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)