Click to See Complete Forum and Search --> : After putting dialog in child thread, GetDlgItm no longer works


koden
October 3rd, 2005, 06:20 PM
CButton *lpStart = (CButton*)GetDlgItem(IDC_STARTBUTTON);
CButton *lpExit = (CButton*)GetDlgItem(IDCANCEL);
CEdit *lpLog = (CEdit *)GetDlgItem(IDC_LOG);


The above used to work when it wasn't a thread. It gives the following errors now:

C:\...testDlg.cpp(239) : error C2352: 'CWnd::GetDlgItem' : illegal call of non-static member function
c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(1992) : see declaration of 'GetDlgItem'
C:\...testDlg.cpp(240) : error C2352: 'CWnd::GetDlgItem' : illegal call of non-static member function
c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(1992) : see declaration of 'GetDlgItem'
C:\...testDlg.cpp(241) : error C2352: 'CWnd::GetDlgItem' : illegal call of non-static member function
c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(1992) : see declaration of 'GetDlgItem'
Error executing cl.exe.


what do i do?

MikeAThon
October 3rd, 2005, 08:58 PM
These errors indicate that you are calling GetDlgItem from a statically-scoped worker thread function. You need to provide a pointer to the dialog class:
CDialog* pDialog;
//.. assign the value of pDialog somehow
CButton *lpStart = (CButton*)(pDialog->GetDlgItem(IDC_STARTBUTTON));
// .. etc.
You need to figure out how to get the pointer to the dialog.

Incidentally, it's almost always the wrong decision to put the UI in a separate thread. Generally speaking, most programs are architected such that the main thread runs the UI and owns all UI elements (windows, ontrols etc) and worker threads notify the main UI thread of important events and new data through use of PostMessage of a user-defined message (like WM_APP+1). See Joseph Newcomer's essay "Using Worker THreads" at http://www.flounder.com/workerthreads.htm

Mike

JohnCz
October 3rd, 2005, 10:14 PM
After putting dialog in child thread, GetDlgItm no longer works
what do i do?It would be good to define what do you mean "After putting dialog in child thread, GetDlgItm no longer works"

How dod you put dialog in the thread and what is a child thread?

Marc G
October 4th, 2005, 03:12 AM
[ moved thread ]