AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Cpp > Pas

Ein Thema von Nils_13 · begonnen am 28. Mär 2008 · letzter Beitrag vom 28. Mär 2008
 
wido

Registriert seit: 2. Jan 2006
122 Beiträge
 
#5

Re: Cpp > Pas

  Alt 28. Mär 2008, 18:21
Ahja, sollst ja auch was lernen bei:

Code:
CHAR_INFO chiBuffer[160]; // [2][80]; <--
Ist ein einfaches Array aus CHAR_INFO. Die Übersetzung lautet entsprechend einfach:

chiBuffer : array[0..159] of CHAR_INFO;
Code:
hNewScreenBuffer := CreateConsoleScreenBuffer(GENERIC_READ, GENERIC_WRITE, nil, 0, CONSOLE_TEXTMODE_BUFFER, 0); <-- [Fehler] Unit1.pas(34): Inkompatible Typen: 'Integer' und 'Pointer' >>> siehe "Nützliches"
Schau im Original Code. Da steht GENERIC_READ | GENERIC_WRITE und nicht GENERIC_READ, GENERIC_WRITE. | ist in C die Bitweise or Verknüpfung, entsprechend wird daraus:

hNewScreenBuffer := CreateConsoleScreenBuffer(GENERIC_READ or GENERIC_WRITE, 0, nil, CONSOLE_TEXTMODE_BUFFER, nil); Auf die anderen Fehler wurdest ja bereits hingewiesen. Entsprechend hier mal das komplette Machwerk:

Delphi-Quellcode:
program Project2;

{$APPTYPE CONSOLE}

uses
  sysutils, windows;

var hStdout, hNewScreenBuffer : THandle;
    srctReadRect, srctWriteRect : _SMALL_RECT;
    coordBufSize, coordBufCoord : _COORD;
    fSuccess : Boolean;
    chiBuffer : array[0..159] of CHAR_INFO; // [2][80]; <--
begin
  hStdout := GetStdHandle(STD_OUTPUT_HANDLE);
  hNewScreenBuffer := CreateConsoleScreenBuffer(GENERIC_READ or GENERIC_WRITE, 0, nil, CONSOLE_TEXTMODE_BUFFER, nil);

  if (hStdout = INVALID_HANDLE_VALUE) or (hNewScreenBuffer = INVALID_HANDLE_VALUE) then
    raise Exception.Create('CreateConsoleScreenBuffer: '+IntToStr(GetLastError));

  if not SetConsoleActiveScreenBuffer(hNewScreenBuffer) then
    raise Exception.Create('SetConsoleActiveScreenBuffer: '+IntToStr(GetLastError));

  srctReadRect.Top := 0; // top left: row 0, col 0
  srctReadRect.Left := 0;
  srctReadRect.Bottom := 1; // bottom right: row 1, col 79
  srctReadRect.Right := 79;
  // The temporary buffer size is 2 rows x 80 columns
  coordBufSize.Y := 2;
  coordBufSize.X := 80;
  // The top left destination cell of the temporary buffer is
  // row 0, col 0.
  coordBufCoord.X := 0;
  coordBufCoord.Y := 0;

  // Copy the block from the screen buffer to the temp. buffer.
  fSuccess := ReadConsoleOutput(hStdout, @chiBuffer[0], coordBufSize, coordBufCoord, srctReadRect);
  if not fSuccess then
    raise Exception.Create('ReadConsoleOutput: '+IntToStr(GetLastError));

  // Set the destination rectangle.
  srctWriteRect.Top := 10; // top lt: row 10, col 0
  srctWriteRect.Left := 0;
  srctWriteRect.Bottom := 11; // bot. rt: row 11, col 79
  srctWriteRect.Right := 79;

  // Copy from the temporary buffer to the new screen buffer.
  fSuccess := WriteConsoleOutput(hNewScreenBuffer, @chiBuffer[0], coordBufSize, coordBufCoord, srctWriteRect);
  if not fSuccess then
    raise Exception.Create('WriteConsoleOutput: '+IntToStr(GetLastError));
  Sleep(5000); // Nötig ????

  // Restore the original active screen buffer.
  if not SetConsoleActiveScreenBuffer(hStdout) then
    raise Exception.Create('SetConsoleActiveScreenBuffer: '+IntToStr(GetLastError));
  readln;
end.
Compiled, macht aber gar nichts. Was sollte denn passieren? Hab keine Lust mich durch die API Dokumentation zu wühlen.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:31 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