Solved

Urgent multithreading question...

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

707 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

15 Experts available now in Live!

Get 1:1 Help Now