How to access UI controls from a user defined class (CFormView based SDI application)

 Answers from codeproject (cy163cy163)

GetActiveWindow() is thread-specific. You have no active windows in your worker thread.

Why not add a CHhhhView* member to your MyClass class (pass it in in the constructor):
 
class MyClass
{
CHhhhView *pView;
public:
MyClass(CHhhhView *view) {pView = view;}
};

void CHhhhView::OnButton1()
{
// TODO: Add your control notification handler code here
MyClass *objMyClass = new MyClass(this);
AfxBeginThread(MyThreadProc, objMyClass);
}

Now you can use pView in MyClass instead of ((CMDIFrameWnd*)AfxGetMainWnd()->GetActiveWindow()).

------------------------
Answer from codeguru (cy163)

The thread below answers your dilemma:
How to access UI elements from a thread in MFC?
http://www.codeguru.com/forum/showthread.php?t=312454
Jist is to pass the HWND of the window you need to update to the thread in some way and use the HWND ( and NOT CWnd object pointer )

posted on 2006-11-05 20:09  cy163  阅读(258)  评论(0编辑  收藏  举报

导航