Есть следующая функция, получающая скриншот
procedure ScreenShot(const Width, Height: LongInt; const Filename: PChar);
var
Bih: TBitmapInfoHeader;
Bfh: TBitmapFileHeader;
CDC, DC: HDC;
CBmp: HBitMap;
Bmp: Pointer;
BmpInfo: TBitMapInfo;
F, Written, Size: LongWord;
begin
DC := GetDC(0);
CDC := CreateCompatibleDC(DC);
Bih.biSize := SizeOf(TBitmapInfoHeader);
Bih.biWidth := Width;
Bih.biHeight := Height;
Bih.biPlanes := 1;
Bih.biBitCount := GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES);
if Bih.biBitCount = 32 then Bih.biBitCount := 24;
Bfh.bfType := $4D42;
Bfh.bfOffBits := SizeOf(TBitmapFileHeader) + SizeOf(TBitmapInfoHeader);
Size := Width * Height * 3;
BmpInfo.bmiHeader := Bih;
CBmp := CreateDIBSection(DC, BmpInfo, 0, Bmp, 0, 0);
SelectObject(CDC, CBmp);
StretchBlt(CDC, 0, 0, Width, Height, DC, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY);
F := CreateFile(Filename, GENERIC_WRITE, 0, nil, CREATE_ALWAYS, 0, 0);
WriteFile(F, Bfh, SizeOf(TBitmapFileHeader), Written, nil);
WriteFile(F, Bih, SizeOf(TBitmapInfoHeader), Written, nil);
WriteFile(F, Bmp^, Size, Written, nil);
CloseHandle(F);
end;
Она отлично работает, если у программы нет окна, но если создать простейшее окно, хотя бы функцией CreateWindowEx, то скрин не создается

Как быть?
Здравствуйте, ldr, Вы писали:
ldr>Есть следующая функция, получающая скриншот
ldr>ldr>procedure ScreenShot(const Width, Height: LongInt; const Filename: PChar);
ldr>var
ldr> Bih: TBitmapInfoHeader;
ldr> Bfh: TBitmapFileHeader;
ldr> CDC, DC: HDC;
ldr> CBmp: HBitMap;
ldr> Bmp: Pointer;
ldr> BmpInfo: TBitMapInfo;
ldr> F, Written, Size: LongWord;
ldr>begin
//.erax: попробуй так
HWND hDeskWnd = GetDesktopWindow();
DC = GetDC(hDeskWnd);
//.erax:
ldr> //DC := GetDC(0);
ldr> CDC := CreateCompatibleDC(DC);
ldr> Bih.biSize := SizeOf(TBitmapInfoHeader);
ldr> Bih.biWidth := Width;
ldr> Bih.biHeight := Height;
ldr> Bih.biPlanes := 1;
ldr> Bih.biBitCount := GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES);
ldr> if Bih.biBitCount = 32 then Bih.biBitCount := 24;
ldr> Bfh.bfType := $4D42;
ldr> Bfh.bfOffBits := SizeOf(TBitmapFileHeader) + SizeOf(TBitmapInfoHeader);
ldr> Size := Width * Height * 3;
ldr> BmpInfo.bmiHeader := Bih;
ldr> CBmp := CreateDIBSection(DC, BmpInfo, 0, Bmp, 0, 0);
ldr> SelectObject(CDC, CBmp);
ldr> StretchBlt(CDC, 0, 0, Width, Height, DC, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY);
ldr> F := CreateFile(Filename, GENERIC_WRITE, 0, nil, CREATE_ALWAYS, 0, 0);
ldr> WriteFile(F, Bfh, SizeOf(TBitmapFileHeader), Written, nil);
ldr> WriteFile(F, Bih, SizeOf(TBitmapInfoHeader), Written, nil);
ldr> WriteFile(F, Bmp^, Size, Written, nil);
ldr> CloseHandle(F);
ldr>end;
ldr>
ldr>Она отлично работает, если у программы нет окна, но если создать простейшее окно, хотя бы функцией CreateWindowEx, то скрин не создается
Как быть?