?
Solved

Urgent multithreading question...

Posted on 1998-12-21
3
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

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

Accepted Solution

by:
Tommy Hui earned 400 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

801 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