メニュー項目の説明をポップアップに表示
2569 ワード
class CSDI01View : public CWindowImpl<CSDI01View>
{
CMenuHandle m_TrackMenu;
CToolTipCtrl m_ToolTip;
public:
DECLARE_WND_CLASS(NULL)
BOOL PreTranslateMessage(MSG* pMsg)
{
pMsg;
return FALSE;
}
BEGIN_MSG_MAP(CSDI01View)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MSG_WM_CONTEXTMENU(OnContextMenu)
MESSAGE_HANDLER(WM_MENUSELECT, OnMenuSelect)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
END_MSG_MAP()
// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CPaintDC dc(m_hWnd);
//TODO: Add your drawing code here
return 0;
}
LRESULT OnMenuSelect(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
UINT nItemID = (UINT)LOWORD(wParam);
UINT nFlags = (UINT)HIWORD(wParam);
CMenuHandle menu = (HMENU)lParam;
if (m_TrackMenu.GetSubMenu(0) == menu)
{
m_ToolTip.UpdateTipText(nItemID, m_hWnd);
CRect rc;
UINT nPos =0, nItemCount = menu.GetMenuItemCount();
// Get Item Position
for (; nPos < nItemCount; nPos++)
{
if (menu.GetMenuItemID(nPos) == nItemID)
{
break;
}
}
int nRes = menu.GetMenuItemRect(NULL, nPos, &rc);
ATLTRACE("GetMenuItemRect() return %d
Menu item coordinate(right,top):(%d,%d)
", nRes, rc.right, rc.top);
CRect rcTip;
CToolInfo toolInfo(TTF_TRACK, m_hWnd);
m_ToolTip.GetToolInfo(&toolInfo);
m_ToolTip.GetWindowRect(&rcTip);
rcTip.MoveToXY(rc.right + 5, rc.top);
m_ToolTip.TrackActivate(&toolInfo, TRUE);
m_ToolTip.MoveWindow(&rcTip);
}
return 0;
}
void OnContextMenu(CWindow wnd, CPoint point)
{
CMenuHandle menu;
m_TrackMenu.LoadMenu(IDR_MENU1);
menu.Attach(m_TrackMenu.GetSubMenu(0));
m_ToolTip.Activate(TRUE);
ATLTRACE("OnContextMenu() :point(%d,%d)
",point.x, point.y);
menu.TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y, m_hWnd);
m_TrackMenu.DestroyMenu();
m_ToolTip.Activate(FALSE);
}
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
//LPCREATESTRUCT lpCreateStruct = (LPCREATESTRUCT)lParam;
m_ToolTip.Create(m_hWnd);
m_ToolTip.AddTool(m_hWnd);
m_ToolTip.SetMaxTipWidth(0);
return 0;
}
};