Dialog box continuous update?
-
I want to continually update the data in the edit boxes on my dialog box with data that is generated in a loop. For example: for( i=0; i<100; i++) { m_X += 1; UpdateData(FALSE); } However, when I try this it loops through the for loop and doesn't display the values until it reaches the end of the loop. Thats when it displays 100. Any help would be appreciated. Thanks
-
I want to continually update the data in the edit boxes on my dialog box with data that is generated in a loop. For example: for( i=0; i<100; i++) { m_X += 1; UpdateData(FALSE); } However, when I try this it loops through the for loop and doesn't display the values until it reaches the end of the loop. Thats when it displays 100. Any help would be appreciated. Thanks
The problem is that the thread that executes your for loop is the same thread that draws the GUI of your app. In order to solve your problem you have to create a workerthread. That thread must have a way to comunicate with your gui. If your ussing MFC the safe way to do it is passing the HWND of the dialog box or the HWNDs of the controls you want to update and use SendMessage/PostMessage to update their contents. To create a worker thread ( a worker thread does not handle any UI events, it does not own a window ) you can call: CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ); pfnThreadProc - this is your thread function,it has the following proto: UINT MyControllingFunction( LPVOID pParam ); pParam - can be anything you want, and it is what you recive in pParam in MyControllingFunction (usualy in MFC a HWND) "I don't want to achieve immortality through my work... I want to achieve it through not dying." Woody Allen
-
The problem is that the thread that executes your for loop is the same thread that draws the GUI of your app. In order to solve your problem you have to create a workerthread. That thread must have a way to comunicate with your gui. If your ussing MFC the safe way to do it is passing the HWND of the dialog box or the HWNDs of the controls you want to update and use SendMessage/PostMessage to update their contents. To create a worker thread ( a worker thread does not handle any UI events, it does not own a window ) you can call: CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ); pfnThreadProc - this is your thread function,it has the following proto: UINT MyControllingFunction( LPVOID pParam ); pParam - can be anything you want, and it is what you recive in pParam in MyControllingFunction (usualy in MFC a HWND) "I don't want to achieve immortality through my work... I want to achieve it through not dying." Woody Allen
thank for the info.