FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Device context to file
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Device context to file
Posted: Mon Apr 04, 2016 02:50 PM

Hi all !

How to save device context of a window in bmp-file ?

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Device context to file
Posted: Tue Apr 05, 2016 01: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 ?

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Device context to file
Posted: Tue Apr 05, 2016 01:36 PM
Try with

Code (fw): Select all Collapse
   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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Device context to file
Posted: Tue Apr 05, 2016 02:18 PM

Thank you, works perfectly ! Only I didn't find description of this function

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Device context to file
Posted: Tue Apr 05, 2016 02: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

Continue the discussion