Advertisement

How to use UpdateData()

Started by September 08, 2000 01:39 AM
3 comments, last by Benjamin 24 years, 3 months ago
I just write a dialog app. I found that UpdateData(false) not work if I put it into while loop. The code like this: void CDialog::OnProcess() { while(bisProcess) { m_string = "some data"; UpdataData(false); } } m_string is a variable of an editbox control, but it show the result after the loop finished. How could I do to show the data?
Ben
You need to force window redraw inside your loop. Like this:
    HWND hEdit = ::GetDlgItem(m_hWnd, IDC_EDIT_CONTROL, FALSE);::InvalidateRect(hEdit, NULL);::UpdateWindow(hEdit);    

This is a plain Win32 way of doing it, MFC classes should have similar methods. Also, it''s likely that you don''t need a call to InvalidateRect() here if UpdateData(false) invalidates the edit''s window.
Advertisement
In MFC, there''s no need to ever invalidate anything in a dialog if you''re sticking with the framework.

When I want to change variable fields in the dialog, it usually goes like this:

    MyDialog::OnSomeAction (){  UpdateData (TRUE); // save all data to member variables  m_strAttachedToEditBox = "Modified...";  // ... etc, etc.  UpdateData (FALSE); // shows my changes in dialog}    


So it looks like you''re doing the right thing, though you might be erasing user data by not having the UpdateData (TRUE) (who knows, you might not have data). Are you sure you''ve connected your member variable to the appropriate control in your dialog? The actual function that updated the data is "DoDataExchange"--you might want to step through it and make sure things are happening correctly.
Are you using UpdateData(false) or UpdateData(FALSE)? From the looks of that code fragment, I would guess the former... The conversion from BOOL to bool works ok, but MSVC++ says not to try to convert from bool to BOOL. That could be your problem (aka false != FALSE).

--------------------


You are not a real programmer until you end all your sentences with semicolons;

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

First you should move up UpdataData(false); to before the while loop.
No need to reset this flag every loop pass.
Second you should add a UpdataData(TURE); after the while loop.

Why didn''t your version work?
It almost did. Problem was, the first time through the loop, you set your variable first. This updated the data. This was reflected on the screen. Then you turn off update data, so subsequent updates were not reflected. But you still managed to update once.
Fix like I suggested.

This topic is closed to new replies.

Advertisement