Discussion:
user defined messages in form view
(too old to reply)
K
2003-10-14 04:14:22 UTC
Permalink
I am unable to receive user-defined messages in a formview-
based object. Here are the relevant pieces of code.

h file:
-------
//{{AFX_MSG(CMyView)
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg LRESULT OnMyButton(unsigned int iButtonID,
unsigned int iState);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

cpp file:
---------
BEGIN_MESSAGE_MAP(CMyView, CFormView)
//{{AFX_MSG_MAP(CMyView)
ON_MESSAGE(HM_BUTTON, OnButton)
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
...
END_MESSAGE_MAP()

HM_BUTTON is defined to be WM_APP+100

I use BroadcastSystemMessage to send this message from
another process.
This works fine if the receiver is not a form-view based
app. In the above case, I simply don't get the message.

TIA
Jeff Partch [MVP]
2003-10-14 06:05:51 UTC
Permalink
I've never used BroadcastSystemMessage, and I'm not sure why it's failing
for just CFormView, but I don't think you should broadcast WM_APP-based
messages at all. The WM_APP range is reserved for private messages used
within an application -- your app can assign one meaning to WM_APP+100, and
another app can use it to signal that it should format the hard drive
(although that meaning would be irresponsible too). FWIW, the prototype for
an ON_MESSAGE handler is LRESULT memberFxn(WPARAM, LPARAM).
--
Jeff Partch [VC++ MVP]
Post by K
I am unable to receive user-defined messages in a formview-
based object. Here are the relevant pieces of code.
-------
//{{AFX_MSG(CMyView)
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg LRESULT OnMyButton(unsigned int iButtonID,
unsigned int iState);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
---------
BEGIN_MESSAGE_MAP(CMyView, CFormView)
//{{AFX_MSG_MAP(CMyView)
ON_MESSAGE(HM_BUTTON, OnButton)
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
...
END_MESSAGE_MAP()
HM_BUTTON is defined to be WM_APP+100
I use BroadcastSystemMessage to send this message from
another process.
This works fine if the receiver is not a form-view based
app. In the above case, I simply don't get the message.
TIA
Scott McPhillips [MVP]
2003-10-14 12:43:35 UTC
Permalink
Post by K
I am unable to receive user-defined messages in a formview-
based object. Here are the relevant pieces of code.
-------
//{{AFX_MSG(CMyView)
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg LRESULT OnMyButton(unsigned int iButtonID,
unsigned int iState);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
---------
BEGIN_MESSAGE_MAP(CMyView, CFormView)
//{{AFX_MSG_MAP(CMyView)
ON_MESSAGE(HM_BUTTON, OnButton)
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
...
END_MESSAGE_MAP()
HM_BUTTON is defined to be WM_APP+100
I use BroadcastSystemMessage to send this message from
another process.
This works fine if the receiver is not a form-view based
app. In the above case, I simply don't get the message.
TIA
It is likely that the message is sent only to top-level windows. You
can check by using the Spy tool. If this is the case the message would
go only to CMainFrame, and MFC does not route user-defined messages from
mainframe to app/doc/views.

As Jeff said, this broadcast is a rather nasty thing to do because it
can affect other programs in unpredictible ways. It would be much
better to post the message to your CMainFrame HWND. If you give
CMainFrame a unique winclass name then other applications can find it by
calling FindWindow. See AfxRegisterWndClass to create the winclass name
and the cs.lpszClass member in PreCreateWindow to assign the name to
your CMainFrame.
--
Scott McPhillips [VC++ MVP]
Ed Dore[MSFT]
2003-10-15 22:45:29 UTC
Permalink
Scott's correct. Broadcast messages are only sent to top level windows on
the desktop. Child windows, like your formview will not get this message.
Your mainframe window will, and you should be able to intercept it with a
message handler on your mainframe class. But as both Jeff and Scott
correctly point out, it's a pretty ugly thing to do. If you absolutely
positively have to broadcast a message, I recommand you use
RegisterWindowMessage to create a unique message identifier, and use the
ON_REGISTERED_MESSAGE macro in your mainframe's message map to handle it.

Sincerely,
Ed Dore [MSFT]

This post is "AS IS" with no warranties, and confers no rights.
Ajay Kalra
2003-10-16 05:48:01 UTC
Permalink
Its sent to Top level window but shouldnt it get routed on to the view using MFC's default
command routing mechanism? I havent had a chance to look at MFC source yet.
--
Ajay Kalra [MVP - VC++]
***@yahoo.com


""Ed Dore[MSFT]"" <***@microsoft.com> wrote in message news:***@cpmsftngxa06.phx.gbl...
| Scott's correct. Broadcast messages are only sent to top level windows on
| the desktop. Child windows, like your formview will not get this message.
| Your mainframe window will, and you should be able to intercept it with a
| message handler on your mainframe class. But as both Jeff and Scott
| correctly point out, it's a pretty ugly thing to do. If you absolutely
| positively have to broadcast a message, I recommand you use
| RegisterWindowMessage to create a unique message identifier, and use the
| ON_REGISTERED_MESSAGE macro in your mainframe's message map to handle it.
|
| Sincerely,
| Ed Dore [MSFT]
|
| This post is "AS IS" with no warranties, and confers no rights.
|
Jeff Partch [MVP]
2003-10-16 13:23:57 UTC
Permalink
Ajay,

No, I think the framework only routes WM_COMMAND (and maybe those special
CN_xxx variants that MFC uses).
--
Jeff Partch [VC++ MVP]
Post by Ajay Kalra
Its sent to Top level window but shouldnt it get routed on to the view using MFC's default
command routing mechanism? I havent had a chance to look at MFC source yet.
--
Ajay Kalra [MVP - VC++]
| Scott's correct. Broadcast messages are only sent to top level windows on
| the desktop. Child windows, like your formview will not get this message.
| Your mainframe window will, and you should be able to intercept it with a
| message handler on your mainframe class. But as both Jeff and Scott
| correctly point out, it's a pretty ugly thing to do. If you absolutely
| positively have to broadcast a message, I recommand you use
| RegisterWindowMessage to create a unique message identifier, and use the
| ON_REGISTERED_MESSAGE macro in your mainframe's message map to handle it.
|
| Sincerely,
| Ed Dore [MSFT]
|
| This post is "AS IS" with no warranties, and confers no rights.
|
Continue reading on narkive:
Loading...