|
-
December 30th, 2012, 03:45 AM
#9
Re: MDI "More Windows..." dialog
First, please let me try to clarify this, which seems to be a little bit confusing:
 Originally Posted by OneEyeMan
[...]
Is there a standard handler for this menu inside Windows? It looks like it as there is no such handler in simple MFC wizard generated code, but it's just MFC...
There is not any "standard handler" in Windows. A message handler is an application-defined function designed to "handle" (process) a message (doing something as a response to a message sent to a window).
For example, in a raw-WinAPI program we can have the following:
Code:
void OnTimer(HWND hWnd, UINT nIDEvent); // WM_TIMER message handler
// ...
// Window procedure. Processes all messages sent to a window
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_TIMER:
OnTimer(hWnd, (UINT)wParam);
break;
// ...
// ...
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//...
// WM_TIMER message handler. Processes WM_TIMER message.
void OnTimer(HWND hWnd, UINT nIDEvent)
{
// handle WM_TIMER message here.
}
OnTimer is a handler for WM_TIMER messages. I've called it "OnTimer" just to be asier for anybody to get what that function is doing, not because it is "standard". Someone else can call it "HumptyDumpty", as well. 
In MFC there is something similar, except that message handlers are class member functions and MFC Wizard makes our life easier, by "mapping" message handlers with the help of some macros:
Code:
class CMainFrame : public CMDIFrameWnd
{
// ...
afx_msg void OnTimer(UINT_PTR nIDEvent);
};
// ...
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_WM_TIMER()
END_MESSAGE_MAP()
// ...
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CMDIFrameWnd::OnTimer(nIDEvent);
}
Again, even here "OnTimer" isn't a "standard handler". If my muscles really want , I can, for example, manually map WM_TIMER as follows:
Code:
class CMainFrame : public CMDIFrameWnd
{
// ...
afx_msg LRESULT HumptyDumpty(WPARAM wParam, LPARAM lParam);
};
// ...
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_MESSAGE(WM_TIMER, HumptyDumpty)
END_MESSAGE_MAP()
// ...
LRESULT CMainFrame::HumptyDumpty(WPARAM wParam, LPARAM lParam)
{
UINT_PTR nIDEvent = (UINT_PTR)wParam;
// Handle WM_TIMER here.
return 0;
}
Or can override CWnd::WindowProc and map a handler function in a way more similar to that from raw-WinAPI example.
Of course, I'll never do something like that in practice, for an MFC application. It's just an example to demonstrate what I said in the top of this post.
[to be continued]
Last edited by ovidiucucu; December 30th, 2012 at 04:51 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|