Re: Thread Communication in between UI and working thread

Tech-Archive recommends: Fix windows errors by optimizing your registry



See my essay on worker threads on my MVP Tips site. Note that you should, whenever
possible, avoid the use of CRITICAL_SECTION or Mutex between threads, that is, design so
they are not actually required because there is no concurrent access to data. Life
becomes simpler if you can avoid needing this level of synchronization.
joe

On Tue, 18 Mar 2008 10:33:58 +0800, asm23 <asmwarrior@xxxxxxxxx> wrote:

Hi, I'm using a SDI-based MFC application. and to create a working
thread, I add a static member function to CMainFrame. Then, I want to
know how does the working thread report some message to CMainFrame, like
a CString.

here is my method I want to use(pseudocode):

//-------------Class
class CMainFrame : public CFrameWnd
{
...
static DWORD WINAPI ThreadProc(void* pParameter);
}

//--------------Thread
DWORD CMainFrame::ThreadProc(void* pParameter){

CMainFrame* This = (CMainFrame*) pParameter;
...
CString * ptrString = new CString("xxxx") ;
...
This->PostMessage(WM_XXX, (unsigned int)ptrString, 0);
}

//----------------Message handler
afx_msg LRESULT CMainFrame::OnXXXX(WPARAM wParam, LPARAM lParam)
{
CString * ptr = (CString *)wParam;
......
return 0;
}

Note: This is the pointer to CMainFrame.

Is it a good method? Or, there are other better alternative. Since that
the Postmessage can only take two parameters, how can I pass a string or
a block of data. Are there any tutorials cover this topic? Thanks!
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: CPtrList with CSocket
    ... This means you don't need to declare ... Generally, you should avoid the ancient and, frankly, poorly-done, classes like CPtrList, ... By using two iteration mechanisms, one of which is inherently unrelated to the structure ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Set default printer for web
    ... realized that I probably should have posted it in ASP.Net to avoid the ... Alvin Bruney [MVP ASP.NET] ... The O.W.C. Black Book with .NET ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Load Registry in Unicode mode
    ... ALWAYS AVOID sprtinf, wsprintf, and other obsolete and dangerous library calls. ... This is usually a bad idea, do an asynchronous proces wait (see my essay on this on my MVP ... CloseHandle; ...
    (microsoft.public.vc.mfc)
  • Re: How to tell if a file exists
    ... but I avoid it when possible. ... implemented can / does occassionally leave it's single Api "find" ... elsewhere in the app. ... MVP - Visual Basic ...
    (microsoft.public.vb.general.discussion)