Ihandle* iupwinMenuGetHandle(HMENU hMenu) { MENUINFO menuinfo; menuinfo.cbSize = sizeof(MENUINFO); menuinfo.fMask = MIM_MENUDATA; if (GetMenuInfo(hMenu, &menuinfo)) return (Ihandle*)menuinfo.dwMenuData; else return NULL; }
LRESULT menu_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITMENUPOPUP: { HMENU hmenu = (HMENU)wparam; struct menu_item* item; MENUINFO mi; mi.cbSize = sizeof(mi); mi.fMask = MIM_MENUDATA; GetMenuInfo(hmenu, &mi); item = (struct menu_item*)mi.dwMenuData; if (item) fill_menu(item); return 0; } break; case WM_MENUCOMMAND: { HMENU hmenu = (HMENU)lparam; struct menu_item* item; MENUITEMINFOW mii; mii.cbSize = sizeof(mii); mii.fMask = MIIM_DATA|MIIM_ID; GetMenuItemInfoW(hmenu, wparam, TRUE, &mii); item = (struct menu_item*)mii.dwItemData; if (item) exec_item(item); else if (mii.wID == MENU_ID_RUN) run_dialog(); destroy_menus(); return 0; } } return DefWindowProcW(hwnd, msg, wparam, lparam); }
/* * Sets the menubar into the mIRC window, and automatically destroys the old menubar * if it isnt the original mIRC menubar. */ void XMenuBar::setMenuBar(HMENU oldMenuBar, HMENU newMenuBar) { if (newMenuBar != g_OriginalMenuBar) { MENUINFO mi; ZeroMemory(&mi, sizeof(MENUINFO)); mi.cbSize = sizeof(MENUINFO); mi.fMask = MIM_BACKGROUND | MIM_HELPID | MIM_MAXHEIGHT | MIM_MENUDATA | MIM_STYLE; GetMenuInfo(oldMenuBar, &mi); SetMenuInfo(newMenuBar, &mi); } SetMenu(Dcx::mIRC.getHWND(), newMenuBar); // Go through old menubar items and detach them VectorOfXPopupMenu temp; VectorOfXPopupMenu::iterator itStart = this->m_vpXMenuBar.begin(); VectorOfXPopupMenu::iterator itEnd = this->m_vpXMenuBar.end(); // Add menus to a temporary list to prevent errors in looping while (itStart != itEnd) { temp.push_back(*itStart); ++itStart; } itStart = temp.begin(); itEnd = temp.end(); // Begin detaching ... while (itStart != itEnd) { (*itStart)->detachFromMenuBar(oldMenuBar); ++itStart; } // Destroy the menu if it isnt the original mIRC menubar. if (g_OriginalMenuBar == NULL) g_OriginalMenuBar = oldMenuBar; else DestroyMenu(oldMenuBar); DrawMenuBar(Dcx::mIRC.getHWND()); }
static LPFMINFO FM_GetMenuInfo(HMENU hmenu) { MENUINFO MenuInfo; LPFMINFO menudata; MenuInfo.cbSize = sizeof(MENUINFO); MenuInfo.fMask = MIM_MENUDATA; if (! GetMenuInfo(hmenu, &MenuInfo)) return NULL; menudata = (LPFMINFO)MenuInfo.dwMenuData; if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO))) { ERR("menudata corrupt: %p %u\n", menudata, MenuInfo.cbSize); return 0; } return menudata; }
LRESULT CALLBACK BaseWindow::baseWndProc(HWND hwnd, UINT mess, WPARAM wParam, LPARAM lParam) { BaseWindow *instance = NULL; BaseWindow *childInstance = NULL; if ( mess == WM_CREATE ) { //ottengo il puntatore this CREATESTRUCT *cStruct = (CREATESTRUCT*)lParam; instance = (BaseWindow*)cStruct->lpCreateParams; if ( instance ) //salvo il puntatore nello spazio utente della window SetWindowLongPtr(hwnd,GWLP_USERDATA, (LONG_PTR)instance); return TRUE; } else { //verifico la notifica di un child if ( mess == NOTIFY_CHILD_CREATION ) { //un child notifica la propria creazione HWND tmpHwnd = (HWND)wParam; childInstance = (BaseWindow*)lParam; if ( childInstance && tmpHwnd ) { //salvo il this sullo spazio utente della hwnd SetWindowLongPtr(tmpHwnd, GWLP_USERDATA, (LONG_PTR)childInstance); } } else if ( mess == WM_COMMAND || mess == WM_HSCROLL || mess == WM_VSCROLL ) { instance = BaseWindow::getInstance((HWND)lParam); } else if ( mess == WM_NOTIFY ) { LPNMHDR data = (LPNMHDR)lParam; instance = BaseWindow::getInstance(data->hwndFrom); } else if ( mess == WM_MENUCOMMAND ) { //messaggio da un menu con MF_BYPOSITION HMENU menu = (HMENU)lParam; MENUINFO info; memset(&info,0,sizeof(MENUINFO)); info.fMask = MIM_MENUDATA; info.cbSize = sizeof(MENUINFO); GetMenuInfo(menu,&info); instance = (BaseWindow*)info.dwMenuData; } /*else if ( mess == WM_CLOSE ) { instance = BaseWindow::getInstance(hwnd); if ( instance && instance->closeList ) return instance->closeList->onClose(instance->idWin, instance->getHWND()); } */ else instance = BaseWindow::getInstance(hwnd); if ( instance ) return instance->wndProc(mess, wParam, lParam); else return DefWindowProc(hwnd, mess, wParam, lParam); } }
/********************************************************************* ** ** Adds a new menu item to a menu. ** ** Position is the position of the new menu item. If position is -1, ** the menu item is inserted as the last item. ** **********************************************************************/ BOOL __far __pascal MyInsertMenu ( HWND hDataWnd, LPSTR lpMenuID, LPSTR lpItemID, LPSTR lpItemText, LPSTR lpMacro, short int Position ) { HMENUSYS hMenuSys; FPMENUSYS MenuSysPtr; /* Menu info. to store in menu info. list. */ MENUINFO MenuInfo, MenuItemInfo; BOOL bReturn; /* Pointer to macro string. */ char __far * MacroStringPtr; /* Get the menu sys. data */ hMenuSys = (HMENUSYS) WndData( hDataWnd, WDM_GETMENUSYS, 0, NULL ); /* Lock menu sys. data. */ MenuSysPtr = ( FPMENUSYS ) GlobalLock( hMenuSys ); /* Menubar does not even exist. */ if( MenuSysPtr->hMenuBar == NULL ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUDOESNOTEXIST, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* Find the menu that the item will be added to. */ if( GetMenuInfo( MenuSysPtr->hMenuList, lpMenuID, &MenuInfo ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUDOESNOTEXIST, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* Verify that the new menu's ID string is unique. */ if( GetMenuInfo( MenuSysPtr->hMenuList, lpItemID, &MenuItemInfo ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUALREADYEXISTS, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* Allocate memory for storage of macro string. */ if( !GlobalAllocMem( hDataWnd, &(MenuItemInfo).hMacroString, _fstrlen( lpMacro ) + sizeof(char) ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* Failure. */ return( FALSE ); } /* Copy macro string storage area. */ MacroStringPtr = (char __far *) GlobalLock( MenuItemInfo.hMacroString ); _fstrcpy( MacroStringPtr, lpMacro ); GlobalUnlock( MenuItemInfo.hMacroString ); /* Init. the other menu item info. */ MenuItemInfo.MenuID = AddAtom( lpItemID ); MenuItemInfo.hMenu = NULL; MenuItemInfo.hParentMenu = MenuInfo->hMenu; MenuItemInfo.hMacroString = NULL; /* Add the menu item to the menu. */ if( ! InsertMenu( MenuInfo->hMenu, Position, MF_BYPOSITION | MF_ENABLED | MF_STRING, MenuItemInfo.MenuID, lpItemText) ) { /* Delete allocated info. */ DeleteAtom( MenuItemInfo.ButtonID ); GlobalFree( MenuItemInfo.hMacroString ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( FALSE ); } /* Save the menu info. */ bReturn = SaveMenuInfo( hDataWnd, &(MenuSysPtr)->hMenuList, (FPMENUINFO) &MenuInfo ); if( bReturn == FALSE ) { /* Delete allocated info. */ DeleteAtom( MenuItemInfo.ButtonID ); GlobalFree( MenuItemInfo.hMacroString ); /* Remove the new menu item. */ RemoveMenu( MenuInfo->hMenu, Position, MF_BYPOSITION ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Failure. */ return FALSE; } /* Show changes. */ DrawMenuBar( MenuSysPtr->hMenuBar ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( TRUE ); }
/********************************************************************* ** ** Adds a new popup menu to the list and to the menu bar. ** ** Position is the position of the new menu. If position is -1, ** the menu is inserted as the last item. ** **********************************************************************/ BOOL __far __pascal MyCreatePopup ( HWND hDataWnd, LPSTR lpMenuID, LPSTR lpMenuText, short int Position ) { HMENUSYS hMenuSys; FPMENUSYS MenuSysPtr; /* Menu info. to store in menu info. list. */ MENUINFO MenuInfo; BOOL bReturn; BOOL bCreatedBar; /* Get the menu sys. data */ hMenuSys = (HMENUSYS) WndData( hDataWnd, WDM_GETMENUSYS, 0, NULL ); /* Lock menu sys. data. */ MenuSysPtr = ( FPMENUSYS ) GlobalLock( hMenuSys ); /* Verify that the new menu's ID string is unique. */ if( GetMenuInfo( MenuSysPtr->hMenuList, lpMenuID, &MenuInfo ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUALREADYEXISTS, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* If there is no menu bar the create one and set it. */ if( MenuSysPtr->hMenuBar == NULL ) { /* Create the menu bar. */ MenuSysPtr->hMenuBar = CreateMenu(); bCreatedBar = TRUE; /* Error. */ if( MenuSysPtr->hMenuBar == NULL ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } SetMenu( hDataWnd, MenuSysPtr->hMenuBar ); } else bCreatedBar = FALSE; /* Create the popup menu. */ MenuInfo.hMenu = CreatePopupMenu(); if( MenuInfo.hMenu == NULL ) { /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* If just created the bar. */ if( bCreatedBar == TRUE ) { /* Remove the bar. */ SetMenu( hDataWnd, NULL ); DestroyMenu( MenuSysPtr->hMenuBar ); MenuSysPtr->hMenuBar = NULL; } /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( FALSE ); } /* Add the menu to the menu bar. */ if( ! InsertMenu( MenuSysPtr->hMenuBar, Position, MF_BYPOSITION | MF_ENABLED | MF_STRING | MF_POPUP, (UINT) MenuInfo.hMenu, lpMenuText) ) { /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* If just created the bar. */ if( bCreatedBar == TRUE ) { /* Remove the bar. */ SetMenu( hDataWnd, NULL ); DestroyMenu( MenuSysPtr->hMenuBar ); MenuSysPtr->hMenuBar = NULL; } /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( FALSE ); } /* Init. the other menu info. */ MenuInfo.MenuID = AddAtom( lpMenuID ); MenuInfo.hParentMenu = MenuSysPtr->hMenuBar; MenuInfo.hMacroString = NULL; /* Save the menu info. */ bReturn = SaveMenuInfo( hDataWnd, &(MenuSysPtr)->hMenuList, (FPMENUINFO) &MenuInfo ); if( bReturn == FALSE ) { /* Remove the new menu from the menu bar. */ RemoveMenu( MenuSysPtr->hMenuBar, Position, MF_BYPOSITION ); DestroyMenu( MenuInfo.hMenu ); /* If just created the bar. */ if( bCreatedBar == TRUE ) { /* Remove the bar. */ SetMenu( hDataWnd, NULL ); DestroyMenu( MenuSysPtr->hMenuBar ); MenuSysPtr->hMenuBar = NULL; } /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Failure. */ return FALSE; } /* Show changes. */ DrawMenuBar( MenuSysPtr->hMenuBar ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( TRUE ); }
/************************************************************************* * FileMenu_AppendItem [SHELL32.115] * */ static BOOL FileMenu_AppendItemW( HMENU hMenu, LPCWSTR lpText, UINT uID, int icon, HMENU hMenuPopup, int nItemHeight) { MENUITEMINFOW mii; LPFMITEM myItem; LPFMINFO menudata; MENUINFO MenuInfo; TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n", hMenu, (lpText!=FM_SEPARATOR) ? debugstr_w(lpText) : NULL, uID, icon, hMenuPopup, nItemHeight); ZeroMemory (&mii, sizeof(MENUITEMINFOW)); mii.cbSize = sizeof(MENUITEMINFOW); if (lpText != FM_SEPARATOR) { int len = strlenW (lpText); myItem = SHAlloc(sizeof(FMITEM) + len*sizeof(WCHAR)); strcpyW (myItem->szItemText, lpText); myItem->cchItemText = len; myItem->iIconIndex = icon; myItem->hMenu = hMenu; mii.fMask = MIIM_DATA; mii.dwItemData = (ULONG_PTR) myItem; } if ( hMenuPopup ) { /* sub menu */ mii.fMask |= MIIM_TYPE | MIIM_SUBMENU; mii.fType = MFT_OWNERDRAW; mii.hSubMenu = hMenuPopup; } else if (lpText == FM_SEPARATOR ) { mii.fMask |= MIIM_ID | MIIM_TYPE; mii.fType = MFT_SEPARATOR; } else { /* normal item */ mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE; mii.fState = MFS_ENABLED | MFS_DEFAULT; mii.fType = MFT_OWNERDRAW; } mii.wID = uID; InsertMenuItemW (hMenu, (UINT)-1, TRUE, &mii); /* set bFixedItems to true */ MenuInfo.cbSize = sizeof(MENUINFO); MenuInfo.fMask = MIM_MENUDATA; if (! GetMenuInfo(hMenu, &MenuInfo)) return FALSE; menudata = (LPFMINFO)MenuInfo.dwMenuData; if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO))) { ERR("menudata corrupt: %p %u\n", menudata, MenuInfo.cbSize); return 0; } menudata->bFixedItems = TRUE; SetMenuInfo(hMenu, &MenuInfo); return TRUE; }
/************************************************************************* * FM_InitMenuPopup [internal] * */ static int FM_InitMenuPopup(HMENU hmenu, LPCITEMIDLIST pAlternatePidl) { IShellFolder *lpsf, *lpsf2; ULONG ulItemAttr = SFGAO_FOLDER; UINT uID, uEnumFlags; LPFNFMCALLBACK lpfnCallback; LPCITEMIDLIST pidl; WCHAR sTemp[MAX_PATH]; int NumberOfItems = 0, iIcon; MENUINFO MenuInfo; LPFMINFO menudata; TRACE("%p %p\n", hmenu, pAlternatePidl); MenuInfo.cbSize = sizeof(MENUINFO); MenuInfo.fMask = MIM_MENUDATA; if (! GetMenuInfo(hmenu, &MenuInfo)) return FALSE; menudata = (LPFMINFO)MenuInfo.dwMenuData; if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO))) { ERR("menudata corrupt: %p %u\n", menudata, MenuInfo.cbSize); return 0; } if (menudata->bInitialized) return 0; pidl = (pAlternatePidl? pAlternatePidl: menudata->pidl); if (!pidl) return 0; uID = menudata->uID; uEnumFlags = menudata->uEnumFlags; lpfnCallback = menudata->lpfnCallback; menudata->bInitialized = FALSE; SetMenuInfo(hmenu, &MenuInfo); if (SUCCEEDED (SHGetDesktopFolder(&lpsf))) { if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2))) { IEnumIDList *lpe = NULL; if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe ))) { LPITEMIDLIST pidlTemp = NULL; ULONG ulFetched; while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched))) { if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, (LPCITEMIDLIST*)&pidlTemp, &ulItemAttr))) { ILGetDisplayNameExW(NULL, pidlTemp, sTemp, ILGDN_FORPARSING); if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon))) iIcon = FM_BLANK_ICON; if ( SFGAO_FOLDER & ulItemAttr) { LPFMINFO lpFmMi; MENUINFO MenuInfo; HMENU hMenuPopup = CreatePopupMenu(); lpFmMi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO)); lpFmMi->pidl = ILCombine(pidl, pidlTemp); lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS; MenuInfo.cbSize = sizeof(MENUINFO); MenuInfo.fMask = MIM_MENUDATA; MenuInfo.dwMenuData = (ULONG_PTR) lpFmMi; SetMenuInfo (hMenuPopup, &MenuInfo); FileMenu_AppendItemW (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT); } else { LPWSTR pExt = PathFindExtensionW(sTemp); if (pExt) *pExt = 0; FileMenu_AppendItemW (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT); } } if (lpfnCallback) { TRACE("enter callback\n"); lpfnCallback ( pidl, pidlTemp); TRACE("leave callback\n"); } NumberOfItems++; } IEnumIDList_Release (lpe); } IShellFolder_Release(lpsf2); } IShellFolder_Release(lpsf); } if ( GetMenuItemCount (hmenu) == 0 ) { static const WCHAR szEmpty[] = { '(','e','m','p','t','y',')',0 }; FileMenu_AppendItemW (hmenu, szEmpty, uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT); NumberOfItems++; } menudata->bInitialized = TRUE; SetMenuInfo(hmenu, &MenuInfo); return NumberOfItems; }