Solved

Urgent multithreading question...

Posted on 1998-12-21
3
236 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…

690 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