Solved

Urgent multithreading question...

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 51
iSeries DB2 Query 2 97
Problem to open Excel file 15 174
how to use laptop or pad camera in vb.net windows application 2 85
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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