Rename getTitle to title, add consoleProcessList.
This commit is contained in:
parent
3e4086cb39
commit
17f5f9e960
@ -74,7 +74,7 @@ int main() {
|
||||
// Set the title and read it back.
|
||||
w.setTitle(narrowString(inputStr));
|
||||
readBuf = kJunk;
|
||||
const DWORD retVal = w.getTitleInternal(readBuf, readLen);
|
||||
const DWORD retVal = w.titleInternal(readBuf, readLen);
|
||||
|
||||
if (readLen == 0) {
|
||||
// When passing a buffer size 0, the API returns 0 and leaves
|
||||
|
@ -273,7 +273,17 @@ bool Worker::setTitleInternal(const std::wstring &wstr) {
|
||||
return cmd().success;
|
||||
}
|
||||
|
||||
DWORD Worker::getTitleInternal(std::array<wchar_t, 1024> &buf, DWORD bufSize) {
|
||||
std::string Worker::title() {
|
||||
std::array<wchar_t, 1024> buf;
|
||||
DWORD ret = titleInternal(buf, buf.size());
|
||||
ret = std::min<DWORD>(ret, buf.size() - 1);
|
||||
buf[std::min<size_t>(buf.size() - 1, ret)] = L'\0';
|
||||
return narrowString(std::wstring(buf.data()));
|
||||
}
|
||||
|
||||
// This API is more low-level than typical, because GetConsoleTitleW is buggy
|
||||
// in older versions of Windows, and this method is used to test the bugs.
|
||||
DWORD Worker::titleInternal(std::array<wchar_t, 1024> &buf, DWORD bufSize) {
|
||||
cmd().dword = bufSize;
|
||||
cmd().u.consoleTitle = buf;
|
||||
rpc(Command::GetConsoleTitle);
|
||||
@ -281,6 +291,15 @@ DWORD Worker::getTitleInternal(std::array<wchar_t, 1024> &buf, DWORD bufSize) {
|
||||
return cmd().dword;
|
||||
}
|
||||
|
||||
std::vector<DWORD> Worker::consoleProcessList() {
|
||||
rpc(Command::GetConsoleProcessList);
|
||||
DWORD count = cmd().dword;
|
||||
ASSERT(count <= cmd().u.processList.size());
|
||||
return std::vector<DWORD>(
|
||||
&cmd().u.processList[0],
|
||||
&cmd().u.processList[count]);
|
||||
}
|
||||
|
||||
void Worker::rpc(Command::Kind kind) {
|
||||
rpcImpl(kind);
|
||||
m_finishEvent.wait();
|
||||
|
@ -108,7 +108,9 @@ public:
|
||||
std::vector<Handle> scanForConsoleHandles();
|
||||
void setTitle(const std::string &str) { auto b = setTitleInternal(widenString(str)); ASSERT(b && "setTitle failed"); }
|
||||
bool setTitleInternal(const std::wstring &str);
|
||||
DWORD getTitleInternal(std::array<wchar_t, 1024> &buf, DWORD bufSize);
|
||||
std::string title();
|
||||
DWORD titleInternal(std::array<wchar_t, 1024> &buf, DWORD bufSize);
|
||||
std::vector<DWORD> consoleProcessList();
|
||||
|
||||
Handle openConin(BOOL bInheritHandle=FALSE) {
|
||||
cmd().bInheritHandle = bInheritHandle;
|
||||
|
@ -226,6 +226,10 @@ int main(int argc, char *argv[]) {
|
||||
cmd.success = FreeConsole();
|
||||
trace("Calling FreeConsole... %s", successOrFail(cmd.success));
|
||||
break;
|
||||
case Command::GetConsoleProcessList:
|
||||
cmd.dword = GetConsoleProcessList(cmd.u.processList.data(),
|
||||
cmd.u.processList.size());
|
||||
break;
|
||||
case Command::GetConsoleScreenBufferInfo:
|
||||
cmd.u.consoleScreenBufferInfo = {};
|
||||
cmd.success = GetConsoleScreenBufferInfo(
|
||||
|
@ -16,6 +16,7 @@ struct Command {
|
||||
Duplicate,
|
||||
Exit,
|
||||
FreeConsole,
|
||||
GetConsoleProcessList,
|
||||
GetConsoleScreenBufferInfo,
|
||||
GetConsoleSelectionInfo,
|
||||
GetConsoleTitle,
|
||||
@ -60,6 +61,7 @@ struct Command {
|
||||
FixedSizeString<1024> writeText;
|
||||
FixedSizeString<1024> systemText;
|
||||
std::array<wchar_t, 1024> consoleTitle;
|
||||
std::array<DWORD, 1024> processList;
|
||||
struct {
|
||||
DWORD mask;
|
||||
DWORD flags;
|
||||
|
Loading…
Reference in New Issue
Block a user