002
21.09.2004, 17:11 Uhr
~chris182
Gast
|
Es funktioniert nicht. Das Prog. kopiert noch fleißig die Buffers. Und es wird eine Datei erstellt. Allerdings ist sie leer. Obwohl sich Daten im Buffer befanden. Hier ist es nochmal: ganz unten ist die CreateFile funktion.
C++: |
#include <iostream> #include <stdlib.h> #include <windows.h> #include <stdio.h>
int main(int argc, char *argv[]) {
HANDLE hStdout, hNewScreenBuffer; SMALL_RECT srctReadRect; SMALL_RECT srctWriteRect; CHAR_INFO chiBuffer[320]; // [4][80]; COORD coordBufSize; COORD coordBufCoord; BOOL fSuccess; // Get a handle to the STDOUT screen buffer to copy from and // create a new screen buffer to copy to. hStdout = GetStdHandle(STD_OUTPUT_HANDLE); hNewScreenBuffer = CreateConsoleScreenBuffer( GENERIC_READ | // read/write access GENERIC_WRITE, 0, // not shared NULL, // default security attributes CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE NULL); // reserved; must be NULL if (hStdout == INVALID_HANDLE_VALUE || hNewScreenBuffer == INVALID_HANDLE_VALUE) { printf("CreateConsoleScreenBuffer failed (%d)\n", GetLastError()); return(0); } // Make the new screen buffer the active screen buffer. if (! SetConsoleActiveScreenBuffer(hNewScreenBuffer) ) { printf("SetConsoleActiveScreenBuffer failed (%d)\n", GetLastError()); return(0); } // Set the source rectangle. srctReadRect.Top = 0; // top left: row 0, col 0 srctReadRect.Left = 0; //das bedeutet fange in der oberen linken ecke an zu lesen srctReadRect.Bottom = 4; // zeilen einlesen srctReadRect.Right = 80; //zeichen einlesen // The temporary buffer size is 2 rows x 80 columns. coordBufSize.Y = 4; //zeilen werden ausgegeben achtung! es kann nur soviel ausgegeben werden, wie auch eingelesen wird! coordBufSize.X = 80; //zeichen werden ausgegeben // 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, // screen buffer to read from chiBuffer, // buffer to copy into coordBufSize, // col-row size of chiBuffer coordBufCoord, // top left dest. cell in chiBuffer &srctReadRect); // screen buffer source rectangle | fläche, die eingelesen werden soll if (! fSuccess) { printf("ReadConsoleOutput failed (%d)\n", GetLastError()); return(0); } // Set the destination rectangle. srctWriteRect.Top = 0; // top lt: row 10, col 0 schreibe die pufferdaten an diese position 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, // screen buffer to write to chiBuffer, // buffer to copy from coordBufSize, // col-row size of chiBuffer coordBufCoord, // top left src cell in chiBuffer &srctWriteRect); // dest. screen buffer rectangle if (! fSuccess) { printf("WriteConsoleOutput failed (%d)\n", GetLastError()); return(0); } Sleep(1000);
// Restore the original active screen buffer. if (! SetConsoleActiveScreenBuffer(hStdout)) { printf("SetConsoleActiveScreenBuffer failed (%d)\n", GetLastError()); return(0); }
//öffnet/erstellt eine datei...
HANDLE hFile; hFile = CreateFile(TEXT("myfile.txt"), // file to create GENERIC_WRITE, // open for writing 0, // do not share NULL, // default security CREATE_ALWAYS, // overwrite existing FILE_ATTRIBUTE_NORMAL | // normal file FILE_FLAG_OVERLAPPED, // asynchronous I/O NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE) { printf("Could not open file (error %d)\n", GetLastError()); return 0; }
//schreibt in die datei...
#define BUFSIZE 4096
DWORD dwBytesRead, dwBytesWritten, dwBufSize=BUFSIZE; //schreibe den konsolenpuffer WriteFile(hFile, chiBuffer, dwBytesRead, &dwBytesWritten, NULL);
return(0); }
|
Bearbeitung: |
Bitte mal CPP-Tags verwenden! dafür sind die schliesslich da!
|
Dieser Post wurde am 21.09.2004 um 22:03 Uhr von FloSoft editiert. |