Solved

Problems with SendMessage

Posted on 1998-12-06
3
192 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 48
Best tools for Backup and restore of Wordpress site 6 55
fizzArray  challenge 1 64
isEverywhere  challenge 19 72
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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 video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

22 Experts available now in Live!

Get 1:1 Help Now