Is it possible to get the rectangle of a contextual menu?
I'd like to be able to have the contextual menu always be inside the Window (CWnd) it is called from.
For example, if the X position is "near" the right size of the CWnd, then the contextual menu should should be called with the flag TPM_RIGHTALIGN.
For example, if the Y position is "near" the bottom size of the CWnd, then the contextual menu should should be called with the flag TPM_BOTTOMALIGN.
I don't think I can compute the size (height and height) of the menu before it is created (with TrackPopupMenu).
for example :
UINT menuFlags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON;
if ( point.x < menuWidth)
{
menuFlags |= TPM_LEFTALIGN;
}
else if ( point.x > clientRect.right - menuWidth)
{
menuFlags |= TPM_RIGHTALIGN;
}
else
{
menuFlags |= TPM_LEFTALIGN;
}
if ( point.y < menuHeight)
{
menuFlags |= TPM_TOPALIGN;
}
else if ( point.y > clientRect.bottom - menuHeight )
{
menuFlags |= TPM_BOTTOMALIGN;
}
else
{
menuFlags |= TPM_TOPALIGN;
}
::ClientToScreen( currentView->GetSafeHwnd(), &point );
pContextMenu->TrackPopupMenu( menuFlags, point.x , point.y , AfxGetMainWnd());
Addendum:
Seems CContextMenuManager::TrackPopupMenu does something near what I want, but only for the screen borders, not a predefined Cwnd Rect.
Thanks.
Max.