Solved

Problems with SendMessage

Posted on 1998-12-06
3
199 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
[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
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

710 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