Solved

Urgent multithreading question...

Posted on 1998-12-21
3
199 Views
Last Modified: 2013-11-20
I have a program that uses a richeditview/richeditdoc.  I have a toolbar that has buttons on it that will allow the user to start/stop parsing through text in the richeditview.  Unfortunately, I have a while loop that processes the text, and the UI is frozen while the 'run' button is pressed, which means it's impossible to press the 'stop' button.  I thought an ideal solution to this problem would be to start up a worker thread.  I coded another worker thread in, which works in the sense that I can have the second thread pop up message boxes, but the problem is this: I understand it's a no-no to share MFC objecst between threads.  Is there some safe way to pass a worker thread a RichEditCtrl Object?  In other words, I want to have something like the following:
CRichEditCtrl& theCtrl = GetRichEditCtrl();
and then pass 'theCtrl' to the worker thread, so it can do things with the contents of the RichEdit buffer.  Any help is much appreciated.

thanks,
-Matt
0
Comment
Question by:smit9
  • 2
3 Comments
 

Author Comment

by:smit9
ID: 1326560
Edited text of question
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1326561
You're right, it is a no-no to pass CObjects between threads. But you can pass HWNDs between threads.

So the idea is to get the HWND of the rich edit control and pass that as a parameter to the thread. Then the thread uses

  CWnd::FromHandle();

to retrieve the CWnd*. From this pointer, cast it to a CRichEditCtrl. Note that this only works if all the member functions of CRichEditCtrl translates to a SendMessage call, which they are. This technique does not work for every CWnd object so be careful.
0
 

Author Comment

by:smit9
ID: 1326562
This is the answer I was hoping to see.  I guess my question then would be how do I retrieve the handle to the richeditcontrol?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now