Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtGridWnd derived class& thread Collapse All
Subject Author Date
Massimo Germi Oct 5, 2005 - 4:00 AM

Hi,


 I have a little question about access to CExtGridWnd derived class in a thread.


My application is a MDI apps, the view is a derived class af CView. Inside a CMyView, I have a CMyGrid (derived from CExtGridWnd).


I’m trying to load data into CMyGrid from a thread in the following manner:


declaration of thread function


static unsigned __stdcall my_function(LPVOID *lpVoid);


 


unsigned __stdcall CMyView::my_function(LPVOID *lpVoid)


{


 


}


 

Technical Support Oct 5, 2005 - 8:18 AM

The MFC library has thread state data for each running thread. These data contain maps of handles to MFC objects such as a map from HWND handles to CWnd pointers. This means you can use any CWnd-derived class only in the thread where it was created. You cannot use this class in another thread because you will face assertion problems. The assertions are triggered because the CWnd pointer is controlled by the internal MFC map of other thread.

Here is what can be done. Define your WM_USER+??? messages and send them to the grid control from another thread. These messages should have pointers to non-MFC based data structures in message parameters. This is a valid way of interaction between a CWnd-based window and other thread. This approach is used in the CLogCtrl::WriteText() method of the MthOutput sample application. The CLogCtrl class implements a log output window which is based on the rich edit control. The CLogCtrl::WriteText() method invokes rich editor’s APIs if it is invoked from the same thread in which the log control was created. This method sends the WM_USR_WRITE_LOG_TEXT message that is defined as (WM_USER + 0x1234) to the rich editor’s thread if the method is invoked from another thread. The WM_USR_WRITE_LOG_TEXT message uses the CLogCtrl::_MthMessageDataFor_WM_USR_WRITE_LOG_TEXT data structure to pass all the needed information and invoke the CLogCtrl::WriteText() method in the rich editor’s native thread.

Massimo Germi Oct 6, 2005 - 9:19 AM

OK, I have implemented this method and its seems to be good.
TX