static const wchar_t* mh_getLabel (menu* m) { int ll = GetMenuString(m->parent, m->command, NULL, 0, MF_BYCOMMAND); wchar_t* wc = malloc(sizeof(wchar_t) * (ll+1)); GetMenuString(m->parent, m->command, wc, ll+1, MF_BYCOMMAND); wc[ll]=0; wchar_t* z = wcschr(wc, 8); if (z) *z=0; return wc; }
BOOL ExportImage( HWND hWnd, ITEMID idItem, ITEMID idIniSection ) { HINSTANCE hInstance; STRING szAppName, szIniSection; STRING szExportName; BOOL bSuccess = FALSE; // Get the name of export filter if ( !(GetMenuString( GetMenu(hWnd), idItem, szAppName, sizeof(szAppName), MF_BYCOMMAND )) ) { return( FALSE ); } // Get the name of the INI section to read hInstance = GetWindowInstance( hWnd ); if ( !AstralStrEx( idIniSection, szIniSection, sizeof(szIniSection) )) { return( FALSE ); } // Get the module file name for the application // Put it in a staic string so the callback has access to it if ( !(GetProfileString( szIniSection, szAppName, "", szExportName, sizeof(szExportName) )) ) { return( FALSE ); } bSuccess = ExportImageDLL( (LPSTR)szExportName ); return( bSuccess ); }
void menucpy(HMENU hTargetMenu, HMENU hSourceMenu) { int n, id, nMn; TCHAR * strBuf; HMENU hSubMenu; nMn = GetMenuItemCount(hSourceMenu); strBuf = (TCHAR *)LocalAlloc(LPTR, 80); for (n=0; n<nMn; n++) { if (0 == (id = GetMenuItemID(hSourceMenu, n))) AppendMenu(hTargetMenu, MF_SEPARATOR, 0, 0L); else { GetMenuString(hSourceMenu, n, strBuf, 80, MF_BYPOSITION); if (id != -1) AppendMenu(hTargetMenu, GetMenuState(hSourceMenu, n, MF_BYPOSITION), id, strBuf); else { hSubMenu = CreatePopupMenu(); AppendMenu(hTargetMenu, MF_POPUP | MF_STRING, (uint)hSubMenu, strBuf); menucpy(hSubMenu, GetSubMenu(hSourceMenu, n)); } } } LocalFree((HLOCAL)strBuf); }
void COwnMenu::MakeItemsOwnDraw(BOOL bFirst) { int iMaxItems = GetMenuItemCount(); for(int i = 0; i < iMaxItems; i++) { CString nameHolder; MenuObject* pObject = new MenuObject; deleteItem.push_back((DWORD)pObject); pObject->m_hIcon = NULL; pObject->bFirstMenu = bFirst; GetMenuString(i, pObject->m_strCaption, MF_BYPOSITION); MENUITEMINFO mInfo; ZeroMemory(&mInfo, sizeof(MENUITEMINFO)); UINT uID = mInfo.wID; //I dont use GetMenuItemID because it doesn't return 0/-1 when it's a Popup (so the MSDN is wrong) ModifyMenu(i, MF_BYPOSITION | MF_OWNERDRAW, uID, (char*)pObject); if(GetSubMenu(i)) { COwnMenu* pSubMenu = new COwnMenu; deleteMenu.push_back((DWORD)pSubMenu); pSubMenu->Attach(GetSubMenu(i)->GetSafeHmenu()); pSubMenu->MakeItemsOwnDraw(); } } }
//=========================================================================== void ContextMenu::Copymenu(HMENU hm) { TCHAR text_string[256]; for (int i = 0; i < GetMenuItemCount(hm); i++) { MENUITEMINFO info; ZeroMemory(&info, sizeof(info)); info.cbSize = sizeof(MENUITEMINFO_0400); // to make this work on win95 info.fMask = MIIM_DATA|MIIM_ID|MIIM_SUBMENU|MIIM_TYPE; GetMenuItemInfo (hm, i, TRUE, &info); text_string[0]=0; if (0 == (info.fType & MFT_OWNERDRAW)) GetMenuString(hm, i, text_string, 128, MF_BYPOSITION); //TCHAR buffer[256]; _stprintf(buffer, _T("%d %s"), info.wID, text_string); _tcscpy(text_string, buffer); Menu *CM = NULL; if (info.hSubMenu) { wc->HandleMenuMsg(WM_INITMENUPOPUP, (WPARAM)info.hSubMenu, MAKELPARAM(i, FALSE)); CM = new ContextMenu(text_string, wc, info.hSubMenu, 0); } else if (info.fType & MFT_SEPARATOR) { //MakeMenuNOP(this, NULL); continue; } MenuItem *CI = new ContextItem(CM, text_string, info.wID, info.dwItemData, info.fType); AddMenuItem(CI); } }
void GetCodeTitle( LPEVENTINFOS2 eiPtr, short code, short param, short mn, LPSTR strBuf, WORD maxLen ) { HMENU hMn; // Finds event in array eiPtr=GetEventInformations(eiPtr, code); // If a special string is to be returned short strID = EVINFO2_PARAMTITLE(eiPtr, param); if ( strID != 0 ) LoadString(hInstLib, strID, strBuf, maxLen); else { // Otherwise, returns the menu option if ((hMn = LoadMenu(hInstLib, MAKEINTRESOURCE(mn))) != NULL ) { GetMenuString(hMn, eiPtr->menu, strBuf, maxLen, MF_BYCOMMAND); DestroyMenu(hMn); } } }
HMENU fsODMenu::CopyMenu(HMENU hMenu) { HMENU hCopy = CreateMenu (); for (int i = 0; i < GetMenuItemCount (hMenu); i++) { UINT uState = GetMenuState (hMenu, i, MF_BYPOSITION); UINT nID; char szMenuText [100]; if (uState & MF_POPUP) { nID = (UINT) CopyMenu (GetSubMenu (hMenu, i)); uState = MF_POPUP | MF_STRING; } else nID = GetMenuItemID (hMenu, i); GetMenuString (hMenu, i, szMenuText, sizeof (szMenuText), MF_BYPOSITION); AppendMenu (hCopy, uState, nID, szMenuText); } return hCopy; }
/* * MenuAddLanguage: Add given language to Language menu. */ void MenuAddLanguage(int lang_id) { int num, index, len; char item_name[MAXRSCSTRING + 1], *name = NULL; if (lang_id > MAX_LANGUAGE_ID) return; num = GetMenuItemCount(language_menu); for(int i = 0; i < MAX_LANGUAGE_ID; i++) if(language_id_table[i].languageid == lang_id) { name = language_id_table[i].language_name; break; } // Add in sorted order. for (index = 0; index < num; index++) { len = GetMenuString(language_menu, index, item_name, MAXRSCSTRING, MF_BYPOSITION); if (len == 0) continue; if (stricmp(item_name, name) >= 0) break; } // Check for adding to end of list. if (index == num) index = -1; InsertMenu(language_menu, index, MF_STRING | MF_BYPOSITION, ID_LANGUAGE + lang_id, name); }
/* * Function: Save the items on the file menu in the KERBEROS.INI file. * * Parameters: * hwnd - handle of the dialog containing the file menu. */ static void kwin_save_file_menu(HWND hwnd) { HMENU hmenu; int i; int id; int ctitems; char menuitem[MAX_K_NAME_SZ + 3]; hmenu = GetMenu(hwnd); assert(hmenu != NULL); hmenu = GetSubMenu(hmenu, 0); assert(hmenu != NULL); ctitems = GetMenuItemCount(hmenu); assert(ctitems >= FILE_MENU_ITEMS); id = 0; for (i = FILE_MENU_ITEMS + 1; i < ctitems; i++) { GetMenuString(hmenu, i, menuitem, sizeof(menuitem), MF_BYPOSITION); strcpy(cns_res.logins[id], menuitem + 3); id++; } }
// find sorted position after the last separator int FindSortedPos(HMENU hMenu, const char* text) { int pos = -1, nbItems = GetMenuItemCount(hMenu); #ifdef _WIN32 wchar_t widetext[4096], widebuf[4096]; MultiByteToWideChar(CP_UTF8, 0, text, -1, widetext, 4096); _locale_t locale = _create_locale(LC_ALL, ""); #else char buf[4096] = ""; #endif MENUITEMINFO mi = {sizeof(MENUITEMINFO),}; mi.fMask = MIIM_TYPE; for (int i=nbItems-1; i>=0 ; i--) { GetMenuItemInfo(hMenu, i, true, &mi); if (mi.fType == MFT_SEPARATOR) break; #ifdef _WIN32 GetMenuStringW(hMenu, i, widebuf, 4096, MF_BYPOSITION); if (_wcsnicoll_l(widetext, widebuf, 4096, locale) < 0) // setLocale() can break things (atof and comma as a decimal mark) so use temporary locale object pos = i; #else GetMenuString(hMenu, i, buf, sizeof(buf), MF_BYPOSITION); if (strcasecmp(text, buf) < 0) // not as good as on Win OS, e.g. French "Sélectionner" vs "Supprimer" pos = i; #endif } #ifdef _WIN32 _free_locale(locale); #endif return pos<0 ? nbItems : pos; }
BOOL CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HMENU hMenu; switch (message) { case WM_CLOSE: DestroyWindow(hWnd); PostQuitMessage(0); return TRUE; case WM_INITDIALOG: hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1)); // Присоединим меню к главному окну приложения SetMenu(hWnd, hMenu); return TRUE; case WM_COMMAND: { TCHAR str1[300], str2[50]; HMENU hMenu = GetMenu(hWnd); GetMenuString(hMenu, LOWORD(wParam), str2, 50, MF_BYCOMMAND); if (HIWORD(wParam) == 1) _tcscpy_s(str1,300, TEXT("Пункт меню выбран с помощью акселератора\n")); else if (HIWORD(wParam) == 0) _tcscpy_s(str1,300, TEXT("Пункт меню выбран при непосредственном обращении к меню\n")); _tcscat_s(str1,300, str2); MessageBox(hWnd, str1, TEXT("Меню и акселераторы"), MB_OK | MB_ICONINFORMATION); } return TRUE; } return FALSE; }
VOID NEAR PASCAL BiasMenu(HMENU hMenu, INT Bias) { INT pos, id, count; HMENU hSubMenu; CHAR szMenuString[80]; ENTER("BiasMenu"); count = GetMenuItemCount(hMenu); if (count < 0) return; for (pos = 0; pos < count; pos++) { id = GetMenuItemID(hMenu, pos); if (id < 0) { // must be a popup, recurse and update all ID's here if (hSubMenu = GetSubMenu(hMenu, pos)) BiasMenu(hSubMenu, Bias); } else if (id) { // replace the item that was there with a new // one with the id adjusted GetMenuString(hMenu, (WORD)pos, szMenuString, sizeof(szMenuString), MF_BYPOSITION); DeleteMenu(hMenu, pos, MF_BYPOSITION); InsertMenu(hMenu, (WORD)pos, MF_BYPOSITION | MF_STRING, id + Bias, szMenuString); } } LEAVE("BiasMenu"); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 通知消息 VOID CChildWnd::OnNotify(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch ((uMsg == WM_NOTIFY) ? ((LPNMHDR) lParam)->code : uMsg) { case TTN_NEEDTEXT: // 显示工具栏提示 GetMenuString(CMainWnd::m_hMenu, (UINT) wParam, ((LPTOOLTIPTEXT) lParam)->szText, 80, MF_BYCOMMAND); case WM_MENUSELECT: // 在状态栏显示相应的菜单项提示 CLanguage::TranslateString(LOWORD(wParam)); if (CLanguage::m_tzText[0]) { SetStatusText(hWnd, CLanguage::m_tzText); break; } case TTN_POP: case WM_EXITMENULOOP: // 在状态栏显示“就绪” SetStatusText(hWnd, LNG_Ready); break; case NM_CLICK: if (((LPNMHDR) lParam)->idFrom == IDC_StatusBar) { GetWnd(hWnd)->OnClickStatusBar((UINT) ((LPNMMOUSE) lParam)->dwItemSpec); } break; } }
BOOL CRecBinViewer::ExecCommand (LPCONTEXTMENU pCtxMenu, LPCTSTR lpszCommand) { UINT uiID = UINT (-1); UINT uiCommand = 0; UINT uiMenuFirst = 1; UINT uiMenuLast = 0x00007FFF; HMENU hmenuCtx; int iMenuPos = 0; int iMenuMax = 0; TCHAR szMenuItem[MAX_PATH]; TCHAR verb[MAX_PATH] ; hmenuCtx = CreatePopupMenu(); HRESULT hr = pCtxMenu->QueryContextMenu(hmenuCtx, 0, uiMenuFirst, uiMenuLast, CMF_NORMAL); iMenuMax = GetMenuItemCount(hmenuCtx); for (iMenuPos = 0 ; iMenuPos < iMenuMax; iMenuPos++) { GetMenuString(hmenuCtx, iMenuPos, szMenuItem, MAX_PATH, MF_BYPOSITION) ; uiID = GetMenuItemID(hmenuCtx, iMenuPos) ; if ((uiID == -1) || (uiID == 0)) { } else { hr = pCtxMenu->GetCommandString(uiID - 1, GCS_VERB, NULL, (LPSTR)verb, MAX_PATH); if (FAILED (hr)) { verb[0] = TCHAR ('\0') ; } else { if (0 == _tcsicmp (verb, lpszCommand)) uiCommand = uiID - 1; } } } if ((UINT)-1 != uiCommand) { CMINVOKECOMMANDINFO cmi; ZeroMemory(&cmi, sizeof(CMINVOKECOMMANDINFO)); cmi.cbSize = sizeof(CMINVOKECOMMANDINFO); cmi.fMask = CMIC_MASK_FLAG_NO_UI; cmi.hwnd = m_hWnd; cmi.lpVerb = (LPSTR)MAKEINTRESOURCE (uiCommand); cmi.nShow = SW_SHOWNORMAL; hr = pCtxMenu->InvokeCommand(&cmi); if (SUCCEEDED (hr)) return TRUE; } return false; }
LRESULT CALLBACK oof(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { NMHDR *hdr = (NMHDR *)lParam; switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case 6666: if(HIWORD(wParam) == CBN_EDITCHANGE) { TCHAR wstr[64]; BYTE buf[64]; int len; GetWindowText((HWND)lParam, wstr, 64); len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, (char *)buf, 64, 0, 0); HexView_SetSearchPattern(g_hwndHexView, buf, len - 1); InvalidateRect(g_hwndHexView, 0, 0); return 0; } return 0; } return 0; case WM_NOTIFY: if(hdr->code == TBN_DROPDOWN) { RECT rect; HMENU hMenu; int cmd; TCHAR buf[20]; TBBUTTONINFO tbbi = { sizeof(tbbi) }; hMenu = LoadMenu(0, MAKEINTRESOURCE(IDR_SEARCHBAR_FINDTYPE)); hMenu = GetSubMenu(hMenu, 0); SendMessage(hdr->hwndFrom, TB_GETITEMRECT, 0, (LPARAM)&rect); MapWindowPoints(hdr->hwndFrom, 0, (POINT *)&rect, 2); cmd = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_NONOTIFY, rect.left, rect.bottom, 0, hwnd, 0); if(cmd != 0) { GetMenuString(hMenu, cmd, buf, 20, MF_BYCOMMAND); tbbi.dwMask = TBIF_COMMAND|TBIF_TEXT; tbbi.idCommand = IDM_FILE_OPEN; tbbi.pszText = buf; SendMessage(hdr->hwndFrom, TB_SETBUTTONINFO, IDM_FILE_OPEN, (LPARAM)&tbbi); } return TBDDRET_DEFAULT; } break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
static void setupSystemMenu( HWND hwnd ) { HMENU smh; HMENU mh; char menuname[256]; smh = GetSystemMenu( hwnd, FALSE ); mh = GetMenu( hwnd ); AppendMenu( smh, MF_SEPARATOR, 0,NULL ); GetMenuString( mh, MENU_LOG_CURRENT_STATE, menuname, sizeof( menuname ), MF_BYCOMMAND ); AppendMenu( smh, MF_ENABLED, MENU_LOG_CURRENT_STATE, menuname ); GetMenuString( mh, MENU_LOG_OPTIONS, menuname, sizeof( menuname ), MF_BYCOMMAND ); AppendMenu( smh, MF_ENABLED, MENU_LOG_OPTIONS, menuname ); GetMenuString( mh, MENU_TASK_CTL, menuname, sizeof( menuname ), MF_BYCOMMAND ); AppendMenu( smh, MF_ENABLED, MENU_TASK_CTL, menuname ); }
/****************************************************************************** * void SetMruMenu(HWND hwnd) * * update the mru menu items according to the changed mru list * * parameters: * hwnd - window handle of window with mru menu items * * notes: * The mru list appears in the File menu for the window's menu bar. * The file menu can be the first (0th) or second (1th) by_position * depending on whether the mdi child is maximized (see mmenu.c MenuStatus()). * * Assumes the file menu last two items initially are a separator followed * by a menu item (exit). Inserts mru items following the separator followed * by a new separator. ******************************************************************************/ static void SetMruMenu(HWND hwnd) { char sz[sizeof("&1 ") + _MAX_PATH]; char *psz; HMENU hMenu = GetMenu(hwnd); int i; int nExit; /* find the File menu */ assert(hMenu != 0); if ( hMenu == 0 ) return; GetMenuString(hMenu, 1, sz, sizeof(sz), MF_BYPOSITION); if ( stricmp(sz, "&File") == 0 ) hMenu = GetSubMenu(hMenu, 1); else hMenu = GetSubMenu(hMenu, 0); assert(hMenu != 0); if ( hMenu == 0 ) return; /* delete any mru items presently in the file menu */ for ( i = 0; i < MAX_MRUFILES; i++ ) DeleteMenu(hMenu, IDM_FILE_MRUFILE1 + i, MF_BYCOMMAND); /* if the 3rd entry from the bottom is a separator, then we assume it's the one we inserted for the mru section, and delete it (to be reinserted below) */ i = GetMenuItemCount(hMenu); nExit = GetMenuItemID(hMenu, i - 1); if ( GetMenuItemID(hMenu, i - 3) == 0 ) DeleteMenu(hMenu, i - 3, MF_BYPOSITION); if ( arszMruFilenames[0][0] != '\0' ) { /* insert mru file names */ for ( i = 0; i < MAX_MRUFILES && *arszMruFilenames[i] != '\0'; i++ ) { wsprintf(sz, "&%d ", i + 1); psz = sz + strlen(sz); MiscShortFilename( arszMruFilenames[i], psz, sizeof("C:\\...\\PATHNAME.EXT\\FILENAME.EXT") - 1); InsertMenu( hMenu, nExit, MF_BYCOMMAND | MF_STRING, IDM_FILE_MRUFILE1 + i, sz ); } /* (re)insert separator preceding File/Exit */ InsertMenu(hMenu, nExit, MF_BYCOMMAND | MF_SEPARATOR, 0, 0); } }
void CUserMeetingDlg::PutIntoPhone(HMENU hMenu, UINT nMenuId) { CString strValue; GetMenuString( hMenu, nMenuId, strValue.GetBuffer(32), 32, MF_BYCOMMAND ); strValue.ReleaseBuffer(); int nPos = strValue.Find( '\t' ); PutIntoPhone( nPos == -1 ? strValue : strValue.Mid( nPos + 1 ), nPos == -1 ? "" : strValue.Left( nPos ) ); }
void CUIEditorView::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu) { CView::OnMenuSelect(nItemID, nFlags, hSysMenu); char szString[256] = {0}; GetMenuString(hSysMenu, nItemID, szString, 255, 0); if(strlen(szString) > 0) { setWindowSelected((CEGUI::utf8*)szString,false); } }
HMENU CUserMeetingDlg::FindMenuGroup(HMENU hParent, LPCTSTR lpszMenu) { for ( int nItem = GetMenuItemCount( hParent ); nItem > 0; nItem-- ) { TCHAR strItem[64]; GetMenuString( hParent, nItem - 1, strItem, 64, MF_BYPOSITION ); if ( ! _tcsicmp( strItem, lpszMenu ) ) return GetSubMenu( hParent, nItem - 1 ); } return NULL; }
void CUserMeetingDlg::PutIntoPhone(HMENU hMenu, int nPos, int nCount) { for ( int nItem = nPos ; nItem < nCount ; nItem ++ ) { CString strValue; GetMenuString( hMenu, nItem, strValue.GetBuffer(32), 32, MF_BYPOSITION ); strValue.ReleaseBuffer(); int nPos = strValue.Find( '\t' ); PutIntoPhone( nPos == -1 ? strValue : strValue.Mid( nPos + 1 ), nPos == -1 ? "" : strValue.Left( nPos ) ); } }
/* using MIIM_STRING doesn't work for win9x/winnt4, so trying an older way */ void uikeyboard_menu_shortcuts(HMENU menu) { int i; int stringsize; LPTSTR buf, newbuf; for (i = 0; idmlist[i].cmd > 0; i++) { if (menuitemmodifier[idmlist[i].cmd] != NULL) { stringsize = GetMenuString(menu, idmlist[i].cmd, NULL, 0, MF_BYCOMMAND); if (stringsize != 0) { stringsize++; buf = lib_malloc(stringsize); if (GetMenuString(menu, idmlist[i].cmd, buf, stringsize, MF_BYCOMMAND)) { newbuf = util_concat(buf, menuitemmodifier[idmlist[i].cmd], NULL); ModifyMenu(menu, idmlist[i].cmd, MF_BYCOMMAND | MF_STRING, idmlist[i].cmd, newbuf); lib_free(newbuf); } lib_free(buf); } } } }
LRESULT CALLBACK MenuWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int id, cnt, mnu; PAINTSTRUCT ps; CHAR szString[256], *pszString; HDC hDC; RECT rc; POINT pt; HFONT hFont, hFontOld; HBRUSH hBrush, hBrushOld; LPMEASUREITEMSTRUCT lpMI = NULL; LPDRAWITEMSTRUCT lpDI = NULL; SIZE size; MENUITEMINFO mii = { sizeof(MENUITEMINFO),MIIM_CHECKMARKS|MIIM_TYPE|MIIM_SUBMENU }; NONCLIENTMETRICS nm; HMENU hMenu, hMenuTop; BOOL isMenuBar; static BOOL bFirst = TRUE; if (pOldWndProc == NULL) return DefWindowProc(hWnd, uMsg, wParam, lParam); hMenu = GetMenu(hWnd); if (bFirst == TRUE) { SetOwnerDraw(hMenu, TRUE); bFirst = FALSE; } switch(uMsg) { case WM_INITMENUPOPUP: if (HIWORD(lParam) == 0) SetOwnerDraw((HMENU)wParam, TRUE); break; case WM_MEASUREITEM: lpMI = (LPMEASUREITEMSTRUCT)lParam; GetMenuItemInfo((HMENU)hMenu, lpMI->itemID, FALSE, &mii); GetMenuString(hMenu, lpMI->itemID, szString, sizeof(szString), MF_BYCOMMAND); if (strlen(szString) == 0 && lpMI->itemData) strcpy(szString, (char*)lpMI->itemData); if ((mii.fType & MF_SEPARATOR) != 0 || ((mii.fType & MF_BITMAP) == 0 && strlen(szString) == 0)) { lpMI->itemHeight = GetSystemMetrics(SM_CYMENU) >> 1; lpMI->itemWidth = 0; } else if (mii.fType & MF_BITMAP)
/* * MenuSpellChosen: The spell with the given command id in the spell menu was chosen. */ void MenuSpellChosen(int id) { int len, num=0, index=0, i; char item_name[MAXRSCSTRING + 1]; spell *sp; HMENU submenu = NULL; if (spell_menu == NULL) return; for (i=0; i < num_schools; i++) { submenu = submenus[i]; if (submenu) { num = GetMenuItemCount(submenu); // Look for menu item matching command id for (index = 0; index < num; index++) { if (GetMenuItemID(submenu, index) == (UINT) id) break; } if (index != num) break; } } if (index == num) { debug(("MenuSpellChosen couldn't find menu id #%d\n", id)); return; } len = GetMenuString(submenu, index, item_name, MAXRSCSTRING, MF_BYPOSITION); if (len == 0) { debug(("MenuSpellChosen get spell #%d from menu\n", index)); return; } sp = FindSpellByName(item_name); if (sp == SPELL_NOMATCH || sp == SPELL_AMBIGUOUS) { debug(("MenuSpellChosen couldn't find spell %s\n", item_name)); return; } PerformAction(A_CASTSPELL, sp); }
void WdeInitToolMenu( HINSTANCE inst, HMENU menu ) { int i; for( i = 0; WdeMenuBitmaps[i].bmp != NULL; i++ ) { WdeMenuBitmaps[i].hbmp = LoadBitmap( inst, WdeMenuBitmaps[i].bmp ); GetMenuString( menu, WdeMenuBitmaps[i].id, WdeMenuBitmaps[i].string, 255, MF_BYCOMMAND ); if( WdeMenuBitmaps[i].hbmp != NULL ) { ModifyMenu( menu, WdeMenuBitmaps[i].id, MF_BYCOMMAND | MF_OWNERDRAW, WdeMenuBitmaps[i].id, (LPCSTR)&WdeMenuBitmaps[i] ); } } }
void InitTrayCBWnd(BOOL bCreate) { LONG i, lMMItemCnt, lTMItemCnt; if (bCreate) { WCHAR lpwText[MAX_PATH] = { 0 }; hTrayMenu = CreatePopupMenu(); AppendMenu(hTrayMenu, MF_STRING, IDM_TRAY_HIDESHOW, L"&Hide/Show Player"); AppendMenu(hTrayMenu, MF_SEPARATOR, 0, 0); lMMItemCnt = GetMenuItemCount(GetMenu(hMainWnd)); for (i = 0; i < lMMItemCnt; i++) { GetMenuString(GetMenu(hMainWnd), i, lpwText, MAX_PATH, MF_BYPOSITION); AppendMenu(hTrayMenu, MF_STRING | MF_POPUP, (UINT_PTR)GetSubMenu(GetMenu(hMainWnd), i), lpwText); } SetMenuDefaultItem(hTrayMenu, IDM_TRAY_HIDESHOW, FALSE); WCEX.cbSize = sizeof(WNDCLASSEX); WCEX.lpfnWndProc = (WNDPROC)TrayCBWndProc; WCEX.hInstance = hAppInstance; WCEX.hbrBackground = GetSysColorBrush(COLOR_3DFACE); WCEX.lpszClassName = TRAY_CB_WND_CLASS; RegisterClassEx(&WCEX); hTrayCBWnd = CreateWindow(WCEX.lpszClassName, 0, WS_POPUP, 16, 16, 32, 32, 0, hTrayMenu, hAppInstance, 0); if (!dwNoOwnerDrawMenu) { pEBMenuTray->hBmpCheck = (HBITMAP)LoadImage(hAppInstance, MAKEINTRESOURCE(IDB_CHECKMARK), IMAGE_BITMAP, 16, 16, 0); pEBMenuTray->hBmpRadioCheck = (HBITMAP)LoadImage(hAppInstance, MAKEINTRESOURCE(IDB_RADIOCHECKMARK), IMAGE_BITMAP, 16, 16, 0); pEBMenuTray->InitEBMenu(hTrayCBWnd, TRUE); } } else { if (!dwNoOwnerDrawMenu) pEBMenuTray->InitEBMenu(0); lMMItemCnt = GetMenuItemCount(GetMenu(hMainWnd)); lTMItemCnt = GetMenuItemCount(hTrayMenu); for (i = (lTMItemCnt - 1); i >= (lTMItemCnt - lMMItemCnt); i--) { RemoveMenu(hTrayMenu, i, MF_BYPOSITION); } DestroyMenu(hTrayMenu); hTrayMenu = 0; DestroyWindow(hTrayCBWnd); hTrayCBWnd = 0; } }
void SetOwnerDraw(HMENU hMenu, BOOL bMode) { int id, mnu; MENUITEMINFO mii = { sizeof(MENUITEMINFO),MIIM_CHECKMARKS|MIIM_TYPE|MIIM_DATA }; CHAR szString[256]; HMENU hSubMenu; if (hMenu == NULL) return; for(mnu = 0; mnu < GetMenuItemCount(hMenu); mnu++) { GetMenuItemInfo((HMENU)hMenu, mnu, TRUE, &mii); if (bMode) { mii.fType |= MFT_OWNERDRAW; if (mii.hSubMenu == NULL && (mii.fType & MF_SEPARATOR) == 0 && mii.dwItemData == 0) { LPSTR pCopy; GetMenuString(hMenu, mnu, szString, sizeof(szString), MF_BYPOSITION); pCopy = strdup(szString); if (pCopy) { mii.fMask |= MIIM_DATA; mii.dwItemData = (DWORD)pCopy; } } } else { mii.fType &= ~MFT_OWNERDRAW; if (mii.hSubMenu == NULL && (mii.fType & MF_SEPARATOR) == 0) { mii.fMask &= ~MIIM_DATA; if (mii.dwItemData) { free((LPSTR)mii.dwItemData); mii.dwItemData = 0; } } } SetMenuItemInfo(hMenu, mnu, TRUE, &mii); hSubMenu = GetSubMenu(hMenu, mnu); if (hSubMenu) SetOwnerDraw(hSubMenu, bMode); } }
// this one copies the menu without deleting the root BOOL CSkinBase::CopyMenu(const HMENU hScr, HMENU hDest) { ASSERT (::IsMenu(hDest)); if (!::IsMenu(hDest)) return FALSE; ASSERT (::IsMenu(hScr)); if (!::IsMenu(hScr)) return FALSE; // delete all the existing items while (GetMenuItemCount(hDest)) DeleteMenu(hDest, 0, MF_BYPOSITION); // copy across int nNumItems = GetMenuItemCount(hScr); CString sLabel; MENUITEMINFO mii; ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); // must fill up this field mii.fMask = MIIM_STATE | MIIM_DATA; // get the state of the menu item for (int nItem = 0; nItem < nNumItems; nItem++) { UINT uIDItem = GetMenuItemID(hScr, nItem); GetMenuString(hScr, nItem, sLabel, MF_BYPOSITION); UINT uFlags = (uIDItem == 0) ? MF_SEPARATOR : (uIDItem == (UINT)-1) ? MF_POPUP : MF_STRING; // special case: if a popup menu we must copy it too if (uFlags == MF_POPUP) { HMENU hPopup = MakeMenuCopy(GetSubMenu(hScr, nItem)); ASSERT (hPopup); uIDItem = (UINT)hPopup; } AppendMenu(hDest, uFlags, uIDItem, sLabel); // make sure we copy the state too ::GetMenuItemInfo(hSrc, nItem, TRUE, &mii); ::SetMenuItemInfo(hDest, nItem, TRUE, &mii); } return TRUE; }
LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_NCPAINT: { // add a menu to the fs window HMENU hFSMenu; hFSMenu = GetMenu(hwnd); if( hFSMenu!=NULL ) { int i; // Look for our menu entry in the main menu. for( i=0; i<GetMenuItemCount(hFSMenu); i++ ) { char buf[128]; GetMenuString( hFSMenu, i, buf, 128, MF_BYPOSITION ); if( strcmp(buf, MENU_ENTRY)==0 ) { // It is already here, we do not need to add it again break; } } if( i<GetMenuItemCount(hFSMenu) ) { // It is already here, we do not need to add it again break; } /* Create new menu. NOTE: It seems that this will be * reached more times, so we cannot save the handle, because * in such case it could be destroyed and we will not have * any access to it in the simulator. */ // add the created menu to the main menu AppendMenu(hFSMenu, MF_STRING | MF_POPUP, (UINT_PTR)uiThread->ui->newMenu(), MENU_ENTRY); } }break; case WM_COMMAND: { if( LOWORD(wParam)>=ID_FIRST && LOWORD(wParam)<=ID_LAST ) uiThread->postThreadMessage( uMsg, wParam, lParam ); else switch( LOWORD(wParam) ) { case ID_ASYNC: uiThread->ui->async(); //dout << "async" << std::endl; break; } } break; } // Call the original window procedure to handle all other messages return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam); }
// returns -1 if not found int GetMenuItemIndex(HMENU hMenu, const char* ItemName) { int index = 0; char buf[256]; while(index < GetMenuItemCount(hMenu)) { if(GetMenuString(hMenu, index, buf, sizeof(buf)-1, MF_BYPOSITION)) { if(!strcmp(ItemName, buf)) return index; } index++; } return -1; }