Вопрос

I have a program that takes a shot of the screen in 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.

My question rests on the LoadFromDevice(), and SaveToFile() functions. What function(s), (if any), could be used to implement these in the C programming language. Trying to keep away from third party libraries as close a possible. (WinAPI)

Это было полезно?

Решение

Look At this

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); 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top