- Offizieller Beitrag
Ich bin mal wieder über meine vor Urzeiten angefangene Console-UDF gestolpert. Damals hatte ich nur einige rudimentäre Umsetzungen gemacht. Nun wollte ich die gesamte Console API in Angriff nehmen und bin dabei über folgende Struktur gestolpert:
typedef struct _CONSOLE_FONT_INFOEX {
ULONG cbSize;
DWORD nFont;
COORD dwFontSize;
UINT FontFamily;
UINT FontWeight;
WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
Das würde ich in AutoIt erstmal so umsetzen:
; struct _COORD
Global $tag_COORD = 'SHORT X;SHORT Y;'
; struct _CONSOLE_FONT_INFOEX
Global $tag_CONSOLE_FONT_INFOEX = _
'ULONG cbSize;' & _
'DWORD nFont;' & _
'STRUCT;' & $tag_COORD & 'ENDSTRUCT;' & _ ; dwFontSize
'UINT FontFamily;' & _
'UINT FontWeight;' & _
'WCHAR FaceName[LF_FACESIZE];'
Alles anzeigen
Unklar ist mir: WCHAR FaceName[LF_FACESIZE];
Als Bsp. für eine Umsetzung in C# habe ich hier was gefunden:
// Set console font to Lucida Console.
CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX();
newInfo.cbSize = (uint) Marshal.SizeOf(newInfo);
newInfo.FontFamily = TMPF_TRUETYPE;
IntPtr ptr = new IntPtr(newInfo.FaceName);
Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length);
// Get some settings from current font.
newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y);
newInfo.FontWeight = info.FontWeight;
SetCurrentConsoleFontEx(hnd, false, newInfo);
Die interessanten Zeilen für FaceName sind hier:
IntPtr ptr = new IntPtr(newInfo.FaceName);
Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length);
Daraus würde ich jetzt schließen, dass ich das so umzusetzen habe:
; statt:
'WCHAR FaceName[LF_FACESIZE];'
; jetzt:
'ptr FaceName;'
; und zur Laufzeit
$fontName = 'Consolas' ; als Bsp. - bzw. Ergebnis von "GetCurrentConsoleFont()"
$tWCHARarray = DllStructCreate('wchar FontName[' & StringLen($fontName) & '];')
$tWCHARarray.FontName = $fontName
$t_CONSOLE_FONT_INFOEX = DllStructCreate($tag_CONSOLE_FONT_INFOEX)
$t_CONSOLE_FONT_INFOEX.FaceName = DllStructGetPtr($tWCHARarray)
Alles anzeigen
Habe ich das soweit richtig interpretiert?
Ein zweiter Punkt:
Die Struktur enthält die eingebettete Struktur COORD. Durch das Integrieren mittels: 'STRUCT;' & $tag_COORD & 'ENDSTRUCT;' geht mir ja der Feldname dwFontSize verloren.
In C# wird in dem Bsp. auf X in dwFontSize mit info.dwFontSize.X zugegriffen. In meiner Umsetzung wäre das im Moment: $t_CONSOLE_FONT_INFOEX.X Grundsätzlich kein Problem, solange nicht eine zweite eingebettete Struktur mit denselben Feldern auftaucht.
Aber genau das passiert z.B. in folgender Struktur:
typedef struct _CONSOLE_SCREEN_BUFFER_INFO {
COORD dwSize;
COORD dwCursorPosition;
WORD wAttributes;
SMALL_RECT srWindow;
COORD dwMaximumWindowSize;
} CONSOLE_SCREEN_BUFFER_INFO;
Wie kann ich das lösen? Bleibt da nur der Zugriff über den Index?
EDIT:
Oder so?
Global $tag_SMALL_RECT = _
'SHORT Left;' & _
'SHORT Top;' & _
'SHORT Right;' & _
'SHORT Bottom;'
Global $tag_CONSOLE_SCREEN_BUFFER_INFO = _
'PTR dwSize;' & _
'PTR dwCursorPosition;' & _
'WORD wAttributes;' & _
'PTR srWindow;' & _
'PTR dwMaximumWindowSize;'
Global $t_dwSize = DllStructCreate($tag_COORD)
Global $t_dwCursorPosition = DllStructCreate($tag_COORD)
Global $t_srWindow = DllStructCreate($tag_SMALL_RECT)
Global $t_dwMaximumWindowSize = DllStructCreate($tag_COORD)
Global $t_CONSOLE_SCREEN_BUFFER_INFO = DllStructCreate($tag_CONSOLE_SCREEN_BUFFER_INFO)
$t_dwSize.X = ...
$t_dwSize.Y = ...
$t_CONSOLE_SCREEN_BUFFER_INFO.dwSize = DllStructGetPtr($t_dwSize)
$t_dwCursorPosition.X = ...
$t_dwCursorPosition.Y = ...
$t_CONSOLE_SCREEN_BUFFER_INFO.dwCursorPosition = DllStructGetPtr($t_dwCursorPosition)
$t_srWindow.Left = ...
$t_srWindow.Top = ...
$t_srWindow.Right = ...
$t_srWindow.Bottom = ...
$t_CONSOLE_SCREEN_BUFFER_INFO.srWindow = DllStructGetPtr($t_srWindow)
$t_dwMaximumWindowSize.X = ...
$t_dwMaximumWindowSize.Y = ...
$t_CONSOLE_SCREEN_BUFFER_INFO.dwMaximumWindowSize = DllStructGetPtr($t_dwMaximumWindowSize)
; Und aus einer befüllten Struktur dann lesen:
; get dwSize
Global $tReadSize = DllStructCreate($tag_COORD, $t_CONSOLE_SCREEN_BUFFER_INFO.dwSize)
ConsoleWrite('dwSize.X: ' & $tReadSize.X & @CrLf)
ConsoleWrite('dwSize.Y: ' & $tReadSize.Y & @CrLf)
Alles anzeigen