下可能會有所幫助:
#include "windows.h"
#include <conio.h>
int _tmain(int argc, _TCHAR* argv[])
{
bool hasSecondary = false;
POINT secondaryPosition;
POINT secondarySize;
POINT primarySize;
{
DISPLAY_DEVICE displayDevice;
displayDevice.cb = sizeof(DISPLAY_DEVICE);
DEVMODE deviceMode;
ZeroMemory(&deviceMode, sizeof(DEVMODE));
deviceMode.dmSize = sizeof(DEVMODE);
int i = 0;
while(::EnumDisplayDevices(NULL, i++, &displayDevice, 0))
{
if(displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP &&
!(displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
{
if(EnumDisplaySettingsEx(displayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &deviceMode, 0) == FALSE)
EnumDisplaySettingsEx(displayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &deviceMode, 0);
if(deviceMode.dmPosition.x != 0 || deviceMode.dmPosition.y != 0)
{
hasSecondary = true;
secondaryPosition.x = deviceMode.dmPosition.x;
secondaryPosition.y = deviceMode.dmPosition.y;
secondarySize.x = deviceMode.dmPelsWidth;
secondarySize.y = deviceMode.dmPelsHeight;
}
else
{
primarySize.x = deviceMode.dmPelsWidth;
primarySize.y = deviceMode.dmPelsHeight;
}
}
}
}
MoveWindow(GetConsoleWindow(),
secondaryPosition.x, secondaryPosition.y,
secondarySize.x, secondarySize.y,
TRUE);
_getch();
return 0;
}
有趣的問題。 +1 – 0xC0000022L 2011-05-22 02:41:24
+1 - 文檔似乎表明[GetLargestConsoleWindowSize](http://msdn.microsoft.com/en-us/library/ms683193.aspx)函數用於確定事物,在這種情況下,重新SOL。 :( – 2011-05-22 03:23:40
所以沒有辦法繞過這個重新編碼整個控制檯窗口系統? – tentonwire 2011-05-26 02:34:57