static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { WCHAR empty = 0; WNDCLASSEXW wndclass = {0}; /* Frame class */ wndclass.cbSize = sizeof(WNDCLASSEXW); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = FrameWndProc; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT)); wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW); wndclass.lpszClassName = szFrameClass; wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); RegisterClassExW(&wndclass); /* Child class */ wndclass.lpfnWndProc = ChildWndProc; wndclass.cbWndExtra = sizeof(HANDLE); wndclass.lpszClassName = szChildClass; RegisterClassExW(&wndclass); hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU)); hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS)); /* Initialize the Windows Common Controls DLL */ InitCommonControls(); /* register our hex editor control */ HexEdit_Register(); nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat); hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle, WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenuFrame, hInstance, NULL/*lpParam*/); if (!hFrameWnd) { return FALSE; } /* Create the status bar */ hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, &empty, hFrameWnd, STATUS_WINDOW); if (hStatusBar) { /* Create the status bar panes */ SetupStatusBar(hFrameWnd, FALSE); CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); } ShowWindow(hFrameWnd, nCmdShow); UpdateWindow(hFrameWnd); return TRUE; }
HMENU WINAPI __LoadMenuW(HINSTANCE hInstance, LPCWSTR lpMenuName) { HMENU hmenu = LoadMenuW(hInstance, lpMenuName); if (lpMenuName == MAKEINTRESOURCEW(IDR_MAIN_MENU)) { InitVDubAuoMenu(hmenu); } return hmenu; }
VOID ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem) { HMENU hMenu = NULL; HMENU hPopupMenu; MENUITEMINFO mii; POINT pt; if (MenuID) { hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID)); hPopupMenu = GetSubMenu(hMenu, 0); } else hPopupMenu = GetMenu(hwnd); ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; GetMenuItemInfo(hPopupMenu, DefaultItem, FALSE, &mii); if (!(mii.fState & MFS_GRAYED)) SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE); GetCursorPos(&pt); SetForegroundWindow(hwnd); TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hMainWnd, NULL); if (hMenu) DestroyMenu(hMenu); }
void CCEGLView::setMenuResource(LPCWSTR menu) { m_menu = menu; if (m_hWnd != NULL) { HMENU hMenu = LoadMenuW(GetModuleHandle(NULL), menu); SetMenu(m_hWnd, hMenu); } }
static HRESULT STDMETHODCALLTYPE UI_ShowContextMenu(IDocHostUIHandler *iface, DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved) { WebBrowserContainer *This = impl_from_IDocHostUIHandler(iface); DWORD cmdid, menu_id = 0; HMENU menu, submenu; TRACE("(%p)->(%d %s)\n", This, dwID, wine_dbgstr_point(ppt)); menu = LoadMenuW(hhctrl_hinstance, MAKEINTRESOURCEW(MENU_WEBBROWSER)); if (!menu) return S_OK; /* FIXME: Support more menu types. */ if(dwID == CONTEXT_MENU_TEXTSELECT) menu_id = 1; submenu = GetSubMenu(menu, menu_id); cmdid = TrackPopupMenu(submenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, This->hwndWindow, NULL); DestroyMenu(menu); switch(cmdid) { case IDTB_BACK: DoPageAction(This, WB_GOBACK); break; case IDTB_FORWARD: DoPageAction(This, WB_GOFORWARD); break; case MIID_SELECTALL: IWebBrowser2_ExecWB(This->web_browser, OLECMDID_SELECTALL, 0, NULL, NULL); break; case MIID_VIEWSOURCE: FIXME("View source\n"); break; case IDTB_PRINT: DoPageAction(This, WB_PRINT); break; case IDTB_REFRESH: DoPageAction(This, WB_REFRESH); break; case MIID_PROPERTIES: FIXME("Properties\n"); break; case MIID_COPY: IWebBrowser2_ExecWB(This->web_browser, OLECMDID_COPY, 0, NULL, NULL); break; case MIID_PASTE: IWebBrowser2_ExecWB(This->web_browser, OLECMDID_PASTE, 0, NULL, NULL); break; case MIID_CUT: IWebBrowser2_ExecWB(This->web_browser, OLECMDID_CUT, 0, NULL, NULL); break; } return S_OK; }
HRESULT CBandSiteMenu::_CreateMenuPart() { WCHAR wszBandName[MAX_PATH]; WCHAR wszBandGUID[MAX_PATH]; WCHAR wRegKey[MAX_PATH]; UINT cBands; DWORD dwDataSize; CATID category = CATID_DeskBand; HMENU hmenuToolbars; DWORD dwRead; CComPtr<IEnumGUID> pEnumGUID; HRESULT hr; if (m_hmenu) DestroyMenu(m_hmenu); /* Load the template we will fill in */ m_hmenu = LoadMenuW(GetModuleHandleW(L"browseui.dll"), MAKEINTRESOURCEW(IDM_TASKBAR_TOOLBARS)); if (!m_hmenu) return HRESULT_FROM_WIN32(GetLastError()); /* Get the handle of the submenu where the available items will be shown */ hmenuToolbars = GetSubMenu(m_hmenu, 0); /* Create the category enumerator */ hr = SHEnumClassesOfCategories(1, &category, 0, NULL, &pEnumGUID); if (FAILED_UNEXPECTEDLY(hr)) return hr; m_ComCatGuids.RemoveAll(); /* Enumerate the classes in the CATID_DeskBand category */ cBands = 0; do { GUID iter; pEnumGUID->Next(1, &iter, &dwRead); if (!dwRead) continue; if (!StringFromGUID2(iter, wszBandGUID, MAX_PATH)) continue; /* Get the band name */ StringCchPrintfW(wRegKey, MAX_PATH, L"CLSID\\%s", wszBandGUID); dwDataSize = MAX_PATH; SHGetValue(HKEY_CLASSES_ROOT, wRegKey, NULL, NULL, wszBandName, &dwDataSize); /* Insert it */ InsertMenu(hmenuToolbars, cBands, MF_BYPOSITION, m_ComCatGuids.GetSize() + FIRST_COMCAT_MENU_ID, wszBandName); m_ComCatGuids.Add(iter); cBands++; } while (dwRead > 0); return S_OK; }
static void hugsprim_LoadMenuW_19(HugsStackPtr hugs_root) { HsPtr arg1; HsPtr arg2; HsPtr res1; arg1 = hugs->getPtr(); arg2 = hugs->getPtr(); res1 = LoadMenuW(arg1, arg2); hugs->putPtr(res1); hugs->returnIO(hugs_root,1); }
VOID ShowPopupMenu(HWND hwnd, UINT MenuID) { HMENU hPopupMenu = GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID)), 0); POINT pt; GetCursorPos(&pt); SetForegroundWindow(hwnd); TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hMainWnd, NULL); DestroyMenu(hPopupMenu); }
HWND Create(HWND hwndParent) { RECT r = { 205, 28, 465, 250 }; DWORD style = WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS; HMENU menu = GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATIONMENU)), 0); HWND hwnd = CListView::Create(hwndParent, r, NULL, style, WS_EX_CLIENTEDGE, menu); if (hwnd) SetExtendedListViewStyle(LVS_EX_FULLROWSELECT); return hwnd; }
/************************************************************************** * ISvItemCm_fnQueryContextMenu() */ static HRESULT WINAPI ISvItemCm_fnQueryContextMenu( IContextMenu2 *iface, HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { ItemCmImpl *This = impl_from_IContextMenu2(iface); INT uIDMax; TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags); This->verb_offset=idCmdFirst; if(!(CMF_DEFAULTONLY & uFlags) && This->cidl>0) { HMENU hmenures = LoadMenuW(shell32_hInstance, MAKEINTRESOURCEW(MENU_SHV_FILE)); if(uFlags & CMF_EXPLORE) RemoveMenu(hmenures, FCIDM_SHVIEW_OPEN, MF_BYCOMMAND); uIDMax = Shell_MergeMenus(hmenu, GetSubMenu(hmenures, 0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS); DestroyMenu(hmenures); if(This->bAllValues) { MENUITEMINFOW mi; WCHAR str[255]; mi.cbSize = sizeof(mi); mi.fMask = MIIM_ID | MIIM_STRING | MIIM_FTYPE; mi.dwTypeData = str; mi.cch = 255; GetMenuItemInfoW(hmenu, FCIDM_SHVIEW_EXPLORE, MF_BYCOMMAND, &mi); RemoveMenu(hmenu, FCIDM_SHVIEW_EXPLORE, MF_BYCOMMAND); _InsertMenuItemW(hmenu, (uFlags & CMF_EXPLORE) ? 1 : 2, MF_BYPOSITION, FCIDM_SHVIEW_EXPLORE, MFT_STRING, str, MFS_ENABLED); } SetMenuDefaultItem(hmenu, 0, MF_BYPOSITION); if(uFlags & ~CMF_CANRENAME) RemoveMenu(hmenu, FCIDM_SHVIEW_RENAME, MF_BYCOMMAND); else EnableMenuItem(hmenu, FCIDM_SHVIEW_RENAME, MF_BYCOMMAND | ISvItemCm_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED); return MAKE_HRESULT(SEVERITY_SUCCESS, 0, uIDMax-idCmdFirst); } return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0); }
static HRESULT WINAPI RecycleBinMenu_QueryContextMenu(IContextMenu2 *iface, HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { HMENU menures = LoadMenuW(shell32_hInstance,MAKEINTRESOURCEW(MENU_RECYCLEBIN)); if(uFlags & CMF_DEFAULTONLY) return E_NOTIMPL; else{ UINT idMax = Shell_MergeMenus(hmenu,GetSubMenu(menures,0),indexMenu,idCmdFirst,idCmdLast,MM_SUBMENUSHAVEIDS); TRACE("Added %d id(s)\n",idMax-idCmdFirst); return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst+1); } }
static void DisplayPopupMenu(HHInfo *info) { HMENU menu, submenu; TBBUTTONINFOW button; MENUITEMINFOW item; POINT coords; RECT rect; DWORD index; menu = LoadMenuW(hhctrl_hinstance, MAKEINTRESOURCEW(MENU_POPUP)); if (!menu) return; submenu = GetSubMenu(menu, 0); /* Update the Show/Hide menu item */ item.cbSize = sizeof(MENUITEMINFOW); item.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_STRING; item.fType = MFT_STRING; item.fState = MF_ENABLED; if (info->WinType.fNotExpanded) item.dwTypeData = HH_LoadString(IDS_SHOWTABS); else item.dwTypeData = HH_LoadString(IDS_HIDETABS); SetMenuItemInfoW(submenu, IDTB_EXPAND, FALSE, &item); heap_free(item.dwTypeData); /* Find the index toolbar button */ button.cbSize = sizeof(TBBUTTONINFOW); button.dwMask = TBIF_COMMAND; index = SendMessageW(info->WinType.hwndToolBar, TB_GETBUTTONINFOW, IDTB_OPTIONS, (LPARAM) &button); if (index == -1) return; /* Get position */ SendMessageW(info->WinType.hwndToolBar, TB_GETITEMRECT, index, (LPARAM) &rect); coords.x = rect.left; coords.y = rect.bottom; ClientToScreen(info->WinType.hwndToolBar, &coords); TrackPopupMenu(submenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_NOANIMATION, coords.x, coords.y, 0, info->WinType.hwndHelp, NULL); }
static void ApplicationPageShowContextMenu2(void) { HMENU hMenu; HMENU hSubMenu; UINT count; POINT pt; GetCursorPos(&pt); hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATION_PAGE_CONTEXT2)); hSubMenu = GetSubMenu(hMenu, 0); count = SendMessageW(hApplicationPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0); if (count == 1) { EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED); } else if (count > 1) { EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } else { EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND); TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); DestroyMenu(hMenu); }
void ApplicationPageShowContextMenu1(void) { HMENU hMenu; HMENU hSubMenu; POINT pt; GetCursorPos(&pt); hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATION_PAGE_CONTEXT1)); hSubMenu = GetSubMenu(hMenu, 0); CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, TaskManagerSettings.ViewMode, MF_BYCOMMAND); TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); DestroyMenu(hMenu); }
void HTMLDocument_ShowContextMenu(HTMLDocument *This, DWORD dwID, POINT *ppt) { HMENU menu_res, menu; HRESULT hres; hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, (IUnknown*)CMDTARGET(This), (IDispatch*)HTMLDOC(This)); if(hres == S_OK) return; menu_res = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU)); menu = GetSubMenu(menu_res, dwID); TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, This->hwnd, NULL); DestroyMenu(menu_res); }
VOID STRING_LoadMenus(VOID) { HMENU hMainMenu; /* Create the menu */ hMainMenu = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(MAIN_MENU)); Globals.hFileMenu = GetSubMenu(hMainMenu, 0); Globals.hOptionMenu = GetSubMenu(hMainMenu, 1); Globals.hWindowsMenu = GetSubMenu(hMainMenu, 2); Globals.hLanguageMenu = GetSubMenu(hMainMenu, 3); if (Globals.hMDIWnd) SendMessageW(Globals.hMDIWnd, WM_MDISETMENU, (WPARAM)hMainMenu, (LPARAM)Globals.hWindowsMenu); else SetMenu(Globals.hMainWnd, hMainMenu); /* Destroy the old menu */ if (Globals.hMainMenu) DestroyMenu(Globals.hMainMenu); Globals.hMainMenu = hMainMenu; }
BOOL CreateListView(HWND hwnd) { hListView = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, L"", WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS, 205, 28, 465, 250, hwnd, GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATIONMENU)), 0), hInst, NULL); if (!hListView) { /* TODO: Show error message */ return FALSE; } (VOID) ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT); return TRUE; }
static void ProcessPageShowContextMenu(DWORD dwProcessId) { HMENU hMenu; HMENU hSubMenu; HMENU hPriorityMenu; POINT pt; SYSTEM_INFO si; HANDLE hProcess; DWORD dwProcessPriorityClass; WCHAR strDebugger[260]; DWORD dwDebuggerSize; HKEY hKey; UINT Idx; static const WCHAR wszAeDebugRegPath[] = { 'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'W','i','n','d','o','w','s',' ','N','T','\\', 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', 'A','e','D','e','b','u','g',0}; memset(&si, 0, sizeof(SYSTEM_INFO)); GetCursorPos(&pt); GetSystemInfo(&si); hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_PROCESS_PAGE_CONTEXT)); hSubMenu = GetSubMenu(hMenu, 0); hPriorityMenu = GetSubMenu(hSubMenu, 4); hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId); dwProcessPriorityClass = GetPriorityClass(hProcess); CloseHandle(hProcess); if (si.dwNumberOfProcessors < 2) RemoveMenu(hSubMenu, ID_PROCESS_PAGE_SETAFFINITY, MF_BYCOMMAND); if (!AreDebugChannelsSupported()) RemoveMenu(hSubMenu, ID_PROCESS_PAGE_DEBUGCHANNELS, MF_BYCOMMAND); switch (dwProcessPriorityClass) { case REALTIME_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, MF_BYCOMMAND); break; case HIGH_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_HIGH, MF_BYCOMMAND); break; case ABOVE_NORMAL_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, MF_BYCOMMAND); break; case NORMAL_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_NORMAL, MF_BYCOMMAND); break; case BELOW_NORMAL_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, MF_BYCOMMAND); break; case IDLE_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_LOW, MF_BYCOMMAND); break; } if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszAeDebugRegPath, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { static const WCHAR wszDebugger[] = {'D','e','b','u','g','g','e','r',0}; dwDebuggerSize = 260; if (RegQueryValueExW(hKey, wszDebugger, NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) == ERROR_SUCCESS) { static const WCHAR wszDRWTSN32[] = {'D','R','W','T','S','N','3','2',0}; for (Idx=0; Idx < lstrlenW(strDebugger); Idx++) strDebugger[Idx] = toupper(strDebugger[Idx]); if (wcsstr(strDebugger, wszDRWTSN32)) EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } else EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); RegCloseKey(hKey); } else { EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); DestroyMenu(hMenu); }
void TaskManager_OnTabWndSelChange(void) { int i; HMENU hMenu; HMENU hOptionsMenu; HMENU hViewMenu; HMENU hSubMenu; WCHAR szTemp[256]; SYSTEM_INFO sysInfo; hMenu = GetMenu(hMainWnd); hViewMenu = GetSubMenu(hMenu, 2); hOptionsMenu = GetSubMenu(hMenu, 1); TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd); for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) { hSubMenu = GetSubMenu(hViewMenu, i); if (hSubMenu) DestroyMenu(hSubMenu); RemoveMenu(hViewMenu, i, MF_BYPOSITION); } RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION); if (hWindowMenu) DestroyMenu(hWindowMenu); switch (TaskManagerSettings.ActiveTabPage) { case 0: ShowWindow(hApplicationPage, SW_SHOW); ShowWindow(hProcessPage, SW_HIDE); ShowWindow(hPerformancePage, SW_HIDE); BringWindowToTop(hApplicationPage); LoadStringW(hInst, IDS_MENU_LARGEICONS, szTemp, 256); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, szTemp); LoadStringW(hInst, IDS_MENU_SMALLICONS, szTemp, 256); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, szTemp); LoadStringW(hInst, IDS_MENU_DETAILS, szTemp, 256); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, szTemp); if (GetMenuItemCount(hMenu) <= 5) { hWindowMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU)); LoadStringW(hInst, IDS_MENU_WINDOWS, szTemp, 256); InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR) hWindowMenu, szTemp); DrawMenuBar(hMainWnd); } CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, TaskManagerSettings.ViewMode, MF_BYCOMMAND); /* * Give the application list control focus */ if (!bWasKeyboardInput) SetFocus(hApplicationPageListCtrl); break; case 1: ShowWindow(hApplicationPage, SW_HIDE); ShowWindow(hProcessPage, SW_SHOW); ShowWindow(hPerformancePage, SW_HIDE); BringWindowToTop(hProcessPage); LoadStringW(hInst, IDS_MENU_SELECTCOLUMNS, szTemp, 256); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, szTemp); LoadStringW(hInst, IDS_MENU_16BITTASK, szTemp, 256); AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, szTemp); if (TaskManagerSettings.Show16BitTasks) CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED); if (GetMenuItemCount(hMenu) > 5) { DeleteMenu(hMenu, 3, MF_BYPOSITION); DrawMenuBar(hMainWnd); } /* * Give the process list control focus */ if (!bWasKeyboardInput) SetFocus(hProcessPageListCtrl); break; case 2: ShowWindow(hApplicationPage, SW_HIDE); ShowWindow(hProcessPage, SW_HIDE); ShowWindow(hPerformancePage, SW_SHOW); BringWindowToTop(hPerformancePage); if (GetMenuItemCount(hMenu) > 5) { DeleteMenu(hMenu, 3, MF_BYPOSITION); DrawMenuBar(hMainWnd); } GetSystemInfo(&sysInfo); /* Hide CPU graph options on single CPU systems */ if (sysInfo.dwNumberOfProcessors > 1) { hSubMenu = CreatePopupMenu(); LoadStringW(hInst, IDS_MENU_ONEGRAPHALLCPUS, szTemp, 256); AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, szTemp); LoadStringW(hInst, IDS_MENU_ONEGRAPHPERCPU, szTemp, 256); AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, szTemp); LoadStringW(hInst, IDS_MENU_CPUHISTORY, szTemp, 256); AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR) hSubMenu, szTemp); if (TaskManagerSettings.CPUHistory_OneGraphPerCPU) CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND); else CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND); } LoadStringW(hInst, IDS_MENU_SHOWKERNELTIMES, szTemp, 256); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, szTemp); if (TaskManagerSettings.ShowKernelTimes) CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED); else CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED); /* * Give the tab control focus */ if (!bWasKeyboardInput) SetFocus(hTabWnd); break; } }
/* Message handler for dialog box. */ INT_PTR CALLBACK TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { #if 0 HDC hdc; PAINTSTRUCT ps; RECT rc; #endif LPRECT pRC; LPNMHDR pnmh; WINDOWPLACEMENT wp; switch (message) { case WM_INITDIALOG: hMainWnd = hDlg; return OnCreate(hDlg); case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } /* Process menu commands */ switch (LOWORD(wParam)) { case ID_FILE_NEW: TaskManager_OnFileNew(); break; case ID_OPTIONS_ALWAYSONTOP: TaskManager_OnOptionsAlwaysOnTop(); break; case ID_OPTIONS_MINIMIZEONUSE: TaskManager_OnOptionsMinimizeOnUse(); break; case ID_OPTIONS_HIDEWHENMINIMIZED: TaskManager_OnOptionsHideWhenMinimized(); break; case ID_OPTIONS_SHOW16BITTASKS: TaskManager_OnOptionsShow16BitTasks(); break; case ID_RESTORE: TaskManager_OnRestoreMainWindow(); break; case ID_VIEW_LARGE: case ID_VIEW_SMALL: case ID_VIEW_DETAILS: ApplicationPage_OnView(LOWORD(wParam)); break; case ID_VIEW_SHOWKERNELTIMES: PerformancePage_OnViewShowKernelTimes(); break; case ID_VIEW_CPUHISTORY_ONEGRAPHALL: PerformancePage_OnViewCPUHistoryOneGraphAll(); break; case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU: PerformancePage_OnViewCPUHistoryOneGraphPerCPU(); break; case ID_VIEW_UPDATESPEED_HIGH: case ID_VIEW_UPDATESPEED_NORMAL: case ID_VIEW_UPDATESPEED_LOW: case ID_VIEW_UPDATESPEED_PAUSED: TaskManager_OnViewUpdateSpeed(LOWORD(wParam)); break; case ID_VIEW_SELECTCOLUMNS: ProcessPage_OnViewSelectColumns(); break; case ID_VIEW_REFRESH: PostMessageW(hDlg, WM_TIMER, 0, 0); break; case ID_WINDOWS_TILEHORIZONTALLY: ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL); break; case ID_WINDOWS_TILEVERTICALLY: ApplicationPage_OnWindowsTile(MDITILE_VERTICAL); break; case ID_WINDOWS_MINIMIZE: ApplicationPage_OnWindowsMinimize(); break; case ID_WINDOWS_MAXIMIZE: ApplicationPage_OnWindowsMaximize(); break; case ID_WINDOWS_CASCADE: ApplicationPage_OnWindowsCascade(); break; case ID_WINDOWS_BRINGTOFRONT: ApplicationPage_OnWindowsBringToFront(); break; case ID_APPLICATION_PAGE_SWITCHTO: ApplicationPage_OnSwitchTo(); break; case ID_APPLICATION_PAGE_ENDTASK: ApplicationPage_OnEndTask(); break; case ID_APPLICATION_PAGE_GOTOPROCESS: ApplicationPage_OnGotoProcess(); break; case ID_PROCESS_PAGE_ENDPROCESS: ProcessPage_OnEndProcess(); break; case ID_PROCESS_PAGE_ENDPROCESSTREE: ProcessPage_OnEndProcessTree(); break; case ID_PROCESS_PAGE_DEBUG: ProcessPage_OnDebug(); break; case ID_PROCESS_PAGE_SETAFFINITY: ProcessPage_OnSetAffinity(); break; case ID_PROCESS_PAGE_SETPRIORITY_REALTIME: DoSetPriority(REALTIME_PRIORITY_CLASS); break; case ID_PROCESS_PAGE_SETPRIORITY_HIGH: DoSetPriority(HIGH_PRIORITY_CLASS); break; case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL: DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS); break; case ID_PROCESS_PAGE_SETPRIORITY_NORMAL: DoSetPriority(NORMAL_PRIORITY_CLASS); break; case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL: DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS); break; case ID_PROCESS_PAGE_SETPRIORITY_LOW: DoSetPriority(IDLE_PRIORITY_CLASS); break; case ID_PROCESS_PAGE_DEBUGCHANNELS: ProcessPage_OnDebugChannels(); break; /* ShutDown items */ case ID_SHUTDOWN_STANDBY: ShutDown_StandBy(); break; case ID_SHUTDOWN_HIBERNATE: ShutDown_Hibernate(); break; case ID_SHUTDOWN_POWEROFF: ShutDown_PowerOff(); break; case ID_SHUTDOWN_REBOOT: ShutDown_Reboot(); break; case ID_SHUTDOWN_LOGOFF: ShutDown_LogOffUser(); break; case ID_SHUTDOWN_SWITCHUSER: ShutDown_SwitchUser(); break; case ID_SHUTDOWN_LOCKCOMPUTER: ShutDown_LockComputer(); break; case ID_SHUTDOWN_DISCONNECT: ShutDown_Disconnect(); break; case ID_SHUTDOWN_EJECT_COMPUTER: ShutDown_EjectComputer(); break; case ID_HELP_ABOUT: OnAbout(); break; case ID_FILE_EXIT: EndDialog(hDlg, IDOK); break; } break; case WM_ONTRAYICON: switch(lParam) { case WM_RBUTTONDOWN: { POINT pt; BOOL OnTop; HMENU hMenu, hPopupMenu; GetCursorPos(&pt); OnTop = ((GetWindowLongPtrW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0); hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP)); hPopupMenu = GetSubMenu(hMenu, 0); if(IsWindowVisible(hMainWnd)) { DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND); } else { SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE); } if(OnTop) { CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED); } else { CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_UNCHECKED); } SetForegroundWindow(hMainWnd); TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL); DestroyMenu(hMenu); break; } case WM_LBUTTONDBLCLK: TaskManager_OnRestoreMainWindow(); break; } break; case WM_NOTIFY: pnmh = (LPNMHDR)lParam; if ((pnmh->hwndFrom == hTabWnd) && (pnmh->idFrom == IDC_TAB)) { switch (pnmh->code) { case TCN_SELCHANGE: TaskManager_OnTabWndSelChange(); break; case TCN_KEYDOWN: bWasKeyboardInput = TRUE; break; case NM_CLICK: bWasKeyboardInput = FALSE; break; } } break; #if 0 case WM_NCPAINT: hdc = GetDC(hDlg); GetClientRect(hDlg, &rc); Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); ReleaseDC(hDlg, hdc); break; case WM_PAINT: hdc = BeginPaint(hDlg, &ps); GetClientRect(hDlg, &rc); Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); EndPaint(hDlg, &ps); break; #endif case WM_SIZING: /* Make sure the user is sizing the dialog */ /* in an acceptable range */ pRC = (LPRECT)lParam; if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) { /* If the width is too small enlarge it to the minimum */ if (nMinimumWidth > (pRC->right - pRC->left)) pRC->left = pRC->right - nMinimumWidth; } else { /* If the width is too small enlarge it to the minimum */ if (nMinimumWidth > (pRC->right - pRC->left)) pRC->right = pRC->left + nMinimumWidth; } if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) { /* If the height is too small enlarge it to the minimum */ if (nMinimumHeight > (pRC->bottom - pRC->top)) pRC->top = pRC->bottom - nMinimumHeight; } else { /* If the height is too small enlarge it to the minimum */ if (nMinimumHeight > (pRC->bottom - pRC->top)) pRC->bottom = pRC->top + nMinimumHeight; } return TRUE; break; case WM_SIZE: /* Handle the window sizing in it's own function */ OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); break; case WM_MOVE: /* Handle the window moving in it's own function */ OnMove(wParam, LOWORD(lParam), HIWORD(lParam)); break; case WM_DESTROY: ShowWindow(hDlg, SW_HIDE); TrayIcon_ShellRemoveTrayIcon(); wp.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hDlg, &wp); TaskManagerSettings.Left = wp.rcNormalPosition.left; TaskManagerSettings.Top = wp.rcNormalPosition.top; TaskManagerSettings.Right = wp.rcNormalPosition.right; TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom; if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED)) TaskManagerSettings.Maximized = TRUE; else TaskManagerSettings.Maximized = FALSE; /* Get rid of the allocated command line cache, if any */ PerfDataDeallocCommandLineCache(); return DefWindowProcW(hDlg, message, wParam, lParam); case WM_TIMER: /* Refresh the performance data */ PerfDataRefresh(); RefreshApplicationPage(); RefreshProcessPage(); RefreshPerformancePage(); TrayIcon_ShellUpdateTrayIcon(); break; case WM_ENTERMENULOOP: TaskManager_OnEnterMenuLoop(hDlg); break; case WM_EXITMENULOOP: TaskManager_OnExitMenuLoop(hDlg); break; case WM_MENUSELECT: TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam); break; case WM_SYSCOLORCHANGE: /* Forward WM_SYSCOLORCHANGE to common controls */ SendMessage(hApplicationPageListCtrl, WM_SYSCOLORCHANGE, 0, 0); SendMessage(hProcessPageListCtrl, WM_SYSCOLORCHANGE, 0, 0); SendMessage(hProcessPageHeaderCtrl, WM_SYSCOLORCHANGE, 0, 0); break; } return 0; }
/* Message handler for dialog box. */ static INT_PTR CALLBACK TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static const WCHAR wszTaskmgr[] = {'t','a','s','k','m','g','r',0}; HDC hdc; PAINTSTRUCT ps; LPRECT pRC; RECT rc; LPNMHDR pnmh; WINDOWPLACEMENT wp; switch (message) { case WM_INITDIALOG: hMainWnd = hDlg; return OnCreate(hDlg); case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } /* Process menu commands */ switch (LOWORD(wParam)) { case ID_FILE_NEW: TaskManager_OnFileNew(); break; case ID_OPTIONS_ALWAYSONTOP: TaskManager_OnOptionsAlwaysOnTop(); break; case ID_OPTIONS_MINIMIZEONUSE: TaskManager_OnOptionsMinimizeOnUse(); break; case ID_OPTIONS_HIDEWHENMINIMIZED: TaskManager_OnOptionsHideWhenMinimized(); break; case ID_OPTIONS_SHOW16BITTASKS: TaskManager_OnOptionsShow16BitTasks(); break; case ID_RESTORE: TaskManager_OnRestoreMainWindow(); break; case ID_VIEW_LARGE: ApplicationPage_OnViewLargeIcons(); break; case ID_VIEW_SMALL: ApplicationPage_OnViewSmallIcons(); break; case ID_VIEW_DETAILS: ApplicationPage_OnViewDetails(); break; case ID_VIEW_SHOWKERNELTIMES: PerformancePage_OnViewShowKernelTimes(); break; case ID_VIEW_CPUHISTORY_ONEGRAPHALL: PerformancePage_OnViewCPUHistoryOneGraphAll(); break; case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU: PerformancePage_OnViewCPUHistoryOneGraphPerCPU(); break; case ID_VIEW_UPDATESPEED_HIGH: TaskManager_OnViewUpdateSpeedHigh(); break; case ID_VIEW_UPDATESPEED_NORMAL: TaskManager_OnViewUpdateSpeedNormal(); break; case ID_VIEW_UPDATESPEED_LOW: TaskManager_OnViewUpdateSpeedLow(); break; case ID_VIEW_UPDATESPEED_PAUSED: TaskManager_OnViewUpdateSpeedPaused(); break; case ID_VIEW_SELECTCOLUMNS: ProcessPage_OnViewSelectColumns(); break; case ID_VIEW_REFRESH: PostMessageW(hDlg, WM_TIMER, 0, 0); break; case ID_WINDOWS_TILEHORIZONTALLY: ApplicationPage_OnWindowsTileHorizontally(); break; case ID_WINDOWS_TILEVERTICALLY: ApplicationPage_OnWindowsTileVertically(); break; case ID_WINDOWS_MINIMIZE: ApplicationPage_OnWindowsMinimize(); break; case ID_WINDOWS_MAXIMIZE: ApplicationPage_OnWindowsMaximize(); break; case ID_WINDOWS_CASCADE: ApplicationPage_OnWindowsCascade(); break; case ID_WINDOWS_BRINGTOFRONT: ApplicationPage_OnWindowsBringToFront(); break; case ID_APPLICATION_PAGE_SWITCHTO: ApplicationPage_OnSwitchTo(); break; case ID_APPLICATION_PAGE_ENDTASK: ApplicationPage_OnEndTask(); break; case ID_APPLICATION_PAGE_GOTOPROCESS: ApplicationPage_OnGotoProcess(); break; case ID_PROCESS_PAGE_ENDPROCESS: ProcessPage_OnEndProcess(); break; case ID_PROCESS_PAGE_ENDPROCESSTREE: ProcessPage_OnEndProcessTree(); break; case ID_PROCESS_PAGE_DEBUG: ProcessPage_OnDebug(); break; case ID_PROCESS_PAGE_SETAFFINITY: ProcessPage_OnSetAffinity(); break; case ID_PROCESS_PAGE_SETPRIORITY_REALTIME: ProcessPage_OnSetPriorityRealTime(); break; case ID_PROCESS_PAGE_SETPRIORITY_HIGH: ProcessPage_OnSetPriorityHigh(); break; case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL: ProcessPage_OnSetPriorityAboveNormal(); break; case ID_PROCESS_PAGE_SETPRIORITY_NORMAL: ProcessPage_OnSetPriorityNormal(); break; case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL: ProcessPage_OnSetPriorityBelowNormal(); break; case ID_PROCESS_PAGE_SETPRIORITY_LOW: ProcessPage_OnSetPriorityLow(); break; case ID_PROCESS_PAGE_DEBUGCHANNELS: ProcessPage_OnDebugChannels(); break; case ID_HELP_TOPICS: WinHelpW(hDlg, wszTaskmgr, HELP_FINDER, 0); break; case ID_HELP_ABOUT: OnAbout(); break; case ID_FILE_EXIT: EndDialog(hDlg, IDOK); break; } break; case WM_ONTRAYICON: switch(lParam) { case WM_RBUTTONDOWN: { POINT pt; BOOL OnTop; HMENU hMenu, hPopupMenu; GetCursorPos(&pt); OnTop = (GetWindowLongW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0; hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP)); hPopupMenu = GetSubMenu(hMenu, 0); if(IsWindowVisible(hMainWnd)) { DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND); } else { SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE); } if(OnTop) { CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED); } SetForegroundWindow(hMainWnd); TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL); DestroyMenu(hMenu); break; } case WM_LBUTTONDBLCLK: TaskManager_OnRestoreMainWindow(); break; } break; case WM_NOTIFY: pnmh = (LPNMHDR)lParam; if ((pnmh->hwndFrom == hTabWnd) && (pnmh->idFrom == IDC_TAB) && (pnmh->code == TCN_SELCHANGE)) { TaskManager_OnTabWndSelChange(); } break; case WM_NCPAINT: hdc = GetDC(hDlg); GetClientRect(hDlg, &rc); Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); ReleaseDC(hDlg, hdc); break; case WM_PAINT: hdc = BeginPaint(hDlg, &ps); GetClientRect(hDlg, &rc); Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); EndPaint(hDlg, &ps); break; case WM_SIZING: /* Make sure the user is sizing the dialog */ /* in an acceptable range */ pRC = (LPRECT)lParam; if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) { /* If the width is too small enlarge it to the minimum */ if (nMinimumWidth > (pRC->right - pRC->left)) pRC->left = pRC->right - nMinimumWidth; } else { /* If the width is too small enlarge it to the minimum */ if (nMinimumWidth > (pRC->right - pRC->left)) pRC->right = pRC->left + nMinimumWidth; } if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) { /* If the height is too small enlarge it to the minimum */ if (nMinimumHeight > (pRC->bottom - pRC->top)) pRC->top = pRC->bottom - nMinimumHeight; } else { /* If the height is too small enlarge it to the minimum */ if (nMinimumHeight > (pRC->bottom - pRC->top)) pRC->bottom = pRC->top + nMinimumHeight; } return TRUE; case WM_SIZE: /* Handle the window sizing in it's own function */ OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); break; case WM_MOVE: /* Handle the window moving in it's own function */ OnMove(wParam, LOWORD(lParam), HIWORD(lParam)); break; case WM_DESTROY: ShowWindow(hDlg, SW_HIDE); TrayIcon_ShellRemoveTrayIcon(); wp.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hDlg, &wp); TaskManagerSettings.Left = wp.rcNormalPosition.left; TaskManagerSettings.Top = wp.rcNormalPosition.top; TaskManagerSettings.Right = wp.rcNormalPosition.right; TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom; if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED)) TaskManagerSettings.Maximized = TRUE; else TaskManagerSettings.Maximized = FALSE; return DefWindowProcW(hDlg, message, wParam, lParam); case WM_TIMER: /* Refresh the performance data */ PerfDataRefresh(); RefreshApplicationPage(); RefreshProcessPage(); RefreshPerformancePage(); TrayIcon_ShellUpdateTrayIcon(); break; case WM_ENTERMENULOOP: TaskManager_OnEnterMenuLoop(hDlg); break; case WM_EXITMENULOOP: TaskManager_OnExitMenuLoop(hDlg); break; case WM_MENUSELECT: TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam); break; } return 0; }
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case MYWM_NOTIFYICON: if(lParam==WM_RBUTTONDOWN){ HMENU hMenu = LoadMenuW(hInst,MAKEINTRESOURCEW(IDR_MENU1)); HMENU hSubMenu = GetSubMenu(hMenu,0); POINT pos; GetCursorPos(&pos); SetForegroundWindow(hWnd); TrackPopupMenu(hSubMenu,TPM_LEFTALIGN,pos.x,pos.y,0,hWnd,NULL); DestroyMenu(hMenu); } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case ID_EXIT: NOTIFYICONDATAW m_tnid; memset(&m_tnid,0,sizeof(m_tnid)); //OnCreate 函数中return 之前添加托盘生成代码 m_tnid.cbSize=sizeof(NOTIFYICONDATA); m_tnid.hWnd=hWnd; m_tnid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; m_tnid.uCallbackMessage=MYWM_NOTIFYICON; //用户定义的回调消息 wcscpy_s<128>(m_tnid.szTip,L"v-Judge-Kernel"); m_tnid.uID=NULL; HICON hIcon; hIcon=LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON2)); m_tnid.hIcon=hIcon; Shell_NotifyIconW(NIM_DELETE,&m_tnid); if(hIcon) DestroyIcon(hIcon); DestroyWindow(hWnd); break; case ID_UNINSTALL: if(IDYES == MessageBoxW(0,L"Are you sure to uninstall the service v-Judge_Kernel?",L"Warning!",MB_YESNO)){ if(SvcUninstall()) MessageBoxW(0,L"Successfully uninstall.",L"Message",MB_OK); else MessageBoxW(0,L"Unsuccessfully uninstall.",L"Message",MB_OK); } break; case ID_INSTALL: if(IDYES == MessageBoxW(0,L"Are you sure to install the service v-Judge_Kernel?",L"Warning!",MB_YESNO)){ if(SvcInstall()) MessageBoxW(0,L"Successfully install.",L"Message",MB_OK); else MessageBoxW(0,L"Unsuccessfully install.",L"Message",MB_OK); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
static void TaskManager_OnTabWndSelChange(void) { int i; HMENU hMenu; HMENU hOptionsMenu; HMENU hViewMenu; HMENU hSubMenu; WCHAR wszLargeIcons[255]; WCHAR wszSmallIcons[255]; WCHAR wszDetails[255]; WCHAR wszWindows[255]; WCHAR wszSelectColumns[255]; WCHAR wszShow16bTasks[255]; WCHAR wszOneGraphAllCPU[255]; WCHAR wszOneGraphPerCPU[255]; WCHAR wszCPUHistory[255]; WCHAR wszShowKernelTimes[255]; LoadStringW(hInst, IDS_VIEW_LARGE, wszLargeIcons, sizeof(wszLargeIcons)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_SMALL, wszSmallIcons, sizeof(wszSmallIcons)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_DETAILS, wszDetails, sizeof(wszDetails)/sizeof(WCHAR)); LoadStringW(hInst, IDS_WINDOWS, wszWindows, sizeof(wszWindows)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_SELECTCOLUMNS, wszSelectColumns, sizeof(wszSelectColumns)/sizeof(WCHAR)); LoadStringW(hInst, IDS_OPTIONS_SHOW16BITTASKS, wszShow16bTasks, sizeof(wszShow16bTasks)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU, sizeof(wszOneGraphAllCPU)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU, sizeof(wszOneGraphPerCPU)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_CPUHISTORY, wszCPUHistory, sizeof(wszCPUHistory)/sizeof(WCHAR)); LoadStringW(hInst, IDS_VIEW_SHOWKERNELTIMES, wszShowKernelTimes, sizeof(wszShowKernelTimes)/sizeof(WCHAR)); hMenu = GetMenu(hMainWnd); hViewMenu = GetSubMenu(hMenu, 2); hOptionsMenu = GetSubMenu(hMenu, 1); TaskManagerSettings.ActiveTabPage = SendMessageW(hTabWnd, TCM_GETCURSEL, 0, 0); for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) { hSubMenu = GetSubMenu(hViewMenu, i); if (hSubMenu) DestroyMenu(hSubMenu); RemoveMenu(hViewMenu, i, MF_BYPOSITION); } RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION); switch (TaskManagerSettings.ActiveTabPage) { case 0: ShowWindow(hApplicationPage, SW_SHOW); ShowWindow(hProcessPage, SW_HIDE); ShowWindow(hPerformancePage, SW_HIDE); BringWindowToTop(hApplicationPage); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails); if (GetMenuItemCount(hMenu) <= 4) { hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU)); InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows); DrawMenuBar(hMainWnd); } if (TaskManagerSettings.View_LargeIcons) CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND); else if (TaskManagerSettings.View_SmallIcons) CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND); else CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND); /* * Give the application list control focus */ SetFocus(hApplicationPageListCtrl); break; case 1: ShowWindow(hApplicationPage, SW_HIDE); ShowWindow(hProcessPage, SW_SHOW); ShowWindow(hPerformancePage, SW_HIDE); BringWindowToTop(hProcessPage); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns); AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks); if (TaskManagerSettings.Show16BitTasks) CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED); if (GetMenuItemCount(hMenu) > 4) { RemoveMenu(hMenu, 3, MF_BYPOSITION); DrawMenuBar(hMainWnd); } /* * Give the process list control focus */ SetFocus(hProcessPageListCtrl); break; case 2: ShowWindow(hApplicationPage, SW_HIDE); ShowWindow(hProcessPage, SW_HIDE); ShowWindow(hPerformancePage, SW_SHOW); BringWindowToTop(hPerformancePage); if (GetMenuItemCount(hMenu) > 4) { RemoveMenu(hMenu, 3, MF_BYPOSITION); DrawMenuBar(hMainWnd); } hSubMenu = CreatePopupMenu(); AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU); AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU); AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory); AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes); if (TaskManagerSettings.ShowKernelTimes) CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED); else CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED); if (TaskManagerSettings.CPUHistory_OneGraphPerCPU) CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND); else CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND); /* * Give the tab control focus */ SetFocus(hTabWnd); break; } }
STDAPI CLangBarItemButton::OnClick(TfLBIClick click, POINT pt, const RECT *prcArea) { if(IsEqualGUID(_LangBarItemInfo.guidItem, GUID_LBI_INPUTMODE)) { switch(click) { case TF_LBI_CLK_RIGHT: { HMENU hMenu = LoadMenuW(g_hInst, MAKEINTRESOURCEW(IDR_SYSTRAY_MENU)); if(hMenu) { UINT check = IDM_DEFAULT; for(int i = 0; i < _countof(menuItems); i++) { if(_pTextService->inputmode == menuItems[i].inputmode) { check = menuItems[i].id; break; } } CheckMenuRadioItem(hMenu, IDM_HIRAGANA, IDM_DEFAULT, check, MF_BYCOMMAND); HMENU hSubMenu = GetSubMenu(hMenu, 0); if(hSubMenu) { TPMPARAMS tpm; TPMPARAMS *ptpm = nullptr; if(prcArea != nullptr) { tpm.cbSize = sizeof(tpm); tpm.rcExclude = *prcArea; ptpm = &tpm; } BOOL bRet = TrackPopupMenuEx(hSubMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_VERTICAL, pt.x, pt.y, GetFocus(), ptpm); this->OnMenuSelect(bRet); } DestroyMenu(hMenu); } } break; case TF_LBI_CLK_LEFT: { BOOL fOpen = _pTextService->_IsKeyboardOpen(); if(fOpen) { _pTextService->_ClearComposition(); } else { _pTextService->inputmode = im_disable; } _pTextService->_SetKeyboardOpen(fOpen ? FALSE : TRUE); } break; default: break; } } return S_OK; }
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { BOOL AclUiAvailable; HMENU hEditMenu; WNDCLASSEXW wcFrame; WNDCLASSEXW wcChild; ATOM hFrameWndClass; ZeroMemory(&wcFrame, sizeof(WNDCLASSEXW)); wcFrame.cbSize = sizeof(WNDCLASSEXW); wcFrame.lpfnWndProc = FrameWndProc; wcFrame.hInstance = hInstance; wcFrame.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT)); wcFrame.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); wcFrame.hCursor = LoadCursorW(NULL, IDC_ARROW); wcFrame.lpszClassName = szFrameClass; hFrameWndClass = RegisterClassExW(&wcFrame); /* register frame window class */ ZeroMemory(&wcChild, sizeof(WNDCLASSEXW)); wcChild.cbSize = sizeof(WNDCLASSEXW); wcChild.lpfnWndProc = ChildWndProc; wcChild.cbWndExtra = sizeof(HANDLE); wcChild.hInstance = hInstance; wcChild.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT)); wcChild.hCursor = LoadCursorW(NULL, IDC_ARROW); wcChild.lpszClassName = szChildClass; wcChild.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); RegisterClassExW(&wcChild); /* register child windows class */ RegisterHexEditorClass(hInstance); hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU)); hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS)); /* Initialize the Windows Common Controls DLL */ // TODO: Replace this call by InitCommonControlsEx(_something_) InitCommonControls(); hEditMenu = GetSubMenu(hMenuFrame, 1); AclUiAvailable = InitializeAclUiDll(); if(!AclUiAvailable) { /* hide the Edit/Permissions... menu entry */ if(hEditMenu != NULL) { RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND); /* remove the separator after the menu item */ RemoveMenu(hEditMenu, 4, MF_BYPOSITION); } } if(hEditMenu != NULL) SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND); nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat); /* if (nClipboardFormat == 0) { DWORD dwError = GetLastError(); } */ hFrameWnd = CreateWindowExW(WS_EX_WINDOWEDGE, (LPCWSTR)(UlongToPtr(hFrameWndClass)), szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenuFrame, hInstance, NULL/*lpParam*/); if (!hFrameWnd) { return FALSE; } /* Create the status bar */ hStatusBar = CreateStatusWindowW(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | SBT_NOBORDERS, L"", hFrameWnd, STATUS_WINDOW); if (hStatusBar) { /* Create the status bar panes */ SetupStatusBar(hFrameWnd, FALSE); CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND | MF_CHECKED); } LoadSettings(); UpdateWindow(hFrameWnd); return TRUE; }
void ProcessPageShowContextMenu(DWORD dwProcessId) { HMENU hMenu; HMENU hSubMenu; HMENU hPriorityMenu; POINT pt; SYSTEM_INFO si; HANDLE hProcess; DWORD dwProcessPriorityClass; WCHAR strDebugger[260]; DWORD dwDebuggerSize; HKEY hKey; memset(&si, 0, sizeof(SYSTEM_INFO)); GetCursorPos(&pt); GetSystemInfo(&si); hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_PROCESS_PAGE_CONTEXT)); hSubMenu = GetSubMenu(hMenu, 0); hPriorityMenu = GetSubMenu(hSubMenu, 4); hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId); dwProcessPriorityClass = GetPriorityClass(hProcess); CloseHandle(hProcess); if (si.dwNumberOfProcessors < 2) RemoveMenu(hSubMenu, ID_PROCESS_PAGE_SETAFFINITY, MF_BYCOMMAND); if (!DebugChannelsAreSupported()) RemoveMenu(hSubMenu, ID_PROCESS_PAGE_DEBUGCHANNELS, MF_BYCOMMAND); switch (dwProcessPriorityClass) { case REALTIME_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, MF_BYCOMMAND); break; case HIGH_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_HIGH, MF_BYCOMMAND); break; case ABOVE_NORMAL_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, MF_BYCOMMAND); break; case NORMAL_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_NORMAL, MF_BYCOMMAND); break; case BELOW_NORMAL_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, MF_BYCOMMAND); break; case IDLE_PRIORITY_CLASS: CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_LOW, MF_BYCOMMAND); break; } if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_READ, &hKey) == ERROR_SUCCESS) { dwDebuggerSize = 260; if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) == ERROR_SUCCESS) { CharUpper(strDebugger); if (wcsstr(strDebugger, L"DRWTSN32")) EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } else EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); RegCloseKey(hKey); } else { EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL); DestroyMenu(hMenu); }
// Если (anFromShowWindow != -1), значит функу зовут из ShowWindow void OnGuiWindowAttached(HWND hWindow, HMENU hMenu, LPCSTR asClassA, LPCWSTR asClassW, DWORD anStyle, DWORD anStyleEx, BOOL abStyleHidden, int anFromShowWindow/*=-1*/) { DWORD nCurStyle = (DWORD)user->getWindowLongPtrW(hWindow, GWL_STYLE); DWORD nCurStyleEx = (DWORD)user->getWindowLongPtrW(hWindow, GWL_EXSTYLE); user->allowSetForegroundWindow(ASFW_ANY); // VLC создает несколько "подходящих" окон, но ShowWindow зовет // только для одного из них. Поэтому фактический аттач делаем // только в том случае, если окно "видимое" if ((!(nCurStyle & WS_VISIBLE)) && (anFromShowWindow <= SW_HIDE)) { // Значит потом, из ShowWindow return; } ghAttachGuiClient = hWindow; gnAttachGuiClientThreadId = user->getWindowThreadProcessId(hWindow, NULL); gbForceShowGuiClient = TRUE; gbAttachGuiClient = FALSE; // Только одно окно приложения. Пока? #if 0 // Для WS_CHILDWINDOW меню нельзя указать при создании окна if (!hMenu && !ghAttachGuiClientMenu && (asClassA || asClassW)) { BOOL lbRcClass; WNDCLASSEXA wca = {sizeof(WNDCLASSEXA)}; WNDCLASSEXW wcw = {sizeof(WNDCLASSEXW)}; if (asClassA) { lbRcClass = GetClassInfoExA(GetModuleHandle(NULL), asClassA, &wca); if (lbRcClass) ghAttachGuiClientMenu = LoadMenuA(wca.hInstance, wca.lpszMenuName); } else { lbRcClass = GetClassInfoExW(GetModuleHandle(NULL), asClassW, &wcw); if (lbRcClass) ghAttachGuiClientMenu = LoadMenuW(wca.hInstance, wcw.lpszMenuName); } hMenu = ghAttachGuiClientMenu; } if (hMenu) { // Для WS_CHILDWINDOW - не работает SetMenu(hWindow, hMenu); HMENU hSys = GetSystemMenu(hWindow, FALSE); TODO("Это в принципе прокатывает, но нужно транслировать WM_SYSCOMMAND -> WM_COMMAND, соответственно, перехватывать WndProc, или хук ставить"); if (hSys) { TODO("Хотя, хорошо бы не все в Popup засоывать, а извлечь ChildPopups из hMenu"); InsertMenu(hSys, 0, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hMenu, L"Window menu"); InsertMenu(hSys, 1, MF_BYPOSITION|MF_SEPARATOR, NULL, NULL); } } #endif DWORD nSize = sizeof(CESERVER_REQ_HDR)+sizeof(CESERVER_REQ_ATTACHGUIAPP); CESERVER_REQ *pIn = ExecuteNewCmd(CECMD_ATTACHGUIAPP, nSize); gnAttachGuiClientFlags = agaf_Success; // С приложенями .Net - приходится работать как с WS_CHILD, // иначе в них "не нажимаются" тулбары и меню if (IsDotNetWindow(hWindow)) { gnAttachGuiClientFlags |= (agaf_DotNet|agaf_WS_CHILD); } // Если в окне нет меню - работаем с ним как с WS_CHILD // так не возникает проблем с активацией и т.д. else if (user->getMenu(hWindow) == NULL) { if (IsQtWindow(asClassA, asClassW)) gnAttachGuiClientFlags |= (agaf_NoMenu|agaf_QtWindow|agaf_WS_CHILD); else gnAttachGuiClientFlags |= (agaf_NoMenu|agaf_WS_CHILD); } pIn->AttachGuiApp.nFlags = gnAttachGuiClientFlags; pIn->AttachGuiApp.nPID = GetCurrentProcessId(); pIn->AttachGuiApp.hAppWindow = hWindow; pIn->AttachGuiApp.Styles.nStyle = nCurStyle; // стили могли измениться после создания окна, pIn->AttachGuiApp.Styles.nStyleEx = nCurStyleEx; // поэтому получим актуальные user->getWindowRect(hWindow, &pIn->AttachGuiApp.rcWindow); GetModuleFileName(NULL, pIn->AttachGuiApp.sAppFilePathName, countof(pIn->AttachGuiApp.sAppFilePathName)); pIn->AttachGuiApp.hkl = (DWORD)(LONG)(LONG_PTR)GetKeyboardLayout(0); wchar_t szGuiPipeName[128]; msprintf(szGuiPipeName, countof(szGuiPipeName), CEGUIPIPENAME, L".", (DWORD)ghConEmuWnd); // AttachThreadInput DWORD nConEmuTID = user->getWindowThreadProcessId(ghConEmuWnd, NULL); DWORD nTID = GetCurrentThreadId(); _ASSERTEX(nTID==gnHookMainThreadId || nTID==gnAttachGuiClientThreadId); BOOL bAttachRc = user->attachThreadInput(nTID, nConEmuTID, TRUE); DWORD nAttachErr = GetLastError(); UNREFERENCED_PARAMETER(bAttachRc); UNREFERENCED_PARAMETER(nAttachErr); HWND hPreFocus = user->getFocus(); CESERVER_REQ* pOut = ExecuteCmd(szGuiPipeName, pIn, 0/*Default timeout*/, NULL); ExecuteFreeResult(pIn); // abStyleHidden == TRUE, если окно при создании указало флаг WS_VISIBLE (т.е. не собиралось звать ShowWindow) if (pOut) { if (pOut->hdr.cbSize > sizeof(CESERVER_REQ_HDR)) { _ASSERTE((pOut->AttachGuiApp.nFlags & agaf_Success) == agaf_Success); BOOL lbRc = FALSE; _ASSERTE(pOut->AttachGuiApp.hConEmuBack && pOut->AttachGuiApp.hConEmuDc && (HWND)pOut->AttachGuiApp.hConEmuDc!=(HWND)pOut->AttachGuiApp.hConEmuBack); _ASSERTE((ghConEmuWndBack==NULL) || (pOut->AttachGuiApp.hConEmuBack==ghConEmuWndBack)); _ASSERTE(ghConEmuWnd && (ghConEmuWnd==pOut->AttachGuiApp.hConEmuWnd)); ghConEmuWnd = pOut->AttachGuiApp.hConEmuWnd; SetConEmuHkWindows(pOut->AttachGuiApp.hConEmuDc, pOut->AttachGuiApp.hConEmuBack); //gbGuiClientHideCaption = pOut->AttachGuiApp.bHideCaption; gGuiClientStyles = pOut->AttachGuiApp.Styles; #ifdef _DEBUG HWND hFocus = user->getFocus(); DWORD nFocusPID = 0; if (hFocus) { user->getWindowThreadProcessId(hFocus, &nFocusPID); DWORD nConEmuPID = 0; user->getWindowThreadProcessId(ghConEmuWnd, &nConEmuPID); if (nFocusPID != GetCurrentProcessId() && nFocusPID != nConEmuPID) { _ASSERTE(hFocus==NULL || (nFocusPID==GetCurrentProcessId() || nFocusPID == nConEmuPID)); hFocus = NULL; } } #endif if (pOut->AttachGuiApp.hkl) { LONG_PTR hkl = (LONG_PTR)(LONG)pOut->AttachGuiApp.hkl; lbRc = ActivateKeyboardLayout((HKL)hkl, KLF_SETFORPROCESS) != NULL; UNREFERENCED_PARAMETER(lbRc); } //grcAttachGuiClientPos = pOut->AttachGuiApp.rcWindow; ReplaceGuiAppWindow(abStyleHidden); //if (hPreFocus) //{ // user->setFocus(hPreFocus); //} UINT nMsgID = user->registerWindowMessageW(CONEMUMSG_RESTORECHILDFOCUS); user->postMessageW(ghConEmuWndBack, nMsgID, 0,0); //// !!! OnSetForegroundWindow не подходит - он дергает Cmd. ////user->setForegroundWindow(ghConEmuWnd); //#if 0 //wchar_t szClass[64] = {}; user->getClassNameW(hFocus, szClass, countof(szClass)); //MessageBox(NULL, szClass, L"WasFocused", MB_SYSTEMMODAL); //#endif ////if (!(nCurStyle & WS_CHILDWINDOW)) //{ // // Если ставить WS_CHILD - пропадет меню! // //nCurStyle = (nCurStyle | WS_CHILDWINDOW|WS_TABSTOP); // & ~(WS_THICKFRAME/*|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX*/); // //user->setWindowLongPtrW(hWindow, GWL_STYLE, nCurStyle); // if (gnAttachGuiClientFlags & agaf_DotNet) // { // } // else // { // SetParent(hWindow, ghConEmuWndBack); // } //} // //RECT rcGui = grcAttachGuiClientPos = pOut->AttachGuiApp.rcWindow; //if (user->setWindowPos(hWindow, HWND_TOP, rcGui.left,rcGui.top, rcGui.right-rcGui.left, rcGui.bottom-rcGui.top, // SWP_DRAWFRAME | /*SWP_FRAMECHANGED |*/ (abStyleHidden ? SWP_SHOWWINDOW : 0))) //{ // if (abStyleHidden) // abStyleHidden = FALSE; //} // //// !!! OnSetForegroundWindow не подходит - он дергает Cmd. //user->setForegroundWindow(ghConEmuWnd); ////if (hFocus) ////SetFocus(hFocus ? hFocus : hWindow); // hFocus==NULL, эффекта нет ////OnSetForegroundWindow(hWindow); ////user->postMessage(ghConEmuWnd, WM_NCACTIVATE, TRUE, 0); ////user->postMessage(ghConEmuWnd, WM_NCPAINT, 0, 0); //user->postMessage(hWindow, WM_NCPAINT, 0, 0); } ExecuteFreeResult(pOut); } if (abStyleHidden) { user->showWindow(hWindow, SW_SHOW); } }
static HRESULT WINAPI ItemMenu_QueryContextMenu( IContextMenu3 *iface, HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { ContextMenu *This = impl_from_IContextMenu3(iface); INT uIDMax; TRACE("(%p)->(%p %d 0x%x 0x%x 0x%x )\n", This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags); if(!(CMF_DEFAULTONLY & uFlags) && This->cidl > 0) { HMENU hmenures = LoadMenuW(shell32_hInstance, MAKEINTRESOURCEW(MENU_SHV_FILE)); if(uFlags & CMF_EXPLORE) RemoveMenu(hmenures, FCIDM_SHVIEW_OPEN, MF_BYCOMMAND); uIDMax = Shell_MergeMenus(hmenu, GetSubMenu(hmenures, 0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS); DestroyMenu(hmenures); if(This->allvalues) { MENUITEMINFOW mi; WCHAR str[255]; mi.cbSize = sizeof(mi); mi.fMask = MIIM_ID | MIIM_STRING | MIIM_FTYPE; mi.dwTypeData = str; mi.cch = 255; GetMenuItemInfoW(hmenu, FCIDM_SHVIEW_EXPLORE, MF_BYCOMMAND, &mi); RemoveMenu(hmenu, FCIDM_SHVIEW_EXPLORE + idCmdFirst, MF_BYCOMMAND); mi.cbSize = sizeof(mi); mi.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_STRING; mi.dwTypeData = str; mi.fState = MFS_ENABLED; mi.wID = FCIDM_SHVIEW_EXPLORE; mi.fType = MFT_STRING; InsertMenuItemW(hmenu, (uFlags & CMF_EXPLORE) ? 1 : 2, MF_BYPOSITION, &mi); } SetMenuDefaultItem(hmenu, 0, MF_BYPOSITION); if(uFlags & ~CMF_CANRENAME) RemoveMenu(hmenu, FCIDM_SHVIEW_RENAME, MF_BYCOMMAND); else { UINT enable = MF_BYCOMMAND; /* can't rename more than one item at a time*/ if (!This->apidl || This->cidl > 1) enable |= MFS_DISABLED; else { DWORD attr = SFGAO_CANRENAME; IShellFolder_GetAttributesOf(This->parent, 1, (LPCITEMIDLIST*)This->apidl, &attr); enable |= (attr & SFGAO_CANRENAME) ? MFS_ENABLED : MFS_DISABLED; } EnableMenuItem(hmenu, FCIDM_SHVIEW_RENAME, enable); } return MAKE_HRESULT(SEVERITY_SUCCESS, 0, uIDMax-idCmdFirst); } return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0); }
HWND WINAPI User32CreateWindowEx(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam, DWORD dwFlags) { LARGE_STRING WindowName; LARGE_STRING lstrClassName, *plstrClassName; UNICODE_STRING ClassName; WNDCLASSEXA wceA; WNDCLASSEXW wceW; HMODULE hLibModule = NULL; DWORD save_error; BOOL Unicode, ClassFound = FALSE; HWND Handle = NULL; #if 0 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle, dwExStyle, hWndParent); #endif if (!RegisterDefaultClasses) { TRACE("RegisterSystemControls\n"); RegisterSystemControls(); } Unicode = !(dwFlags & NUCWE_ANSI); if (IS_ATOM(lpClassName)) { plstrClassName = (PVOID)lpClassName; } else { if(Unicode) RtlInitUnicodeString(&ClassName, (PCWSTR)lpClassName); else { if (!RtlCreateUnicodeStringFromAsciiz(&ClassName, (PCSZ)lpClassName)) { SetLastError(ERROR_OUTOFMEMORY); return (HWND)0; } } /* Copy it to a LARGE_STRING */ lstrClassName.Buffer = ClassName.Buffer; lstrClassName.Length = ClassName.Length; lstrClassName.MaximumLength = ClassName.MaximumLength; plstrClassName = &lstrClassName; } /* Initialize a LARGE_STRING */ RtlInitLargeString(&WindowName, lpWindowName, Unicode); // HACK: The current implementation expects the Window name to be UNICODE if (!Unicode) { NTSTATUS Status; PSTR AnsiBuffer = WindowName.Buffer; ULONG AnsiLength = WindowName.Length; WindowName.Length = 0; WindowName.MaximumLength = AnsiLength * sizeof(WCHAR); WindowName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, WindowName.MaximumLength); if (!WindowName.Buffer) { SetLastError(ERROR_OUTOFMEMORY); goto cleanup; } Status = RtlMultiByteToUnicodeN(WindowName.Buffer, WindowName.MaximumLength, &WindowName.Length, AnsiBuffer, AnsiLength); if (!NT_SUCCESS(Status)) { goto cleanup; } } if(!hMenu && (dwStyle & (WS_OVERLAPPEDWINDOW | WS_POPUP))) { if(Unicode) { wceW.cbSize = sizeof(WNDCLASSEXW); if(GetClassInfoExW(hInstance, (LPCWSTR)lpClassName, &wceW) && wceW.lpszMenuName) { hMenu = LoadMenuW(hInstance, wceW.lpszMenuName); } } else { wceA.cbSize = sizeof(WNDCLASSEXA); if(GetClassInfoExA(hInstance, lpClassName, &wceA) && wceA.lpszMenuName) { hMenu = LoadMenuA(hInstance, wceA.lpszMenuName); } } } if (!Unicode) dwExStyle |= WS_EX_SETANSICREATOR; for(;;) { Handle = NtUserCreateWindowEx(dwExStyle, plstrClassName, NULL, &WindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam, dwFlags, NULL); if (Handle) break; if (!ClassFound) { save_error = GetLastError(); if ( save_error == ERROR_CANNOT_FIND_WND_CLASS ) { ClassFound = VersionRegisterClass(ClassName.Buffer, NULL, NULL, &hLibModule); if (ClassFound) continue; } } if (hLibModule) { save_error = GetLastError(); FreeLibrary(hLibModule); SetLastError(save_error); hLibModule = 0; } break; } #if 0 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle); #endif cleanup: if(!Unicode) { if (!IS_ATOM(lpClassName)) { RtlFreeUnicodeString(&ClassName); } RtlFreeLargeString(&WindowName); } return Handle; }