1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// exemple d'implémentation d'un classe Menu améloriée.
class CMenuEx:public CMenu
{
public:
CMenuEx():CMenu(){}
// initialise le contexte avec le parent
void InitPopupMenu(const CWnd *pWnd)
{
CPoint Point;
DWORD dwPos;
dwPos = GetMessagePos();
Point.x = LOWORD (dwPos);
Point.y = HIWORD (dwPos);
TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,
Point.x,
Point.y,
pWnd); // owner is the main application window
}
// ajoute un item au menu : sa position ,son IdControle,son texte.
void AddPopupMenuItem(const int nindex,const UINT nicmd,LPCTSTR szitem)
{
InsertMenu(nindex,MF_BYPOSITION | MF_STRING ,nicmd,szitem);
}
// ajoute un item separator.
void AddPopupMenuSeparator(const int nindex)
{
InsertMenu(nindex,MF_BYPOSITION | MF_SEPARATOR ,0,"");
}
};
// utilisation
char *tblm[]=
{
"Copier",
"Coller",
"Associer"
};
UINT tblid[]=
{
ID_MENU_COPY,
ID_MENU_PAST,
ID_MENU_LINK
};
CMenuEx *m_pMenu = new CMenuEx;
for(int i=0;i<sizeof(tblid)/sizeof(UINT);i++)
m_pMenu->AddPopupMenuItem(i,tblid[i],tblm[i]);
// appel
m_pMenu->InitPopupMenu(this); // this== fenetre concernée.. |
Partager