Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SDI Application, sending a message

Posted on 2003-03-14
7
Medium Priority
?
406 Views
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
UINT UWM_CHG_VIEW_ES;

afx_msg LRESULT OnChangeView(WPARAM wParam, LPARAM lParam);

// In Cpp File
ON_REGISTERED_MESSAGE(UWM_CHG_VIEW_ES, OnChangeView)

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 ...
0
Comment
Question by:FlorianJaeger
  • 5
7 Comments
 

Author Comment

by:FlorianJaeger
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 ...
0
 

Author Comment

by:FlorianJaeger
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") );

but

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 ...
0
 

Expert Comment

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

 

Author Comment

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

Any other ideas?
0
 

Author Comment

by:FlorianJaeger
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.
0
 

Accepted Solution

by:
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
        lParam);

(in CMainFrame.cpp)
In message map...
   ON_MESSAGE (WM_CHGVIEW, OnChangeView)

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

0
 

Author Comment

by:FlorianJaeger
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...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

581 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