More updates to test programs for font/resizing work
This commit is contained in:
parent
ebefb91e80
commit
33c5687d4a
@ -1,25 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "TestUtil.cc"
|
||||
|
||||
int main() {
|
||||
const HANDLE conout = CreateFileW(L"CONOUT$",
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, 0, NULL);
|
||||
ASSERT(conout != INVALID_HANDLE_VALUE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO info = {};
|
||||
BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
|
||||
ASSERT(ret && "GetConsoleScreenBufferInfo failed");
|
||||
|
||||
trace("srWindow={L=%d,T=%d,R=%d,B=%d}", info.srWindow.Left, info.srWindow.Top, info.srWindow.Right, info.srWindow.Bottom);
|
||||
printf("srWindow={L=%d,T=%d,R=%d,B=%d}\n", info.srWindow.Left, info.srWindow.Top, info.srWindow.Right, info.srWindow.Bottom);
|
||||
|
||||
trace("dwSize=%d,%d", info.dwSize.X);
|
||||
printf("dwSize=%d,%d\n", info.dwSize.X);
|
||||
|
||||
return 0;
|
||||
}
|
38
misc/GetConsolePos.cc
Normal file
38
misc/GetConsolePos.cc
Normal file
@ -0,0 +1,38 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "TestUtil.cc"
|
||||
|
||||
int main() {
|
||||
const HANDLE conout = openConout();
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO info = {};
|
||||
BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
|
||||
ASSERT(ret && "GetConsoleScreenBufferInfo failed");
|
||||
|
||||
trace("srWindow={L=%d,T=%d,R=%d,B=%d}", info.srWindow.Left, info.srWindow.Top, info.srWindow.Right, info.srWindow.Bottom);
|
||||
printf("srWindow={L=%d,T=%d,R=%d,B=%d}\n", info.srWindow.Left, info.srWindow.Top, info.srWindow.Right, info.srWindow.Bottom);
|
||||
|
||||
trace("dwSize=%d,%d", info.dwSize.X, info.dwSize.Y);
|
||||
printf("dwSize=%d,%d\n", info.dwSize.X, info.dwSize.Y);
|
||||
|
||||
const HWND hwnd = GetConsoleWindow();
|
||||
if (hwnd != NULL) {
|
||||
RECT r = {};
|
||||
if (GetWindowRect(hwnd, &r)) {
|
||||
const int w = r.right - r.left;
|
||||
const int h = r.bottom - r.top;
|
||||
trace("hwnd: pos=(%d,%d) size=(%d,%d)", r.left, r.top, w, h);
|
||||
printf("hwnd: pos=(%d,%d) size=(%d,%d)\n", r.left, r.top, w, h);
|
||||
} else {
|
||||
trace("GetWindowRect failed");
|
||||
printf("GetWindowRect failed\n");
|
||||
}
|
||||
} else {
|
||||
trace("GetConsoleWindow returned NULL");
|
||||
printf("GetConsoleWindow returned NULL\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,3 +1,9 @@
|
||||
// Determines whether this is a new console by testing whether MARK moves the
|
||||
// cursor.
|
||||
//
|
||||
// WARNING: This test program may behave erratically if run under winpty.
|
||||
//
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@ -8,6 +14,23 @@
|
||||
const int SC_CONSOLE_MARK = 0xFFF2;
|
||||
const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
|
||||
|
||||
static COORD getWindowPos(HANDLE conout) {
|
||||
CONSOLE_SCREEN_BUFFER_INFO info = {};
|
||||
BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
|
||||
ASSERT(ret && "GetConsoleScreenBufferInfo failed");
|
||||
return { info.srWindow.Left, info.srWindow.Top };
|
||||
}
|
||||
|
||||
static COORD getWindowSize(HANDLE conout) {
|
||||
CONSOLE_SCREEN_BUFFER_INFO info = {};
|
||||
BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
|
||||
ASSERT(ret && "GetConsoleScreenBufferInfo failed");
|
||||
return {
|
||||
static_cast<short>(info.srWindow.Right - info.srWindow.Left + 1),
|
||||
static_cast<short>(info.srWindow.Bottom - info.srWindow.Top + 1)
|
||||
};
|
||||
}
|
||||
|
||||
static COORD getCursorPos(HANDLE conout) {
|
||||
CONSOLE_SCREEN_BUFFER_INFO info = {};
|
||||
BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
|
||||
@ -25,24 +48,39 @@ int main() {
|
||||
const HWND hwnd = GetConsoleWindow();
|
||||
ASSERT(hwnd != NULL && "GetConsoleWindow() returned NULL");
|
||||
|
||||
bool isWindows10NewConsole = false;
|
||||
COORD pos = getCursorPos(conout);
|
||||
setCursorPos(conout, { 1, 0 });
|
||||
// With the legacy console, the Mark command moves the the cursor to the
|
||||
// top-left cell of the visible console window. Determine whether this
|
||||
// is the new console by seeing if the cursor moves.
|
||||
|
||||
const auto windowSize = getWindowSize(conout);
|
||||
if (windowSize.X <= 1) {
|
||||
printf("Error: console window must be at least 2 columns wide\n");
|
||||
trace("Error: console window must be at least 2 columns wide");
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool cursorMoved = false;
|
||||
const auto initialPos = getCursorPos(conout);
|
||||
|
||||
const auto windowPos = getWindowPos(conout);
|
||||
setCursorPos(conout, { static_cast<short>(windowPos.X + 1), windowPos.Y });
|
||||
|
||||
{
|
||||
COORD posA = getCursorPos(conout);
|
||||
const auto posA = getCursorPos(conout);
|
||||
SendMessage(hwnd, WM_SYSCOMMAND, SC_CONSOLE_MARK, 0);
|
||||
COORD posB = getCursorPos(conout);
|
||||
isWindows10NewConsole = !memcmp(&posA, &posB, sizeof(posA));
|
||||
const auto posB = getCursorPos(conout);
|
||||
cursorMoved = memcmp(&posA, &posB, sizeof(posA)) != 0;
|
||||
SendMessage(hwnd, WM_CHAR, 27, 0x00010001); // Send ESCAPE
|
||||
}
|
||||
|
||||
setCursorPos(conout, pos);
|
||||
setCursorPos(conout, initialPos);
|
||||
|
||||
if (isWindows10NewConsole) {
|
||||
printf("New Windows 10 console\n");
|
||||
if (cursorMoved) {
|
||||
printf("Legacy console (i.e. MARK moved cursor)\n");
|
||||
trace("Legacy console (i.e. MARK moved cursor)");
|
||||
} else {
|
||||
printf("Legacy console\n");
|
||||
printf("Windows 10 new console (i.e MARK did not move cursor)\n");
|
||||
trace("Windows 10 new console (i.e MARK did not move cursor)");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
BOOL ret = MoveWindow(hwnd, x, y, w, h, TRUE);
|
||||
trace("MoveWindow: ret=%d", ret);
|
||||
printf("MoveWindow: ret=%d", ret);
|
||||
printf("MoveWindow: ret=%d\n", ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
9
misc/build32.sh
Executable file
9
misc/build32.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
name=$1
|
||||
name=${name%.}
|
||||
name=${name%.cc}
|
||||
name=${name%.exe}
|
||||
echo Compiling $name.cc to $name.exe
|
||||
i686-w64-mingw32-g++.exe -static -std=c++11 $name.cc -o $name.exe
|
||||
i686-w64-mingw32-strip $name.exe
|
9
misc/build64.sh
Executable file
9
misc/build64.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
name=$1
|
||||
name=${name%.}
|
||||
name=${name%.cc}
|
||||
name=${name%.exe}
|
||||
echo Compiling $name.cc to $name.exe
|
||||
x86_64-w64-mingw32-g++.exe -static -std=c++11 $name.cc -o $name.exe
|
||||
x86_64-w64-mingw32-strip $name.exe
|
@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
g++ Win32Echo1.cc -o Win32Echo1
|
||||
g++ Win32Echo2.cc -o Win32Echo2
|
||||
g++ Win32Write1.cc -o Win32Write1
|
Loading…
Reference in New Issue
Block a user