Kansana
April 27th, 2007, 01:47 AM
Hi All,
I have a menu which is normally displayed at the left bottom of an icon in the UI(the UI is displayed at the rigth side of the screen). I use TrackPopUpMenu to display the window.
My requirement is that when the 'menu width' exceeds that of the width(calculated between the top-left of the menu icon and the rigth end of the desktop window) , I have to display the menu at the right bottom of the icon. At present, I handle the WM_INITMENUPOPUP . In that I calculate the widths and try to reposition the menu.I used SetWindowPos,MoveWindow but still I get the menu displayed at the left bottom of the icon. Please let me know how to reposition the menu. Also please let me know whether my approach is correct.
Please find below the code snippet
case WM_INITMENUPOPUP:
{
HMENU hMenu;
hMenu = GetMenu (this->GetHwnd());
int nMenuWidth = 0;
int nMenuHeight = 0;
RECT rct;
int nScreenWidth = 0;
int nWidth = 0;
BOOL bRet = false;
HWND hWndMenu = FindWindow(L"#32768", NULL);
LONG nMenuSize = (LONG)SendMessage((HWND)hWndMenu, 0x01E2, 1, 0);
nMenuWidth = LOWORD(nMenuSize) + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
nMenuHeight = HIWORD(nMenuSize) + GetSystemMetrics(SM_CYFIXEDFRAME) * 2;
nScreenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
::GetWindowRect(m_btnMenu.GetHwnd(), &rct);
nWidth = nScreenWidth - rct.left;
if((nWidth < nMenuWidth)/* && (m_fRedrawMenu)*/)
{
bRet = ::MoveWindow((HWND)hWndMenu,
rct.right,
rct.bottom,
nMenuWidth,
nMenuHeight,
false
);
//bRet = ::SetWindowPos((HWND)hWndMenu, NULL, rct.right, rct.bottom, 0, 0, SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
}
break;
}
Thanks ,
Kansana
I have a menu which is normally displayed at the left bottom of an icon in the UI(the UI is displayed at the rigth side of the screen). I use TrackPopUpMenu to display the window.
My requirement is that when the 'menu width' exceeds that of the width(calculated between the top-left of the menu icon and the rigth end of the desktop window) , I have to display the menu at the right bottom of the icon. At present, I handle the WM_INITMENUPOPUP . In that I calculate the widths and try to reposition the menu.I used SetWindowPos,MoveWindow but still I get the menu displayed at the left bottom of the icon. Please let me know how to reposition the menu. Also please let me know whether my approach is correct.
Please find below the code snippet
case WM_INITMENUPOPUP:
{
HMENU hMenu;
hMenu = GetMenu (this->GetHwnd());
int nMenuWidth = 0;
int nMenuHeight = 0;
RECT rct;
int nScreenWidth = 0;
int nWidth = 0;
BOOL bRet = false;
HWND hWndMenu = FindWindow(L"#32768", NULL);
LONG nMenuSize = (LONG)SendMessage((HWND)hWndMenu, 0x01E2, 1, 0);
nMenuWidth = LOWORD(nMenuSize) + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
nMenuHeight = HIWORD(nMenuSize) + GetSystemMetrics(SM_CYFIXEDFRAME) * 2;
nScreenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
::GetWindowRect(m_btnMenu.GetHwnd(), &rct);
nWidth = nScreenWidth - rct.left;
if((nWidth < nMenuWidth)/* && (m_fRedrawMenu)*/)
{
bRet = ::MoveWindow((HWND)hWndMenu,
rct.right,
rct.bottom,
nMenuWidth,
nMenuHeight,
false
);
//bRet = ::SetWindowPos((HWND)hWndMenu, NULL, rct.right, rct.bottom, 0, 0, SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
}
break;
}
Thanks ,
Kansana