MFC SDI (single-document interface) 프로젝트에서 사용자 지정 팝업 메뉴를 그리려고합니다. ,
는 here에서, 나는
그래서 핸들 OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
을 추가하고이 함수 내에서 일부 코드를 추가 The framework calls this member function for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed.
을 찾았지만, 내가 바로보기를 클릭 할 때이 콜백이 프레임 워크에 의해 호출되지 않은 것을 발견 like :
동적으로 팝업 메뉴를 만드는 방법은 무엇입니까?
기능 build_dynamic_menu()
내부MFC SDI에서 사용자 지정 메뉴를 동적으로 그리는 방법
void Cdynamic_menu_sdiView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
if (IDR_MY_MENU == 0)
return;
CMenu dynamicMenu, proxyMenu;
if (dynamicMenu.GetSafeHmenu())
dynamicMenu.DestroyMenu();
// Create a new popup menu.
if (dynamicMenu.CreatePopupMenu() == FALSE)
return;
if (proxyMenu.LoadMenu(IDR_MY_MENU) == FALSE)
return;
int nSubMenu = 1;
CMenu* pProxyMenu = proxyMenu.GetSubMenu(nSubMenu);
build_dynamic_menu(m_map_menu_element_2, pProxyMenu, dynamicMenu, CString(""));
//m_menu_on_draw = &dynamicMenu; // link up the dynamic menu to the on draw menu, so that we can print it on the screen
CPoint ptCurPos; // current cursor position
GetCursorPos(&ptCurPos);
dynamicMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, ptCurPos.x, ptCurPos.y, AfxGetMainWnd(), NULL);
}
, 그것은 깊이 첫 번째 검색 기능입니다, 내가 InsertMenu(i, MF_BYPOSITION | MF_POPUP | MF_OWNERDRAW, uSubMenuID, strLabel);
그래서 동적으로 팝업 메뉴의 텍스트를 변경할 수 있습니다 할 : 여기
내가 내 팝업 메뉴를 얻는 방법이다 .
여기에 함수를 넣으려면 너무 길기 때문에 생각 만 말합니다.
또한 텍스트 색상과 배경색을 동적으로 변경하려고하므로 코드로 메뉴를 그리는 방법을 찾으려고합니다.
어디에서 시작해야합니까? owner drawn menus가 나에게 좋은 접근인가?
소유자가 그리는 메뉴입니까? 그렇지 않은 경우 해당 함수는 호출되지 않습니다. – immibis
고마워요, @immibis,이 첫 번째'http : // www.codeproject.com/Articles/7073/How-to-create-owner-drawn-menus-Step-by-Step '을 보려고합니다. – sflee
Itn 'OnDrawItem'과 관련이 없습니다. 팝업 메뉴를로드하는 방법을 보여줍니다. –