IMHO.WS

IMHO.WS (http://www.imho.ws/index.php)
-   Программирование (http://www.imho.ws/forumdisplay.php?f=40)
-   -   Как программно заграбить полноэкранное DOS окно (http://www.imho.ws/showthread.php?t=94876)

Chaser 27.10.2005 14:43

Как программно заграбить полноэкранное DOS окно
 
Кто знает, как программно заграбить (аналог PrintScreen) полноэкранное DOS окно?
Нижеприведенный код, запоминающий Windows окна на полноэкранном DOS окне дает белый квадрат:

var
bmp: TBitmap;
dc: hdc;
jp: TJPEGImage;
begin
bmp := TBitmap.Create;
jp :=TJpegImage.Create;
bmp.Width := Screen.Width;
bmp.Height := Screen.Height;

BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,
GetDC(GetDesktopWindow), 0, 0, SRCCopy);
Clipboard.Assign(bmp);

if Clipboard.HasFormat(CF_BITMAP) then
begin
bmp.Canvas.Font.Color := clGreen;
bmp.Canvas.Font.Size:=10;
try
with Bmp do
begin
jp.Assign(Bmp);
jp.SaveToFile(IntToStr(i)+'.jpg');
end;
except

end;
end;
end;

SapeR 28.10.2005 02:30

то есть читать не окно а консоль ?

слямзил из МСДН:
Reading and Writing Blocks of Characters and Attributes
Код:

#include <windows.h>
 
VOID main(void)
{
    HANDLE hStdout, hNewScreenBuffer;
    SMALL_RECT srctReadRect;
    SMALL_RECT srctWriteRect;
    CHAR_INFO chiBuffer[160]; // [2][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,                    // no security attributes
      CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE
      NULL);                  // reserved; must be NULL
    if (hStdout == INVALID_HANDLE_VALUE ||
            hNewScreenBuffer == INVALID_HANDLE_VALUE)
    {
        MyErrorExit("CreateConsoleScreenBuffer");
    }
 
    // Make the new screen buffer the active screen buffer.
 
    if (! SetConsoleActiveScreenBuffer(hNewScreenBuffer) )
        MyErrorExit("SetConsoleActiveScreenBuffer");
 
    // Set the source rectangle.
 
    srctReadRect.Top = 0;    // top left: row 0, col 0
    srctReadRect.Left = 0;
    srctReadRect.Bottom = 1; // bot. 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,        // 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
    if (! fSuccess)
        MyErrorExit("ReadConsoleOutput");
 
    // 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, // 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)
        MyErrorExit("WriteConsoleOutput");
    Sleep(10000);
 
    // Restore the original active screen buffer.
 
    if (! SetConsoleActiveScreenBuffer(hStdout))
        MyErrorExit("SetConsoleActiveScreenBuffer");
 
}


Chaser 31.10.2005 16:11

А можно ли это перевести на Delphi?


Часовой пояс GMT +4, время: 00:52.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.