void VMenu2::Close(int ExitCode, bool Force) { if(ExitCode>=0) SetSelectPos(ExitCode); cancel=ExitCode==-1; closing=true; ForceClosing = Force; }
BOOL CListCtrlEditBase::PreTranslateMessageEx(MSG* pMsg) { CWnd *pWnd; if(m_pInEdit == NULL) return false; if(!m_pParentList) return false; switch (pMsg->message) { case WM_USER_SHOW_EDIT: ShowEdit((int)pMsg->wParam, (int)pMsg->lParam); return true; case WM_KEYDOWN: if(( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_TAB) && m_pInEdit->m_hWnd!= NULL && m_pParentList != NULL) { DWORD dwStyle = m_pInEdit->GetStyle(); if((dwStyle&WS_VISIBLE) == WS_VISIBLE) { OnEditEnd(); CRect rcCtrl; int nItem; int nSub; if(FALSE == Key_Ctrl(nItem,nSub)) Key_Shift(nItem,nSub); m_pParentList->GetSubItemRect(nItem,nSub,LVIR_LABEL,rcCtrl); CPoint pt(rcCtrl.left+1,rcCtrl.top+1); //ShowEdit(nItem, nSub); /*POSITION pos = m_pParentList->GetFirstSelectedItemPosition(); if (pos == NULL) { } else { while (pos) { int ntpItem = m_pParentList->GetNextSelectedItem(pos); m_pParentList->SetItemState(ntpItem,0,LVIS_SELECTED); } } //m_pParentList->SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED); */ SetSelectPos(); return TRUE; } } else if(pMsg->wParam == VK_UP) { if (m_nCurrentItem > 0) m_nCurrentItem--; pWnd = m_CtrlMap.GetSubWnd(m_pParentList, m_nCurrentSubItem); if (pWnd ) { pWnd->PostMessage(WM_USER_SHOW_EDIT, m_nCurrentItem, m_nCurrentSubItem); SetSelectPos(); } return TRUE; } else if(pMsg->wParam == VK_DOWN) { if (m_nCurrentItem < m_pParentList->GetItemCount() - 1) m_nCurrentItem++; pWnd = m_CtrlMap.GetSubWnd(m_pParentList, m_nCurrentSubItem); if (pWnd ) { pWnd->PostMessage(WM_USER_SHOW_EDIT, m_nCurrentItem, m_nCurrentSubItem); SetSelectPos(); } return TRUE; } else if(pMsg->wParam == VK_RETURN) { CWnd* pParent = m_pInEdit->GetParent(); m_bExchange = TRUE; //::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,0); OnEditEnd(); m_pInEdit->ShowWindow(SW_HIDE); return true; } else if(pMsg->wParam == VK_ESCAPE) { CWnd* pParent = m_pInEdit->GetParent(); m_bExchange = FALSE; m_pInEdit->ShowWindow(SW_HIDE); return true; //::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,0); } }//end switch return false; }
void ShowProcessList() { static bool Active = false; if (Active) return; Active = true; SCOPE_EXIT{ Active = false; }; const auto ProcList = VMenu2::create(msg(lng::MProcessListTitle), {}, ScrY - 4); ProcList->SetMenuFlags(VMENU_WRAPMODE); ProcList->SetPosition({ -1, -1, 0, 0 }); bool ShowImage = false; const auto FillProcList = [&] { ProcList->clear(); ProcInfo Info{ ProcList.get(), ShowImage }; if (!EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&Info))) { rethrow_if(Info.ExceptionPtr); return false; } ProcList->SortItems([](const MenuItemEx& a, const MenuItemEx& b, SortItemParam&) { return string_sort::less(std::any_cast<const menu_data&>(a.ComplexUserData).Title, std::any_cast<const menu_data&>(b.ComplexUserData).Title); }); return true; }; if (!FillProcList()) return; ProcList->AssignHighlights(FALSE); ProcList->SetBottomTitle(msg(lng::MProcessListBottom)); ProcList->Run([&](const Manager::Key& RawKey) { const auto Key=RawKey(); int KeyProcessed = 1; switch (Key) { case KEY_F1: help::show(L"TaskList"sv); break; case KEY_NUMDEL: case KEY_DEL: { if (const auto MenuData = ProcList->GetComplexUserDataPtr<menu_data>()) { if (Message(MSG_WARNING, msg(lng::MKillProcessTitle), { msg(lng::MAskKillProcess), MenuData->Title, msg(lng::MKillProcessWarning) }, { lng::MKillProcessKill, lng::MCancel }) == Message::first_button) { const os::handle Process(OpenProcess(PROCESS_TERMINATE, FALSE, MenuData->Pid)); if (!Process || !TerminateProcess(Process.native_handle(), 0xFFFFFFFF)) { const auto ErrorState = error_state::fetch(); Message(MSG_WARNING, ErrorState, msg(lng::MKillProcessTitle), { msg(lng::MCannotKillProcess) }, { lng::MOk }); } } } } [[fallthrough]]; case KEY_CTRLR: case KEY_RCTRLR: { if (!FillProcList()) ProcList->Close(-1); break; } case KEY_F2: { // TODO: change titles, don't enumerate again ShowImage = !ShowImage; const auto SelectPos = ProcList->GetSelectPos(); if (!FillProcList()) { ProcList->Close(-1); } else { ProcList->SetSelectPos(SelectPos); } break; } default: KeyProcessed = 0; } return KeyProcessed; }); if (ProcList->GetExitCode() < 0) return; const auto MenuData = ProcList->GetComplexUserDataPtr<menu_data>(); if (!MenuData) return; SwitchToWindow(MenuData->Hwnd); }
void ShowProcessList() { static bool Active = false; if (Active) return; Active = true; auto ProcList = VMenu2::create(MSG(MProcessListTitle), nullptr, 0, ScrY - 4); ProcList->SetMenuFlags(VMENU_WRAPMODE); ProcList->SetPosition(-1,-1,0,0); static bool bShowImage = false; ProcInfo pi = {ProcList.get(), bShowImage}; if (EnumWindows(EnumWindowsProc,(LPARAM)&pi)) { ProcList->AssignHighlights(FALSE); ProcList->SetBottomTitle(MSG(MProcessListBottom)); ProcList->SortItems(TaskSort); ProcList->Run([&](const Manager::Key& RawKey)->int { const auto Key=RawKey.FarKey(); int KeyProcessed = 1; switch (Key) { case KEY_F1: { Help::create(L"TaskList"); break; } case KEY_NUMDEL: case KEY_DEL: { auto ProcWnd = *static_cast<HWND*>(ProcList->GetUserData(nullptr, 0)); if (ProcWnd) { wchar_t_ptr Title; int LenTitle=GetWindowTextLength(ProcWnd); if (LenTitle) { Title.reset(LenTitle + 1); if (Title && (LenTitle=GetWindowText(ProcWnd, Title.get(), LenTitle+1))) Title[LenTitle]=0; } DWORD ProcID; GetWindowThreadProcessId(ProcWnd,&ProcID); if (!Message(MSG_WARNING,2,MSG(MKillProcessTitle),MSG(MAskKillProcess), NullToEmpty(Title.get()),MSG(MKillProcessWarning),MSG(MKillProcessKill),MSG(MCancel))) { if (KillProcess(ProcID)) Sleep(500); else { Global->CatchError(); Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MKillProcessTitle),MSG(MCannotKillProcess),MSG(MOk)); } } } } case KEY_CTRLR: case KEY_RCTRLR: { ProcList->DeleteItems(); if (!EnumWindows(EnumWindowsProc,(LPARAM)&pi)) ProcList->Close(-1); else ProcList->SortItems(TaskSort); break; } case KEY_F2: { pi.bShowImage=(bShowImage=!bShowImage); int SelectPos=ProcList->GetSelectPos(); ProcList->DeleteItems(); if (!EnumWindows(EnumWindowsProc,(LPARAM)&pi)) ProcList->Close(-1); else { ProcList->SortItems(TaskSort); ProcList->SetSelectPos(SelectPos); } break; } default: KeyProcessed = 0; } return KeyProcessed; }); if (ProcList->GetExitCode()>=0) { auto ProcWnd = *static_cast<HWND*>(ProcList->GetUserData(nullptr, 0)); if (ProcWnd) { //SetForegroundWindow(ProcWnd); // Allow SetForegroundWindow on Win98+. DWORD dwMs; // Remember the current value. BOOL bSPI = SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &dwMs, 0); if (bSPI) // Reset foreground lock timeout bSPI = SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, 0); SetForegroundWindow(ProcWnd); if (bSPI) // Restore old value SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, ToPtr(dwMs), 0); WINDOWPLACEMENT wp = { sizeof(wp) }; if (!GetWindowPlacement(ProcWnd,&wp) || wp.showCmd!=SW_SHOWMAXIMIZED) ShowWindowAsync(ProcWnd,SW_RESTORE); } } } Active = false; }