SDI Application, sending a message

Posted on 2003-03-14
Medium Priority
Last Modified: 2013-11-20
I have an SDI application (I usually do dialog based) and I need to send messages between different classes.

This SDI application in particular is an explorer style class - with the explorer bar on the left. Now I *think* that I need messages to accomplish what I need.

If the user clicks in the left explorer pane then I need to display a different dialog on the right pane. Now apparently I can only switch views and such (I really have no idea) from the CMainForm class. However the click occurs in the LeftView class.

So I figured I would send a message from the LeftView class to the MainForm class. Is that thought correct? I just can't seem to comprehend the MFC SDI stuff - MFC in general :(

So anyway, I added the following code to the MainForm class:

// Header File

afx_msg LRESULT OnChangeView(WPARAM wParam, LPARAM lParam);

// In Cpp File

LRESULT CMainFrame::OnChangeView(WPARAM wParam, LPARAM lParam)

but it won't compile and frankly I have no idea if I did it even right. These are the errors I am getting:

error C2440: 'type cast' : cannot convert from 'unsigned int CMainFrame::*' to 'unsigned int *'
        There is no context in which this conversion is possible
error C2440: 'initializing' : cannot convert from 'void (__thiscall CCmdTarget::*)(void)' to 'unsigned int'
        Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast

Does anybody have any idea?

Thanks a lot ...
Question by:FlorianJaeger
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
  • 5

Author Comment

ID: 8140487
OK, I can compile it now. I originally had UINT UWM_CHG_VIEW_ES as a member of the MainForm class and that was apparently not good, I put it outside the class now and it compiles.

General thoughts are still welcome ...

Author Comment

ID: 8140723
Unfortunately the message that I send from the LeftView class never arrives in the MainFrame class.

I checked the value of the UINT UWM_CHG_VIEW_ES variable and it is the same in both classes after I call

UWM_CHG_VIEW_ES = ::RegisterWindowMessage( _T("UWM_CHG_VIEW_ES") );


HWND hWnd = reinterpret_cast<HWND>(m_hWnd);
::PostMessage(hWnd, UWM_CHG_VIEW_ES, 0, 0);

never seems to arrive in the function that handles the mesasage.

How can I troubleshoot messages??

Hopefully somebody will read this message even ...

Expert Comment

ID: 8141942
Instead of PostMessage try SendMessage since it is more direct..
Technology Partners: 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!


Author Comment

ID: 8143086
Unfortunately that doesn't work either, nothing happens.

Any other ideas?

Author Comment

ID: 8143235
I also just tried to debug with Spy++ looking at messages and I can't seemt to find the message in the list ... I find that very strange.

Accepted Solution

MrNoName earned 1000 total points
ID: 8143958
try this:

(in resource.h)
#define WM_CHGVIEW (WM_USER + 100)

(in CMainFrame.h)
afx_msg LRESULT OnChangeView(WPARAM wParam, LPARAM

(in CMainFrame.cpp)
In message map...

When you're ready to call it...
Get a pointer to your main frame:
CMainFrame *pFrame = (CMainFrame*) AfxGetMainWnd ();
pFrame->SendMessage (WM_CHGVIEW, 0, 0);


Author Comment

ID: 8146592
Thanks, after reading MSDN I actually did figure it out myself, I had no idea that both of them actually used different windows...

Featured Post

Industry Leaders: 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

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: 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…
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 we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

765 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