gpt4 book ai didi

c - Pascal 到 C 的翻译

转载 作者:行者123 更新时间:2023-11-30 15:39:32 25 4
gpt4 key购买 nike

我有一个用 pascal 拍摄屏幕的程序:

uses Graphics, 
LCLIntf,
LCLType;

var
Screen: TBitmap;
ScreenDC: HDC;
begin
Screen := TBitmap.Create;
ScreenDC := GetDC(0);
Screen.LoadFromDevice(ScreenDC);
ReleaseDC(0, ScreenDC);
Screen.SaveToFile("Screen.bmp");
end.

我的问题在于LoadFromDevice() ,和SaveToFile()功能。可以使用哪些函数(如果有)在 C 编程语言中实现这些功能。尝试尽可能远离第三方库。 (WinAPI)

最佳答案

看看这个

HDC hDC = GetDC(g_hWnd); 
LPRECT rect = (LPRECT)malloc(sizeof(RECT));
GetWindowRect(g_hWnd,rect);
int h = rect->right - rect->left;
int w = rect->bottom - rect->top;
LPRECT rect = (LPRECT)malloc(sizeof(RECT));

GetWindowRect(g_hWnd,rect);
HBITMAP hBmp = CreateCompatibleBitmap(hDC,w,h);
PBITMAPINFO pbmi;
pbmi = CreateBitmapInfoStruct(g_hWnd,hBmp);

CreateBMPFile(g_hWnd, TEXT("c:\\TEMPO\\TestG2.bmp"), pbmi, hBmp, hDC) ;
ReleaseDC(g_hWnd,hDC);
DeleteObject(hBmp);
DeleteObject(pbmi);

if (rect != nullptr)
free(rect);

关于c - Pascal 到 C 的翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21384798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com