Handling sysmenu new item event
-
Hello all, I have a class CChildFrame : public CMDIChildWnd : public CFrameWnd i have declared a new item in sysMenu called "Map Info"
CMenu \*pSysMenu = pFrm->GetSystemMenu(FALSE); ASSERT(pSysMenu != NULL); pSysMenu->AppendMenu(MF\_STRING, IDI\_SYS\_MENU\_MAP\_INFO, \_T("&Map Info"));
how do i handle the event of clicking that new item in the sysmenu ?? i have looked for something like it on the web but all i found is talking about CDialog and the WM_ON_SYSCOMMAND which doesn't seem to work for me. anyone ? Thank's Eyal
-
Hello all, I have a class CChildFrame : public CMDIChildWnd : public CFrameWnd i have declared a new item in sysMenu called "Map Info"
CMenu \*pSysMenu = pFrm->GetSystemMenu(FALSE); ASSERT(pSysMenu != NULL); pSysMenu->AppendMenu(MF\_STRING, IDI\_SYS\_MENU\_MAP\_INFO, \_T("&Map Info"));
how do i handle the event of clicking that new item in the sysmenu ?? i have looked for something like it on the web but all i found is talking about CDialog and the WM_ON_SYSCOMMAND which doesn't seem to work for me. anyone ? Thank's Eyal
Create a dialog based application and see how the
About
menu is added and handled. It is indeed theON_WM_SYSCOMMAND
macro and theOnSysCommand
method.«_Superman_»
I love work. It gives me something to do between weekends. -
Create a dialog based application and see how the
About
menu is added and handled. It is indeed theON_WM_SYSCOMMAND
macro and theOnSysCommand
method.«_Superman_»
I love work. It gives me something to do between weekends. -
I just tried it and it works perfectly. I added the menu from within my frame class. Added the following in
OnCreate
-CMenu *pSysMenu = GetSystemMenu(FALSE);
ASSERT(pSysMenu != NULL);
pSysMenu->AppendMenu(MF_STRING, 10101, _T("&About ..."));Added
ON_WM_SYSCOMMAND()
in between the message map macros. Added the following method -void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if (nID == 10101)
MessageBox(L"About me");CFrameWnd::OnSysCommand(nID, lParam);
}
«_Superman_»
I love work. It gives me something to do between weekends. -
I just tried it and it works perfectly. I added the menu from within my frame class. Added the following in
OnCreate
-CMenu *pSysMenu = GetSystemMenu(FALSE);
ASSERT(pSysMenu != NULL);
pSysMenu->AppendMenu(MF_STRING, 10101, _T("&About ..."));Added
ON_WM_SYSCOMMAND()
in between the message map macros. Added the following method -void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if (nID == 10101)
MessageBox(L"About me");CFrameWnd::OnSysCommand(nID, lParam);
}
«_Superman_»
I love work. It gives me something to do between weekends.I've tried to take ur example and plant it in my code. the thing is that for some reason, in my Class Wizard i couldn't find WM_SYSCOMMAND message, so i implemented it manually like you said in between the message map macros. but still, when i click on the "About" item, nothing happen's.. no trigger pumps the event. maybe something im missing ?
-
I've tried to take ur example and plant it in my code. the thing is that for some reason, in my Class Wizard i couldn't find WM_SYSCOMMAND message, so i implemented it manually like you said in between the message map macros. but still, when i click on the "About" item, nothing happen's.. no trigger pumps the event. maybe something im missing ?
This is how I added the
WM_SYSCOMMAND
handler - Right click onCMainFrame
fromClass View
and selectProperties
. Click in theMessages
icon in theProperties
window. Here you will findWM_SYSCOMMAND
. Add the handler for this here.«_Superman_»
I love work. It gives me something to do between weekends. -
This is how I added the
WM_SYSCOMMAND
handler - Right click onCMainFrame
fromClass View
and selectProperties
. Click in theMessages
icon in theProperties
window. Here you will findWM_SYSCOMMAND
. Add the handler for this here.«_Superman_»
I love work. It gives me something to do between weekends. -
No. I tried this in VS2010. But if you add this manually it should work. Did you add the
ON_WM_SYSCOMMAND
macro?«_Superman_»
I love work. It gives me something to do between weekends. -
No. I tried this in VS2010. But if you add this manually it should work. Did you add the
ON_WM_SYSCOMMAND
macro?«_Superman_»
I love work. It gives me something to do between weekends.I dont think so, how do i add it ? what i did in my .h file is:
protected:
//{{AFX_MSG(CChildFrame)
afx_msg void OnClose();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd);
//This functions were inserted by the class wizard...
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
};then on the .cpp file:
void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
//...
} -
I dont think so, how do i add it ? what i did in my .h file is:
protected:
//{{AFX_MSG(CChildFrame)
afx_msg void OnClose();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd);
//This functions were inserted by the class wizard...
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
};then on the .cpp file:
void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
//...
}You need this in the .cpp file -
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_CTLCOLOR()
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()«_Superman_»
I love work. It gives me something to do between weekends. -
You need this in the .cpp file -
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_CTLCOLOR()
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()«_Superman_»
I love work. It gives me something to do between weekends.Ok man, i've found the solution in VC6++ i've went to the class view of the class Frame im using. right-click -> Add Windows Message Handler.. then on the bottom under: "Filter for messages available for class" i selected "Window" and added the WM_SYSCOMMAND to my class wizard. now it work's i think that the problam was that even if i added it manualy, there was no trigger to the event. now since the message is in the wizard, and known by the compailer it triggers the event. Thank's anyway.. Good day