From: VB on 28 Apr 2010 05:57 Hi if two users are working simultaneously in a same form,How to refresh the data automatically which was added by the other user. I herad that through windows API 'Postmessage' and 'registerdwindowmessgae' we can handle this. Please give some examples runcyclexcsk wrote: Scott - many thanks, I will give it a try! 07-Jul-07 Scott - many thanks, I will give it a try! Previous Posts In This Thread: On Wednesday, July 04, 2007 4:03 PM runcyclexcsk wrote: passing "parent" ID to a new thread Hi all, secondary window and to communicate with the main window by PostMessage. pNewThread = (CNewThread*)AfxBeginThread(RUNTIME_CLASS(CNewThread),0); I need to pass the ID of the main window to the new thread when I create the new thread, to be able to PostMessage to the main window later. How do I pass the main widnow ID to the new thread? I understand that there is no parent-child reglationship between threads. On Wednesday, July 04, 2007 4:21 PM Doug Harrison [MVP] wrote: Re: passing "parent" ID to a new thread On Wed, 04 Jul 2007 13:03:41 -0700, runcyclexcski(a)yahoo.com wrote: If there were such a relationship, it wouldn't be between a window and a thread; it would be between the threads. For a number of reasons, it is usually better for one thread to create all the windows; this thread is called the "main UI thread" among other things. That said, to pass information into a thread when you create it, use the second AfxBeginThread parameter for which you're currently passing 0. If it's pointer-sized or smaller, you can just cast it to LPVOID when you call AfxBeginThread and back to the original type in the thread entry function; it's common to do this with the "this" pointer of a member function. If you need to pass a lot of information and can't do it with "this", create a new class or struct, dynamically create an instance with new, and pass a pointer to it as the thread parameter. The created thread then assumes ownership of the object and must delete it when done with it. This hand-off protocol avoids lifetime issues, and you may need to use it when you PostMessage between threads. Finally, for some info on safely using AfxBeginThread, see: http://members.cox.net/doug_web/threads.htm -- Doug Harrison Visual C++ MVP On Wednesday, July 04, 2007 4:30 PM runcyclexcsk wrote: Doug,Thanks a bunch, it hepled a lot. Doug, Thanks a bunch, it hepled a lot. On Wednesday, July 04, 2007 10:05 PM Ben Voigt [C++ MVP] wrote: Re: passing "parent" ID to a new thread If there is only one "main window", then a global variable will work perfectly fine. On Wednesday, July 04, 2007 10:50 PM runcyclexcsk wrote: I know, this is how I've been doing it so far, but I am drowning inglobals by I know, this is how I have been doing it so far, but I am drowning in globals by now... too many of them. I am trying to make it cleaner. On Wednesday, July 04, 2007 11:13 PM Ben Voigt [C++ MVP] wrote: Re: passing "parent" ID to a new thread static member variable... to keep things organized But it still acts like a global. On Thursday, July 05, 2007 12:27 AM Scott Seligman [MSFT] wrote: Re: passing "parent" ID to a new thread Why not pass it in as the pParam of AfxBeginThread()? -- Scott Seligman [MSFT] This posting is provided AS IS with no warranties, and confers no rights. On Friday, July 06, 2007 12:34 AM runcyclexcsk wrote: Yeah, I am trying to figure it out, but I am confused about converting"this" Yeah, I am trying to figure it out, but I am confused about converting "this" (which is a pointer to a CDialog class) to LPVOID. If I just do AfxBeginThread(RUNTIME_CLASS(Fluoro_532_thread), this) ....it does not work, and casting "this" to (void *) does not work either. On Friday, July 06, 2007 12:50 AM runcyclexcsk wrote: AfxBeginThread with RUNTIME_CLASS(thread) as the first parametercreates a user AfxBeginThread with RUNTIME_CLASS(thread) as the first parameter creates a user interface thread. "LPVOID pParameter" is not among parameters of an interface thread overloading. On Friday, July 06, 2007 7:33 AM Scott McPhillips [MVP] wrote: Re: passing "parent" ID to a new thread runcyclexcski(a)yahoo.com wrote: Here is a two-step way to pass parameters to a UI thread: pThread = (CMyThread *)AfxBeginThread( RUNTIME_CLASS(CMyThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_hModalWait = CreateEvent(NULL, FALSE, FALSE, NULL); pThread->m_bAutoDelete = FALSE; pThread->ResumeThread(); -- Scott McPhillips [MVP VC++] On Saturday, July 07, 2007 5:13 PM runcyclexcsk wrote: Scott - many thanks, I will give it a try! Scott - many thanks, I will give it a try! Submitted via EggHeadCafe - Software Developer Portal of Choice A Framework to Animate WPF and Silverlight Pages Similar to the PowerPoint Slides http://www.eggheadcafe.com/tutorials/aspnet/7390a840-dd39-4c35-9940-c7354940d878/a-framework-to-animate-wp.aspx
From: Brian Muth on 28 Apr 2010 13:04 You have posted in a C++ newsgroup. Try one of the microsoft.public.vb.* newsgroups.
|
Pages: 1 Prev: CString::Replace corrupts unicode strings Next: [ANN] CodeSynthesis XSD 3.3.0 released |