Device context to file

Device context to file

Postby Natter » Mon Apr 04, 2016 2:50 pm

Hi all !

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

Re: Device context to file

Postby Natter » Tue Apr 05, 2016 1:33 pm

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 ?
Natter
 
Posts: 1211
Joined: Mon May 14, 2007 9:49 am

Re: Device context to file

Postby cnavarro » Tue Apr 05, 2016 1:36 pm

Try with

Code: Select all  Expand view


   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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Device context to file

Postby Natter » Tue Apr 05, 2016 2:18 pm

Thank you, works perfectly ! Only I didn't find description of this function
Natter
 
Posts: 1211
Joined: Mon May 14, 2007 9:49 am

Re: Device context to file

Postby cnavarro » Tue Apr 05, 2016 2:21 pm

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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 69 guests