for creating the Menu on Right Click or any click look at these apis;
http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/res
ources/menus/menureference/menufunctions/trackpopupmenu.asp
-> How can I add new item to the menu?
AppendMenu(..)
--
With Regards
Alok Gupta
Visit me at http://alok.bizhat.com
"I think this will Help"
POINT point;
GetCursorPos(&point);
::TrackPopupMenu(hMnu,TPM_LEFTBUTTON |
TPM_RIGHTBUTTON,point.x,point.y,NULL,this->m_hWnd,NULL);
--
With Regards
Alok Gupta
Visit me at http://alok.bizhat.com
"I think this will Help"
"Moritz" <Mor...@discussions.microsoft.com> wrote in message
news:B0ACA13A-F262-44DB...@microsoft.com...
There are three ways I know of to do this, and all of them involve first
subclassing the combo's edit control. In MFC this means using a class
derived from CEdit, instantiating it as a member variable and calling its
SubclassWindow member function using the HWND returned by calling the
combo's GetWindow(GW_CHILD). After that you can handle the WM_CONTEXTMENU
message in the subclass and 1) CreatePopupMenu or LoadMenu/GetSubMenu your
own and add the standard edit menu items yourself along with your custom
item(s). The command ids map as: WM_UNDO("&Undo"),
WM_COPY("&Copy),WM_PASTE("&Paste"), WM_CUT("Cu&t"), WM_CLEAR("&Delete") and
EM_SETSEL("Select &All"); 2) I've not explored this as to practicality, but
you can load the default edit menu from user32.dll (I think it might be
different on the 9x platforms). Its menu resource id is 1 and submenu index
is 0. In theory this approach would obtain the text for the current locale.
This menu does contain several items that I've never seen in the OS versions
I use, so you may have to discern if and when to remove them before adding
your custom item(s). In either case, you then need to enable/disable the
commands as appropriate, calculate the menu position and call TrackPopupMenu
yourself using TPM_RETURNCMD (along with which ever other flags seem
necessary), and then forward all standard commands to the base class
implementation for default processing and handle your additions locally; 3)
I came up with this one last August, and I've only ever tested it on XP so I
can't promise it on any other platform. It starts by adding a BOOL member
variable to your derived CEdit which you initialize to FALSE in the ctor...
CComboEdit::CComboEdit() : m_bMenuInitialized(FALSE)
{
}
...Then add handlers for the WM_ENTERIDLE and WM_MENUSELECT messages...
VOID CComboEdit::OnEnterIdle(UINT nWhy, CWnd* pWho)
{
CEdit::OnEnterIdle(nWhy, pWho);
if (!m_hMenu && pWho && (MSGF_MENU == nWhy))
{
if (InPopupMenuMode(m_hWnd))
{
HMENU hMenu = (HMENU)pWho->SendMessage(MN_GETHMENU);
if (hMenu)
{
// Add custom item to the standard menu
CString strItem((LPCTSTR)IDS_CUSTOM_MENUITEM_1);
if (AppendMenu(hMenu, MF_STRING, RWM_CUSTOM_MENUITEM_1,
strItem))
m_bMenuInitialized = TRUE;
}
}
}
}
VOID CComboEdit::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
CEdit::OnMenuSelect(nItemID, nFlags, hSysMenu);
if (!hSysMenu && (0x0000FFFF == nFlags))
m_bMenuInitialized = FALSE;
}
...where the InPopupMenuMode helper function goes something like this...
static CONST _inline BOOL _stdcall InPopupMenuMode(
IN CONST HWND hWndMenuOwner)
{
GUITHREADINFO gti = { sizeof(gti) };
return (GetGUIThreadInfo(NULL, >i) &&
(gti.flags & GUI_POPUPMENUMODE) &&
(gti.hwndMenuOwner == hWndMenuOwner));
}
...and the RWM_CUSTOM_MENUITEM_1 is declared something like so (or amybe use
a GUID string)...
static CONST UINT RWM_CUSTOM_MENUITEM_1 = RegisterWindowMessage(
_T("CComboEdit::RWM_CUSTOM_MENUITEM_1"));
...lastly, you add a handler for your custom item...
BEGIN_MESSAGE_MAP(CComboEdit, CEdit)
// {{AFX_MSG_MAP(CComboEdit)
ON_WM_ENTERIDLE()
ON_WM_MENUSELECT()
// }}AFX_MSG_MAP
ON_REGISTERED_MESSAGE(RWM_CUSTOM_MENUITEM_1, OnMenuCustom1)
END_MESSAGE_MAP()
...and implement it however you want, really, but for the sake of example...
LRESULT CComboEdit::OnMenuCustom1(WPARAM, LPARAM)
{
AfxMessageBox(IDS_CUSTOM_MENU_1_MSG, MB_OK);
return 0;
}
The benefits of this last approach are that the edit control does all of the
menu creation, localizing, tracking, default command enabling/disabling and
handling itself just as it normally would. All you have to worry about is
your own custom items and matching the locale. Presumably this would involve
localized STRINGTABLE entries, but I have no real experience with supporting
international languages and locales, so I can't say much about that part.
Anyway, HTH...
--
Jeff Partch [VC++ MVP]