#include "app.h" namespace ks { void launchScreenshot(App &app) { auto path=std::filesystem::path(executable()).parent_path()/L"KSwitcher.Screenshot.exe"; if (!std::filesystem::exists(path)) throw std::runtime_error("KSwitcher.Screenshot.exe is missing. Extract the complete application package."); auto command=L"\""+path.wstring()+L"\" --auto-open-editor="+ (app.settings.screenshotAutoOpenEditor?L"1":L"0"); if(app.settings.writeLog) command+=L" --write-log"; STARTUPINFOW startup{sizeof(startup)}; PROCESS_INFORMATION process{}; // Grant foreground rights before the child's first selection window opens. if (!CreateProcessW(path.c_str(),command.data(),nullptr,nullptr,FALSE,CREATE_SUSPENDED, nullptr,path.parent_path().c_str(),&startup,&process)) throw std::runtime_error(utf8(lastError(L"Cannot start screenshot editor"))); AllowSetForegroundWindow(process.dwProcessId); ResumeThread(process.hThread); CloseHandle(process.hThread); CloseHandle(process.hProcess); } }