winpty/Misc/SelectAllTest.cc
Ryan Prichard bba54c0703 Use "Select All" instead of "Mark" to freeze the console.
The Mark command moves the cursor to the top-left, which interferes with
lynx, a full-screen Cygwin web browser, and probably other programs.
The Select All command also puts the console into selection mode, blocking
console output.
2011-11-24 03:03:25 -08:00

41 lines
964 B
C++

#define _WIN32_WINNT 0x0501
#include <stdio.h>
#include <windows.h>
const int SC_CONSOLE_MARK = 0xFFF2;
const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
CALLBACK DWORD pausingThread(LPVOID dummy)
{
HWND hwnd = GetConsoleWindow();
while (true) {
SendMessage(hwnd, WM_SYSCOMMAND, SC_CONSOLE_SELECT_ALL, 0);
SendMessage(hwnd, WM_CHAR, 27, 0x00010001);
}
}
int main()
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(out, &info);
COORD initial = info.dwCursorPosition;
CreateThread(NULL, 0,
pausingThread, NULL,
0, NULL);
while (true) {
GetConsoleScreenBufferInfo(out, &info);
if (memcmp(&info.dwCursorPosition, &initial, sizeof(COORD)) != 0) {
printf("cursor moved to [%d,%d]\n",
info.dwCursorPosition.X,
info.dwCursorPosition.Y);
GetConsoleScreenBufferInfo(out, &info);
initial = info.dwCursorPosition;
}
}
return 0;
}