Device context to file

Post Reply
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Device context to file

Post by Natter »

Hi all !

How to save device context of a window in bmp-file ?
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Device context to file

Post by Natter »

hDeskTop:=GetWindowDc(FindWindow(...))

siz:=GetWndRect(hDeskTop)
hDC := CreateCompatibleDC( hDeskTop )
hBmp := CreateCompatibleBitMap( hDC, siz[4]-siz[2], siz[3]-siz[1])
hOldBmp:=SelectObject(hDc, hBmp)
BitBlt(hDc, 0, 0, siz[4]-siz[2], siz[3]-siz[1], hDeskTop, 0, 0, 13369376) //SCRCOPY
oImg:=GdiBmp():New()
oImg:hBmp:=Gdip_FromHBitmap(hBmp,, HasAlpha(hBmp))
oImg:Save("test.bmp")
SelectObject(hDc, hOldBmp)
DeleteDC(hDc)
DeleteObject(hOldBmp)
ReleaseDC(0, hDeskTop)

It works and I get a screenshot of a window to a bitmap file, but only in black and white. How can I get color bitmap ?
User avatar
cnavarro
Posts: 6572
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 4 times
Been thanked: 6 times

Re: Device context to file

Post by cnavarro »

Try with

Code: Select all | Expand



   SaveWindow( hWnd, cBmp, nWidth , nHeight )  // cBmp - .bmp, .png, ..

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Device context to file

Post by Natter »

Thank you, works perfectly ! Only I didn't find description of this function
User avatar
cnavarro
Posts: 6572
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 4 times
Been thanked: 6 times

Re: Device context to file

Post by cnavarro »

Look classes\tgdiplus.prg
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Post Reply