Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problems with SendMessage

Posted on 1998-12-06
3
Medium Priority
?
202 Views
Last Modified: 2013-11-20
Hi!
 I use VC++5. My app is SDI. From the main thread (CWinApp), in the doc file,i create a new thread using a class derived from CWinThread giving in the constructor the handle to the doc view (derived from CEditView).
 The problem is, that in the new thread I try to post a message to the view of the doc using the PostMessage function and the handle to the view (HWND) as parameter --> there is not error, but the message doesn't reach the window queue.
 If I send a message to the AfxGetMainWnd()(so to the main window), its working. What's the problem?
0
Comment
Question by:visualc
3 Comments
 

Author Comment

by:visualc
ID: 1325797
Edited text of question
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1325798
Are you using SendMessage/PostMessage right for the view, to get the HWND you do

::PostMessage( pView->m_hWnd, ...etc...)
0
 
LVL 2

Accepted Solution

by:
prasanth earned 100 total points
ID: 1325799
The problem lies with passing the thread a handle to the doc view. CWnds are thread-specific - you can't pass them between threads. You can, however, pass the HWNDs between threads. So change your constructor from taking a CWnd (or a CEditView, or whatever) to taking a HWND. Then call the constructor with pView->GetSafeHwnd() as the parameter. Then you can SendMessage(m_docviewhwnd, ...) from your thread.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

971 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