0

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)

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
James Parsons
  • 6,097
  • 12
  • 68
  • 108
  • 3
    WinAPI **is** a third party library. Anyway googling "winapi screenshot" should give you plenty of references. And [the first one](http://wiki.freepascal.org/LCL_Internals) is from freepascal wiki. – Bartek Banachewicz Jan 27 '14 at 15:31
  • 1
    http://stackoverflow.com/questions/997175/how-can-i-take-a-screenshot-and-save-it-as-jpeg-on-windows – David Ranieri Jan 27 '14 at 15:32
  • 2
    Nothing. There is no such thing as a "screen" in C. You will need some platform-specific functionality. In you case, the winapi sounds like a good candidate. – Magnus Reftel Jan 27 '14 at 15:32
  • 1
    Yep, this is not translating Pascal to C, it's translating from using one set of APIs to using another set. You could have essentially the same work to do going between two different Pascal platforms. – Hot Licks Jan 27 '14 at 15:39
  • What do you mean by "Third-party" API? What would be an example of a "first-party API" by your working definition? – Brandin Jan 27 '14 at 16:24

1 Answers1

1

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); 
Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77