void add_or_update_menu_item(int menuId, wchar_t* title, wchar_t* tooltip, short disabled, short checked) { // todo(thomasf),, should title and tooltip be freeed? MENUITEMINFO menuItemInfo; menuItemInfo.cbSize = sizeof(MENUITEMINFO); menuItemInfo.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA | MIIM_STATE; menuItemInfo.fType = MFT_STRING; menuItemInfo.dwTypeData = title; menuItemInfo.cch = wcslen(title) + 1; menuItemInfo.dwItemData = (ULONG_PTR)menuId; menuItemInfo.fState = 0; if (disabled == 1) { menuItemInfo.fState |= MFS_DISABLED; } if (checked == 1) { menuItemInfo.fState |= MFS_CHECKED; } int itemCount = GetMenuItemCount(hTrayMenu); int i; for (i = 0; i < itemCount; i++) { int id = GetMenuItemId(i); if (-1 == id) { continue; } if (menuId == id) { SetMenuItemInfo(hTrayMenu, i, TRUE, &menuItemInfo); break; } } if (i == itemCount) { InsertMenuItem(hTrayMenu, -1, TRUE, &menuItemInfo); } }
MIR_CORE_DLL(void) TranslateMenu_LP(HMENU hMenu, int _hLangpack) { MUUID *uuid = Langpack_LookupUuid(_hLangpack); MENUITEMINFO mii = { 0 }; mii.cbSize = sizeof(mii); for (int i = GetMenuItemCount(hMenu) - 1; i >= 0; i--) { TCHAR str[256]; mii.fMask = MIIM_TYPE | MIIM_SUBMENU; mii.dwTypeData = (TCHAR*)str; mii.cch = _countof(str); GetMenuItemInfo(hMenu, i, TRUE, &mii); if (mii.cch && mii.dwTypeData) { TCHAR *result = (TCHAR*)LangPackTranslateString(uuid, (const char*)mii.dwTypeData, TRUE); if (result != mii.dwTypeData) { mii.dwTypeData = result; mii.fMask = MIIM_TYPE; SetMenuItemInfo(hMenu, i, TRUE, &mii); } } if (mii.hSubMenu != NULL) TranslateMenu_LP(mii.hSubMenu, _hLangpack); } }
value external_start (void) { /* Disable close button on console */ #if defined(__MINGW32__) char *buf = "[MLDonkey TitleSearch]\0"; /* if multiple instances */ SetConsoleTitle((LPCTSTR)buf); myHWND = FindWindowEx(NULL, NULL, NULL, (LPCTSTR)buf); if (myHWND != NULL) { HMENU hmenu = GetSystemMenu(myHWND, FALSE); MENUITEMINFO CloseItem; CloseItem.cbSize = sizeof(MENUITEMINFO); CloseItem.fMask = MIIM_ID; CloseItem.wID = SC_MINIMIZE+1; EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); SetMenuItemInfo(hmenu, SC_CLOSE, FALSE, &CloseItem); DrawMenuBar(myHWND); } #endif /* defined(__MINGW32__) */ #if defined(HAVE_PTHREAD) && defined(PTW32_STATIC_LIB) pthread_win32_process_attach_np(); #endif return Val_unit; }
LRESULT CMainWindow::OnIsNotSpam(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { m_Dummy.Create(m_hWnd); m_Dummy.ShowWindow(SW_SHOW); m_ProgressDlg.CreateDialogInThread(false, m_hWnd); UINT nTotalMessages = 0; if (m_OETricks.SendSelectedMessagesToMC(false, nTotalMessages)) { m_ProgressDlg.SetTotalMessages(nTotalMessages); m_nStyle = GetWindowLong(GWL_STYLE); SetWindowLong(GWL_STYLE, m_nStyle & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX)); HMENU hSysMenu = GetSystemMenu(FALSE); if (hSysMenu) { MENUITEMINFO mii; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STATE; mii.fState = MFS_GRAYED; SetMenuItemInfo(hSysMenu, SC_CLOSE, FALSE, &mii); } } return S_OK; }
BOOL CUIMenu::DeleteMenu(UINT nPosition, UINT nFlags) { BOOL bByPosition; UI_MENU_ITEM_INFO * lpUIMenuItemInfo; bByPosition = nFlags & MF_BYPOSITION; lpUIMenuItemInfo = GetMenuItemInfo(nPosition, bByPosition); if (lpUIMenuItemInfo != NULL && UI_MENU_MAGIC == lpUIMenuItemInfo->nMagic) { if (lpUIMenuItemInfo->hSubMenu != NULL) { CUIMenu SubMenu(lpUIMenuItemInfo->hSubMenu); SubMenu.DeleteMenu(nPosition, nFlags); } //CUIManager::GetInstance()->ReleaseImage(lpUIMenuItemInfo->lpIconImgN); //CUIManager::GetInstance()->ReleaseImage(lpUIMenuItemInfo->lpIconImgH); delete lpUIMenuItemInfo; SetMenuItemInfo(nPosition, nFlags, NULL); } return ::DeleteMenu(m_hMenu, nPosition, nFlags); }
void PlayerMenuItemWin::setTitle(const std::string &title) { if (title.length() == 0) { CCLOG("MenuServiceWin::setTitle() - can not set menu title to empty, menu id (%s)", _menuId.c_str()); return; } MENUITEMINFO menuitem; menuitem.cbSize = sizeof(menuitem); menuitem.fMask = MIIM_FTYPE | MIIM_STRING; menuitem.fType = (title.compare("-") == 0) ? MFT_SEPARATOR : MFT_STRING; std::u16string u16title; cocos2d::StringUtils::UTF8ToUTF16(title, u16title); menuitem.dwTypeData = (LPTSTR)u16title.c_str(); if (SetMenuItemInfo(_parent->_hmenu, _commandId, MF_BYCOMMAND, &menuitem)) { _title = title; } else { DWORD err = GetLastError(); CCLOG("MenuServiceWin::setTitle() - set menu title failed, menu id (%s). error code = %u", _menuId.c_str(), err); } }
BOOL CUIMenu::RemoveMenu(UINT nPosition, UINT nFlags) { BOOL bByPosition; UI_MENU_ITEM_INFO * lpUIMenuItemInfo; MENUITEMINFO stMenuItemInfo = { 0 }; WCHAR cText[256] = { 0 }; bByPosition = nFlags & MF_BYPOSITION ? TRUE : FALSE; lpUIMenuItemInfo = GetMenuItemInfo(nPosition, bByPosition); if (lpUIMenuItemInfo != NULL && UI_MENU_MAGIC == lpUIMenuItemInfo->nMagic) { if (lpUIMenuItemInfo->hSubMenu != NULL) { CUIMenu SubMenu(lpUIMenuItemInfo->hSubMenu); SubMenu.RemoveMenu(nPosition, nFlags); } //CUIManager::GetInstance()->ReleaseImage(lpUIMenuItemInfo->lpIconImgN); //CUIManager::GetInstance()->ReleaseImage(lpUIMenuItemInfo->lpIconImgH); delete lpUIMenuItemInfo; SetMenuItemInfo(nPosition, bByPosition, NULL); } return ::RemoveMenu(m_hMenu, nPosition, nFlags); }
void SetDefaultMenuItem(HMENU p_menu,unsigned p_id) { MENUITEMINFO info = {sizeof(info)}; info.fMask = MIIM_STATE; GetMenuItemInfo(p_menu,p_id,FALSE,&info); info.fState |= MFS_DEFAULT; SetMenuItemInfo(p_menu,p_id,FALSE,&info); }
void LocalizeMenu(HMENU hMenu) { if (Localization == NULL) return; MENUITEMINFO mii; mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA; UINT idx = 0; while (GetMenuItemInfo(hMenu, idx, TRUE, &mii)) { if (mii.fType == MFT_STRING) { TCHAR *str = Localization->GetStr(mii.wID); if (str != NULL) { mii.cbSize = sizeof(mii); mii.fMask = MIIM_TYPE; mii.dwTypeData = (LPTSTR) str; mii.cch = wcslen(str); SetMenuItemInfo(hMenu, idx, TRUE, &mii); } } idx++; mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA; } }
static int winItemSetTitleAttrib(Ihandle* ih, const char* value) { char *str; MENUITEMINFO menuiteminfo; if (ih->handle == (InativeHandle*)-1) /* check if submenu is actually created */ return 1; if (!value) { str = " "; value = str; } else str = iupMenuProcessTitle(ih, value); menuiteminfo.cbSize = sizeof(MENUITEMINFO); menuiteminfo.fMask = MIIM_TYPE; menuiteminfo.fType = MFT_STRING; menuiteminfo.dwTypeData = str; menuiteminfo.cch = strlen(str); SetMenuItemInfo((HMENU)ih->handle, (UINT)ih->serial, FALSE, &menuiteminfo); if (str != value) free(str); winMenuUpdateBar(ih); return 1; }
void CDownloadMonitorDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint point) { CMainWnd* pMainWnd = (CMainWnd*)AfxGetMainWnd(); if ( ! pMainWnd || ! IsWindow( pMainWnd->m_hWnd ) ) return; CDownloadsWnd* pDownWnd = (CDownloadsWnd*)pMainWnd->m_pWindows.Find( RUNTIME_CLASS(CDownloadsWnd) ); if ( ! pDownWnd ) return; if ( ! pDownWnd->Select( m_pDownload ) ) return; CMenu* pPopup = ::Skin.GetMenu( _T("CDownloadsWnd.Download") ); if ( ! pPopup ) return; MENUITEMINFO pInfo; pInfo.cbSize = sizeof(pInfo); pInfo.fMask = MIIM_STATE; GetMenuItemInfo( pPopup->GetSafeHmenu(), m_pDownload->IsCompleted() ? ID_DOWNLOADS_LAUNCH_COMPLETE : ID_DOWNLOADS_LAUNCH_COPY, FALSE, &pInfo ); pInfo.fState |= MFS_DEFAULT; SetMenuItemInfo( pPopup->GetSafeHmenu(), m_pDownload->IsCompleted() ? ID_DOWNLOADS_LAUNCH_COMPLETE : ID_DOWNLOADS_LAUNCH_COPY, FALSE, &pInfo ); CoolMenu.AddMenu( pPopup, TRUE ); UINT nID = pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD, point.x, point.y, pDownWnd ); if ( nID && pDownWnd->Select( m_pDownload ) ) { pDownWnd->SendMessage( WM_COMMAND, nID ); } }
/* Update menu string if text is non-null Update enable / disable if "enable" is non-zero. Positive will enable. Negative will disable. Update checked status if "check" is non-zero. Positive will enable, negative will disable. */ static void updateMenu(int id, char *text, int enable, int check) { MENUITEMINFO menuInfo; int rc; if (text) { memset(&menuInfo, 0, sizeof(menuInfo)); menuInfo.fMask = MIIM_STRING; menuInfo.cbSize = sizeof(menuInfo); menuInfo.fType = MFT_STRING; menuInfo.dwTypeData = NULL; menuInfo.fMask = MIIM_STRING; menuInfo.dwTypeData = text; menuInfo.cch = (uint) slen(text) + 1; rc = SetMenuItemInfo(app->subMenu, id, FALSE, &menuInfo); } if (enable > 0) { rc = EnableMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_ENABLED); } else if (enable < 0) { rc = EnableMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_GRAYED); } if (check > 0) { rc = CheckMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_CHECKED); } else if (check < 0) { rc = CheckMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_UNCHECKED); } rc = DrawMenuBar(app->appHwnd); }
void CDebugger::UpdateLoggingMenu() { HMENU hMenu = GetMenu(m_hWnd); hMenu = GetSubMenu(hMenu, 2); const int stateCount = 8; bool nState[stateCount]; memset(nState, 0, sizeof(nState)); // nState[0] = m_virtualMachine.m_Logging.GetGSLoggingStatus(); // nState[1] = m_virtualMachine.m_Logging.GetDMACLoggingStatus(); // nState[2] = m_virtualMachine.m_Logging.GetIPULoggingStatus(); // nState[3] = m_virtualMachine.m_Logging.GetOSLoggingStatus(); // nState[4] = m_virtualMachine.m_Logging.GetOSRecordingStatus(); // nState[5] = m_virtualMachine.m_Logging.GetSIFLoggingStatus(); // nState[6] = m_virtualMachine.m_Logging.GetIOPLoggingStatus(); for(unsigned int i = 0; i < stateCount; i++) { MENUITEMINFO mii; memset(&mii, 0, sizeof(MENUITEMINFO)); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STATE; mii.fState = nState[i] ? MFS_CHECKED : 0; SetMenuItemInfo(hMenu, i, TRUE, &mii); } }
void ContextMenu::ChangeSkinIndex(HMENU menu, int index) { if (index > 0) { const int count = GetMenuItemCount(menu); for (int i = 0; i < count; ++i) { HMENU subMenu = GetSubMenu(menu, i); if (subMenu) { ChangeSkinIndex(subMenu, index); } else { MENUITEMINFO mii = {sizeof(MENUITEMINFO)}; mii.fMask = MIIM_FTYPE | MIIM_ID; GetMenuItemInfo(menu, i, TRUE, &mii); if ((mii.fType & MFT_SEPARATOR) == 0) { mii.wID |= (index << 16); mii.fMask = MIIM_ID; SetMenuItemInfo(menu, i, TRUE, &mii); } } } } }
BOOL CCustomMenu::SetMenuItemInfo(CMenu *pMenu, BOOL Toped) { if (pMenu != NULL) { int MenuCount = pMenu->GetMenuItemCount(); for (int i=0;i<MenuCount;i++) { pMenu->GetMenuString(i,m_MenuList[m_Index].m_MenuText,MF_BYPOSITION); UINT MenuID = pMenu->GetMenuItemID(i); if ((MenuID==-1 || MenuID==65535) && Toped==TRUE) //MenuID = -1 Toped = false 表示弹出式菜单 { MenuID = -2; //顶层菜单 }; m_MenuList[m_Index].m_MenuType = MenuID; pMenu->ModifyMenu(i,MF_OWNERDRAW|MF_BYPOSITION |MF_STRING,m_MenuList[m_Index].m_MenuType,(LPSTR)&(m_MenuList[m_Index])); m_Index += 1; CMenu* pSubMenu = pMenu->GetSubMenu(i); if (pSubMenu) { SetMenuItemInfo(pSubMenu,FALSE); } } } return TRUE; }
static int winItemSetTitleAttrib(Ihandle* ih, const char* value) { char *str; /* check if the submenu handle was created in winSubmenuAddToParent */ if (ih->handle == (InativeHandle*)-1) return 1; if (!value) { str = " "; value = str; } else str = iupMenuProcessTitle(ih, value); { TCHAR* tstr = iupwinStrToSystem(str); int len = lstrlen(tstr); MENUITEMINFO menuiteminfo; menuiteminfo.cbSize = sizeof(MENUITEMINFO); menuiteminfo.fMask = MIIM_TYPE; menuiteminfo.fType = MFT_STRING; menuiteminfo.dwTypeData = tstr; menuiteminfo.cch = len; SetMenuItemInfo((HMENU)ih->handle, (UINT)ih->serial, FALSE, &menuiteminfo); } if (str != value) free(str); winMenuUpdateBar(ih); return 1; }
void InitalizeMenus() { MENUITEMINFO mii; int i; hMenu_main = CreateMenu(); hMenu_main_popup = CreatePopupMenu(); hMenu_windows_popup = CreatePopupMenu(); hMenu_open_popup = CreatePopupMenu(); hMenu_rtf = CreatePopupMenu(); hMenu_lvw = CreatePopupMenu(); hMenu_client = CreatePopupMenu(); hMenu_lvwColumns = CreatePopupMenu(); hMenu_lvwBots = CreatePopupMenu(); hMenu_txtExt = CreatePopupMenu(); hMenu_lvwClan = CreatePopupMenu(); menus[0].id = (int)hMenu_main_popup; menus[3].id = (int)hMenu_windows_popup; menus[4].id = (int)hMenu_open_popup; menus[27].id = (int)hMenu_txtExt; for (i = 0; i != NUM_MENUITEMS; i++) AppendMenu(*menus[i].lphMenu, menus[i].type, menus[i].id, menus[i].title); SetMenu(hWnd_main, hMenu_main); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STATE; mii.fState = MFS_CHECKED; for (i = 10080; i != 10085; i++) SetMenuItemInfo(hMenu_lvwColumns, i, false, &mii); }
void Menu::updateSeparator( HMENU hmenu, int& index, ItemPtr item, const MENUITEMINFO& info ) { if( ( info.fType & MFT_SEPARATOR ) == 0 ) { MENUITEMINFO info = { sizeof( info ), MIIM_FTYPE, MFT_SEPARATOR }; SetMenuItemInfo( hmenu, index, TRUE, &info ); } }
void TrayIcon::SetMenuItemText(HMENU hMenu, UINT nID, LPCWSTR pszText) { wchar_t szText[128]; MENUITEMINFO mi = {sizeof(MENUITEMINFO)}; mi.fMask = MIIM_STRING; lstrcpyn(szText, pszText, countof(szText)); mi.dwTypeData = szText; SetMenuItemInfo(hMenu, nID, FALSE, &mi); }
void SetMenuName (HMENU menu, UINT pos, BOOL bypos, LPCTSTR name) { MENUITEMINFO mii; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_DATA; if (!GetMenuItemInfo(menu, pos, bypos, &mii)) return; if (mii.dwItemData) free((void*)(mii.dwItemData)); mii.dwItemData = name? (ULONG_PTR)tstrdup(name) :NULL; SetMenuItemInfo(menu, pos, bypos, &mii); }
bool CBaseMenu::AddMenu(MENU_HANDLE hMenu, MenuItemList Items ) { if (Items.begin() == Items.end()) { return false; } UINT ItemID, uFlags; stdstr Text; stdstr String; for (MenuItemList::iterator MenuItem = Items.begin(); MenuItem != Items.end(); MenuItem++) { ItemID = MenuItem->ID; uFlags = MF_STRING; Text = _Lang->GetString(MenuItem->Title).c_str(); if (MenuItem->Title == EMPTY_STRING && MenuItem->ManualString.length() > 0) { Text = MenuItem->ManualString; } if (ItemID == SPLITER) { uFlags |= MF_SEPARATOR; } if (MenuItem->ItemTicked) { uFlags |= MFS_CHECKED; } if (MenuItem->ItemEnabled) { uFlags |= MFS_ENABLED; } else { uFlags |= MFS_DISABLED; } MenuItemList * SubMenu = (MenuItemList *)MenuItem->SubMenu; if (ItemID == SUB_MENU && HIWORD(SubMenu) != 0 && (SubMenu->begin() != SubMenu->end())) { ItemID = (UINT)CreatePopupMenu(); uFlags |= MF_POPUP; AddMenu((MENU_HANDLE)ItemID,*SubMenu); } if (ItemID == ID_PLUGIN_MENU) { ItemID = (UINT)MenuItem->SubMenu; uFlags |= MF_POPUP; MENUITEMINFO lpmii; lpmii.cbSize = sizeof(MENUITEMINFO); lpmii.fMask = MIIM_STATE; lpmii.fState = 0; SetMenuItemInfo((HMENU)ItemID, (DWORD)MenuItem->SubMenu, FALSE,&lpmii); } if (MenuItem->ShotCut.empty() == false) { String = Text; String += "\t"; String += MenuItem->ShotCut; Text = String; } AppendMenu((HMENU)hMenu,uFlags,ItemID,Text.c_str()); } return true; }
BOOL SetMenuName (HMENU hm, int n, const char* name) { MENUITEMINFO mii; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_DATA; if (!GetMenuItemInfo(hm, n, TRUE, &mii)) return FALSE; if (mii.dwItemData) free(mii.dwItemData); mii.dwItemData = strdup(name); return !!SetMenuItemInfo(hm, n, TRUE, &mii); }
static int mh_newindex (lua_State* l) { menu* m = lua_touserdata(l,1); const char* nm = luaL_checkstring(l,2); if (streq(nm, "checked")) { if (m->sub) luaL_error(l, "unsupported operation"); int flags = MF_BYCOMMAND | (luaL_checkboolean(l,3)? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(m->parent, m->command, flags); } else if (streq(nm, "enabled")) { if (m->sub) luaL_error(l, "unsupported operation"); int flags = MF_BYCOMMAND | (luaL_checkboolean(l,3)? MF_ENABLED : MF_DISABLED); EnableMenuItem(m->parent, m->command, flags); } else if (streq(nm, "name")) SetMenuName(m->parent, m->position, luaL_checkstring(l,3)); else if (streq(nm, "text")) { const char* str = luaL_checkstring(l,3); const wchar_t* wstr = strcvt(str, CP_UTF8, CP_UTF16, NULL); mh_updateLabel(m, wstr, -1, -1); free(wstr); } else if (streq(nm, "onAction")) { if (m->sub || m->command<IDM_CUSTOMCOMMAND) luaL_error(l, "unsupported operation"); if (!lua_isfunction(l,2)) luaL_typerror(l, 2, "function"); lua_pushlightuserdata(l, m->command); lua_pushvalue(l,3); lua_rawset(l, LUA_REGISTRYINDEX); void** p = getCustomCommand(m->command - IDM_CUSTOMCOMMAND); *p = lua_topointer(l,3); } else if (streq(nm, "accelerator")) { const char* str = NULL; if (!lua_isnil(l,3)) str = luaL_checkstring(l,3); int f, k; if (!(m->sub) && str && parseKeyName(str, &f, &k)) { BOOL b = removeAccelerator(m->command); addAccelerator(f, k, m->command); mh_updateLabel(m, NULL, f, k); } else if (!str) { BOOL b = removeAccelerator(m->command); mh_updateLabel(m, NULL, 0, 0); }} else if (streq(nm, "radio")) { BOOL b = luaL_checkboolean(l,3); MENUITEMINFO mii; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_FTYPE; if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0; if (b) mii.fType|=MFT_RADIOCHECK; else mii.fType&=~MFT_RADIOCHECK; if (!SetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0; return 1; } // SUITE else luaL_argerror(l, 2, "unknown property"); return 0; }
void NgineSlackBrowser::UpdateStartup() { MENUITEMINFO mii; ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = Util::IsStartup() ? MFS_CHECKED : 0; SetMenuItemInfo(m_hTrayMenu, ID_TRAY_CONTEXTMENU_STARTUP, FALSE, &mii); }
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); m_titles[pos] = label; if ( !IsAttached() ) { return; } //else: have to modify the existing menu int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos); UINT id; UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION); if ( flagsOld == 0xFFFFFFFF ) { wxLogLastError(wxT("GetMenuState")); return; } if ( flagsOld & MF_POPUP ) { // HIBYTE contains the number of items in the submenu in this case flagsOld &= 0xff; id = (UINT)::GetSubMenu((HMENU)m_hMenu, mswpos); } else { id = pos; } #ifdef __WXWINCE__ MENUITEMINFO info; wxZeroMemory(info); info.cbSize = sizeof(info); info.fMask = MIIM_TYPE; info.fType = MFT_STRING; info.cch = label.Length(); info.dwTypeData = (LPTSTR) label.c_str(); if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) ) { wxLogLastError(wxT("SetMenuItemInfo")); } #else if ( ::ModifyMenu(GetHmenu(), mswpos, MF_BYPOSITION | MF_STRING | flagsOld, id, label) == (int)0xFFFFFFFF ) { wxLogLastError(wxT("ModifyMenu")); } #endif Refresh(); }
BOOL CIconMenu::SetMenuItemData(UINT_PTR nIDNewItem, LONG_PTR data) { MENUITEMINFO menuinfo ={0}; menuinfo.cbSize = sizeof(menuinfo); GetMenuItemInfo((UINT)nIDNewItem, &menuinfo); menuinfo.dwItemData =data; menuinfo.fMask |= MIIM_DATA; return SetMenuItemInfo((UINT)nIDNewItem ,&menuinfo); }
BOOL CUIMenu::AppendMenu(UINT nFlags, UINT_PTR nIDNewItem/* = 0*/, LPCTSTR lpszNewItem/* = NULL*/) { UI_MENU_ITEM_INFO * lpUIMenuItemInfo; int nCount; BOOL bRet; nFlags |= MF_OWNERDRAW; bRet = ::AppendMenu(m_hMenu, nFlags, nIDNewItem, lpszNewItem); if (bRet) { lpUIMenuItemInfo = new UI_MENU_ITEM_INFO; if (lpUIMenuItemInfo != NULL) { memset(lpUIMenuItemInfo, 0, sizeof(UI_MENU_ITEM_INFO)); lpUIMenuItemInfo->nMagic = UI_MENU_MAGIC; if (nFlags & MF_POPUP) // 弹出菜单 { lpUIMenuItemInfo->hSubMenu = (HMENU)nIDNewItem; if (lpszNewItem != NULL && _tcslen(lpszNewItem) > 0) { lpUIMenuItemInfo->szText = string_t(lpszNewItem); //_tcsncpy_s(lpUIMenuItemInfo->szText, lpszNewItem, // sizeof(lpUIMenuItemInfo->szText) / sizeof(TCHAR)); } bRet = EnableOwnerDraw(lpUIMenuItemInfo->hSubMenu, TRUE); } else { if (nFlags & MF_SEPARATOR) // 分隔符 { lpUIMenuItemInfo->nID = 0; lpUIMenuItemInfo->nType = MFT_SEPARATOR; } else // 菜单项 { lpUIMenuItemInfo->nID = nIDNewItem; if (lpszNewItem != NULL && _tcslen(lpszNewItem) > 0) { lpUIMenuItemInfo->szText = string_t(lpszNewItem); //_tcsncpy_s(lpUIMenuItemInfo->szText, lpszNewItem, // sizeof(lpUIMenuItemInfo->szText) / sizeof(TCHAR)); } } } nCount = ::GetMenuItemCount(m_hMenu); bRet = SetMenuItemInfo(nCount - 1, TRUE, lpUIMenuItemInfo); } } return bRet; }
BOOL CUIMenu::InsertMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem/* = 0*/, LPCTSTR lpszNewItem/* = NULL*/) { BOOL bByPosition; UI_MENU_ITEM_INFO * lpUIMenuItemInfo; BOOL bRet; bByPosition = nFlags & MF_BYPOSITION ? TRUE : FALSE; nFlags |= MF_OWNERDRAW; bRet = ::InsertMenu(m_hMenu, nPosition, nFlags, nIDNewItem, lpszNewItem); if (bRet) { lpUIMenuItemInfo = new UI_MENU_ITEM_INFO; if (lpUIMenuItemInfo != NULL) { memset(lpUIMenuItemInfo, 0, sizeof(UI_MENU_ITEM_INFO)); lpUIMenuItemInfo->nMagic = UI_MENU_MAGIC; if (nFlags & MF_POPUP) // 弹出菜单 { lpUIMenuItemInfo->hSubMenu = (HMENU)nIDNewItem; if (lpszNewItem != NULL && _tcslen(lpszNewItem) > 0) { lpUIMenuItemInfo->szText = string_t(lpszNewItem); //_tcsncpy_s(lpUIMenuItemInfo->szText, lpszNewItem, // sizeof(lpUIMenuItemInfo->szText) / sizeof(TCHAR)); } bRet = EnableOwnerDraw(lpUIMenuItemInfo->hSubMenu, TRUE); } else { if (nFlags & MF_SEPARATOR) // 分隔符 { lpUIMenuItemInfo->nID = 0; lpUIMenuItemInfo->nType = MFT_SEPARATOR; } else if (nFlags & MF_STRING) // 菜单项 { lpUIMenuItemInfo->nID = nIDNewItem; if (lpszNewItem != NULL && _tcslen(lpszNewItem) > 0) { lpUIMenuItemInfo->szText = string_t(lpszNewItem); //_tcsncpy_s(lpUIMenuItemInfo->szText, lpszNewItem, // sizeof(lpUIMenuItemInfo->szText) / sizeof(TCHAR)); } } } bRet = SetMenuItemInfo(nPosition, bByPosition, lpUIMenuItemInfo); } } return bRet; }
void SetText(HMENU m, UINT id, WCHAR *s) { MENUITEMINFO mii = { 0 }; mii.cbSize = sizeof(mii); mii.fMask = MIIM_STRING; mii.fType = MFT_STRING; mii.dwTypeData = s; mii.cch = (UINT)str::Len(s); SetMenuItemInfo(m, id, FALSE, &mii); }
void SetMenuCheckedState(HMENU menu, int did, int id) { MENUITEMINFO info; info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_STATE; GetMenuItemInfo(menu, id, MF_BYCOMMAND, &info); info.fState = (info.fState &~MFS_CHECKED) | (GetWindowIndex(did) == -1 ? 0 : MFS_CHECKED); SetMenuItemInfo(menu, id, MF_BYCOMMAND, &info); }