22 lines
932 B
C++
22 lines
932 B
C++
#include "app.h"
|
|
|
|
namespace ks {
|
|
void launchScreenshot(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"\"";
|
|
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);
|
|
}
|
|
}
|