Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi WriteConsoleOutput (https://www.delphipraxis.net/24210-writeconsoleoutput.html)

SleepyMaster 17. Jun 2004 15:01


WriteConsoleOutput
 
Hi ihrs

Ich schaffe es leider nicht mit diesem Code eine Ausgabe zu erstellen.

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  CH: THandle;
  p:pointer;
  CI: array[0..10,0..10]of CHAR_INFO;
  x,y: COORD;
  z: SMALL_RECT;
  i,j:integer;
begin
for i:=low(ci) to high(ci)do
  for j:=low(ci[i]) to high(ci[i])do
    begin
    ci[i,j].UnicodeChar:='A';
    ci[i,j].Attributes:=FOREGROUND_BLUE;
    ci[i,j].AsciiChar:='A';
    end;
CH:=0;
p:=AllocMem(sizeof(TSecurityAttributes));
PSECURITYATTRIBUTES(p).nLength:=sizeof(TSecurityAttributes);
PSECURITYATTRIBUTES(p).lpSecurityDescriptor:=nil;
PSECURITYATTRIBUTES(p).bInheritHandle:=true;
AllocConsole;
SetConsoleTitle('Hallo');
CH:=CreateConsoleScreenBuffer(GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, p, CONSOLE_TEXTMODE_BUFFER, nil);
x.X:=high(ci)-low(ci);
x.Y:=high(ci[high(ci)])-low(ci[high(ci)]);
y.X:=0;
y.Y:=0;
z.Left:=low(CI);
z.Top:=low(CI[low(CI)]);
z.Right:=high(CI);
z.Bottom:=high(CI[low(CI)]);
WriteConsoleOutput(CH,@ci,x,y,z);
ShowMessage(inttostr(GetLastError()));
end;
Wo liegt der Fehler?

shmia 17. Jun 2004 15:21

Re: WriteConsoleOutput
 
Delphi-Quellcode:
CH:=CreateConsoleScreenBuffer(GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, p, CONSOLE_TEXTMODE_BUFFER, nil);
if CH = INVALID_HANDLE_VALUE then // Handle immer überprüfen
   RaiseLastWin32Error;
if not SetConsoleActiveScreenBuffer(CH) then  // vergessen den ScreenBuffer zu aktivieren ???
   RaiseLastWin32Error;

SleepyMaster 17. Jun 2004 16:13

Re: WriteConsoleOutput
 
Jo! So gehts! Vielen Dank!


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:46 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz