|
hum - they want the source
screen capture can be done using winAPI like this:
call GetDC(0) to get the screen dc where all is painted;
determine the rectangle size - by call to GetClientRect, with window handle from GetDesktopWindow();
CreateBitmap with the determined size; call BitBlt to copy to our bitmap from screen;
finally use ReleaseDc to free allocated DC;
sorry that i have no time to write it in C.
DLL will be needed if you want to hook keyboard clicks.
|
|
|
|
|
Hey, thanks! Here's what I wrote in Borland Delphi 7 based on your tips:
procedure TForm1.Button1Click(Sender: TObject);
var
hWndIE, AppDC: THandle;
Rect: TRect;
begin
hWndIE := FindWindow('IEFrame', nil); // http://delphi.about.com/library/weekly/aa060303b.htm
if hWndIE > 0 then
begin
try
Application.Minimize;
AppDC := GetWindowDC(hWndIE);
Windows.GetClientRect(hWndIE, Rect);
with Image.Picture.Bitmap do
begin
PixelFormat := pf32bit;
Height := Rect.Bottom - Rect.Top + 1;
Width := Rect.Right - Rect.Left + 1;
{thanks to http://www.swissdelphicenter.ch/torry/showcode.php?id=140}
BitBlt(Canvas.Handle, 0, 0, Width, Height, AppDC, 0, 0, SRCCOPY);
Modified := True;
end;
finally
ReleaseDC(0, hWndIE);
end;
Application.Restore;
end;
end;
|
|
|
|
|
HI
i used the gdi way to capture the screen. bu there seems to be some problems.
1) cursor is not captured.. if so how can i draw the cursor on the capture image...
2) i have form in C# whose Opacity=0.25 percent. and there are some writings on them... i could not cathc them also...
is there anywya to capture this thing also... i suppose they r like overlays..
ve
|
|
|
|
|
Well , thanks , but I'm coding in pure C using the
win32 api.
I have something that looks like this :
<br />
HBITMAP hbm;<br />
HDC screendc;<br />
HDC imagedc;<br />
int w;<br />
int h;<br />
<br />
int init(void)<br />
{<br />
screendc = GetDC(NULL);<br />
imagedc = CreateCompatibleDC(screendc);<br />
w = GetSystemMetrics(SM_CXSCREEN);<br />
h = GetSystemMetrics(SM_CYSCREEN);<br />
<br />
hbm = CreateCompatibleBitmap(imagedc,w,h);<br />
ReleaseDC(NULL,screendc);<br />
}<br />
<br />
void CaptureSave(LPSTR szFname)<br />
{<br />
SelectObject(imagedc,hbm);<br />
screendc = GetDC(NULL);<br />
BitBlt(imagedc,0,0,w,h,screendc,0,0,SRCCOPY);<br />
ReleaseDC(NULL,screendc);<br />
<br />
ConvertSaveDIB(szFname,hbm);<br />
}<br />
<br />
void ConvertSaveDIB(LPSTR fn,HBITMAP bm)<br />
{<br />
<br />
<br />
}<br />
The tears shed in vain
and the hatred and pain
will be nothing but dust
at the end of the day
|
|
|
|
|
Hi , I have a good way for you to get a hold of the screen.... :
this method has worked for me without fail , for more than a year now ,
and Im still waiting to find a pc that won't be able to perform this function
To use it simply add the forward declaration (prototype) at the top of your file :
int SnapShot(char* fname);
And then , when you want to use it , simply call it with a file name :
<br />
{<br />
SnapShot("img0.bmp");<br />
}<br />
<br />
int SnapShot(char* fname)<br />
{<br />
HBITMAP hdib;<br />
BITMAPINFO bi;<br />
BITMAPFILEHEADER bfh;<br />
void *bits;
bits=NULL;<br />
<br />
int WIDTH,HEIGHT,BPP;<br />
WIDTH = GetSystemMetrics(SM_CXSCREEN);<br />
HEIGHT=GetSystemMetrics(SM_CYSCREEN);<br />
BPP = 24; <br />
<br />
bi.bmiHeader.biSize = 40;<br />
bi.bmiHeader.biWidth = WIDTH;<br />
bi.bmiHeader.biHeight = HEIGHT;<br />
bi.bmiHeader.biPlanes = 1;<br />
bi.bmiHeader.biBitCount = BPP;<br />
bi.bmiHeader.biCompression = BI_RGB;<br />
bi.bmiHeader.biSizeImage = (BPP/8)*(WIDTH)*(HEIGHT);<br />
bi.bmiHeader.biXPelsPerMeter =0;<br />
bi.bmiHeader.biYPelsPerMeter =0;<br />
bi.bmiHeader.biClrUsed =0;<br />
bi.bmiHeader.biClrImportant =0;<br />
<br />
bfh.bfType = 0x4D42;<br />
bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);<br />
bfh.bfSize = bi.bmiHeader.biSizeImage+bfh.bfOffBits;<br />
bfh.bfReserved1 = 0;<br />
bfh.bfReserved2 = 0;<br />
<br />
HDC hdc = GetDCEx (hWnd,NULL, DCX_CACHE|DCX_LOCKWINDOWUPDATE) ;<br />
HDC fdc = CreateCompatibleDC(hdc);<br />
<br />
hdib = CreateDIBSection(fdc,&bi,DIB_RGB_COLORS,&bits,NULL,0);<br />
SelectObject(fdc,hdib);<br />
BitBlt(fdc,0,0,WIDTH,HEIGHT,hImgDC,0,0,SRCCOPY);<br />
ReleaseDC(hWnd,hdc); <br />
<br />
<br />
<br />
<br />
char firstpath[255];<br />
GetCurrentDirectory(255,firstpath);<br />
if(SetCurrentDirectory("SnapShots") == 0)<br />
CreateDirectory("SnapShots",NULL); <br />
SetCurrentDirectory(firstpath);<br />
<br />
char *tempbuffer=malloc(sizeof(char)*255);<br />
sprintf(tempbuffer,"%s\\SnapShots\\%s",firstpath,fname);<br />
<br />
MessageBox(NULL,tempbuffer,"Creating...",MB_OK);<br />
<br />
BOOL bSuccess = FALSE ;<br />
DWORD dwBytesWritten ;<br />
HANDLE hFile ;<br />
hFile = CreateFile (tempbuffer, GENERIC_WRITE,FILE_SHARE_WRITE, NULL,<br />
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) ; <br />
if (hFile == INVALID_HANDLE_VALUE)<br />
return FALSE ;<br />
bSuccess = WriteFile (hFile,&bfh,sizeof(bfh), &dwBytesWritten, NULL) ;<br />
<br />
bSuccess = WriteFile (hFile,&bi.bmiHeader,sizeof(bi.bmiHeader), &dwBytesWritten, NULL) ;<br />
<br />
bSuccess = WriteFile (hFile,bits,bi.bmiHeader.biSizeImage, &dwBytesWritten, NULL) ;<br />
<br />
CloseHandle (hFile) ;<br />
DeleteDC(fdc);<br />
DeleteObject(hdib);<br />
free(tempbuffer);<br />
return TRUE;<br />
}<br />
The tears shed in vain
and the hatred and pain
will be nothing but dust
at the end of the day
|
|
|
|
|