Insert device context
Insert device context
Hi,
I get the device context of someone else's application or browser window:
hDC:=GetWindowDc(FindWindow(...))
Then I need to put this device context on my window. How can I do this ?
I get the device context of someone else's application or browser window:
hDC:=GetWindowDc(FindWindow(...))
Then I need to put this device context on my window. How can I do this ?
- Antonio Linares
- Site Admin
- Posts: 42599
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 41 times
- Been thanked: 88 times
- Contact:
Re: Insert device context
Please explain what you are trying to do, thanks
What do you need that for ?
What do you need that for ?
Re: Insert device context
I have to make a universal grabber. I take the device context of any window, then I put this DC on the window of my application and cut out an arbitrary fragment. I wanted to do this using FW Save Screen() / FWRestScreen(), but it didn't work out 

- Antonio Linares
- Site Admin
- Posts: 42599
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 41 times
- Been thanked: 88 times
- Contact:
Re: Insert device context
Could you post your source code here so we can test it and help you to make it work ? thanks
Re: Insert device context
Sorry, Antonio, I can't give you the whole code, it's very big. I will try to explain
For example, I get a handle - hWn (via WMI) of a browser window and open the Lay_Dog(hWn) procedure to which I pass this handle. In this procedure, I want to replace the DC of the oLay window with the DC of the browser window. In this case, I can't do it
procedure Lay_Dlg(hWn)
private oLay
oDc:=FWSaveScreen(hWn, 1, 1, 1000, 1000)
DEFINE DIALOG oLay PIXEL STYLE nOR(WS_POPUP) TRANSPARENT
ACTIVATE DIALOG oLay ON INIT Lay_Ini() ;
ON PAINT FWRestScreen(oLay:hWnd, oDc, 1, 1, 1000, 1000)
return
procedure Lay_Ini
oLay:Move(1,1,1000,1000)
oLay:Center()
return
For example, I get a handle - hWn (via WMI) of a browser window and open the Lay_Dog(hWn) procedure to which I pass this handle. In this procedure, I want to replace the DC of the oLay window with the DC of the browser window. In this case, I can't do it
procedure Lay_Dlg(hWn)
private oLay
oDc:=FWSaveScreen(hWn, 1, 1, 1000, 1000)
DEFINE DIALOG oLay PIXEL STYLE nOR(WS_POPUP) TRANSPARENT
ACTIVATE DIALOG oLay ON INIT Lay_Ini() ;
ON PAINT FWRestScreen(oLay:hWnd, oDc, 1, 1, 1000, 1000)
return
procedure Lay_Ini
oLay:Move(1,1,1000,1000)
oLay:Center()
return
- Antonio Linares
- Site Admin
- Posts: 42599
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 41 times
- Been thanked: 88 times
- Contact:
Re: Insert device context
ON PAINT FWRestScreen( hDC, oDc, 1, 1, 1000, 1000)
This option also does not work
This option also does not work
Re: Insert device context
hi,
do you want to "save Screen" from "other" App and show it in "your" App
i don´t know if FiveWin save "other Screen" ... normal you just have Control of "your" App
---
i do get "Snapshot" of running Video
using FindWindow API you got a handle of Windows so you can get Pos / Size but IHMO not DC
so i do
and "import" Clipboard using harbour Bos Taurus Function BT_DrawDCtoDC() to get "Part" (Pos / Size) of "other" Video Player Windows
do you want to "save Screen" from "other" App and show it in "your" App

i don´t know if FiveWin save "other Screen" ... normal you just have Control of "your" App
---
i do get "Snapshot" of running Video
using FindWindow API you got a handle of Windows so you can get Pos / Size but IHMO not DC
so i do
Code: Select all | Expand
SENDKEY( VK_SNAPSHOT )
and "import" Clipboard using harbour Bos Taurus Function BT_DrawDCtoDC() to get "Part" (Pos / Size) of "other" Video Player Windows
greeting,
Jimmy
Jimmy
Re: Insert device context
Hi, Jimmy !
Interesting.. I just don't know how to transform Clipboard into DC (or bitmap).
I tried to do get an external window as a bitmap and make a BRUSH of my window. Also it does not work
Interesting.. I just don't know how to transform Clipboard into DC (or bitmap).
I tried to do get an external window as a bitmap and make a BRUSH of my window. Also it does not work
- Antonio Linares
- Site Admin
- Posts: 42599
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 41 times
- Been thanked: 88 times
- Contact:
Re: Insert device context
I deleted it. It doesn't help
I tried to get the window of another application as a bitmap.
hBmp:=WndBitmap(hWn)
Is it possible to save a bmp to a file as an image ?
I tried to get the window of another application as a bitmap.
hBmp:=WndBitmap(hWn)
Is it possible to save a bmp to a file as an image ?
Re: Insert device context
hi,
i "import" Clipboard and use harbour Bos Taurus Function BT_DrawDCtoDC() to get "Part" (Size) of "other" Windows
now i use Pos / Size to "extract" Window from Picture
hope it give you a Idee
i "import" Clipboard and use harbour Bos Taurus Function BT_DrawDCtoDC() to get "Part" (Size) of "other" Windows
Code: Select all | Expand
LOCAL hBitmap_aux
IF .NOT. ( BT_BitmapClipboardIsEmpty() )
hBitmap_aux := BT_BitmapClipboardGet( "Win1" )
IF hBitmap_aux <> 0
BT_BitmapClipboardClean( "Win1" )
BT_BitmapRelease( hBitmap )
hBitmap := hBitmap_aux
Image_Width := BT_BitmapWidth( hBitmap )
Image_Height := BT_BitmapHeight( hBitmap )
BT_ClientAreaInvalidateAll( "Win1" )
ENDIF
ENDIF
RETURN
now i use Pos / Size to "extract" Window from Picture
Code: Select all | Expand
// create DC and draw Bitmap with Desktop Size
hDC1 := BT_CreateDC (hBitmap1, BT_HDC_BITMAP, @BTstruct1)
Width1 := BT_DesktopWidth()
Height1 := BT_DesktopHeight()
BT_DrawBitmap (hDC1, 0,0, Width1, Height1, BT_COPY, hBitmap1)
// create empty Bitmap
hBitmap2 := BT_BitmapCreateNew (nPicWidth-10, nPicHeight, {255,0,0} )
hDC2 := BT_CreateDC (hBitmap2, BT_HDC_BITMAP, @BTstruct2)
// draw from DC1 to DC2 only within Pos / Size
BT_DrawDCtoDC (hDC2, 0, 0, nPicWidth-10, nPicHeight, BT_COPY ,;
hDC1,Row+nTitlebar+8, Col+10, Width-10, Height)
// now save Result
BT_BitmapSaveFile (hBitmap2, cFileName2, nTypePicture)
// clean up
BT_DeleteDC (BTstruct1)
BT_DeleteDC (BTstruct2)
BT_BitmapRelease (hBitmap1)
BT_BitmapRelease (hBitmap2)
Code: Select all | Expand
[code][/code]
hope it give you a Idee
greeting,
Jimmy
Jimmy
- Antonio Linares
- Site Admin
- Posts: 42599
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 41 times
- Been thanked: 88 times
- Contact:
Re: Insert device context
This example works perfectly fine:

Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local oDlg
DEFINE DIALOG oDlg
ACTIVATE DIALOG oDlg CENTER ;
ON PAINT FWRestScreen( hDC,;
FWSaveScreen( GetDesktopWindow(), 1, 1, 1000, 1000 ), 1, 1, 1000, 1000 )
return nil

- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Insert device context
Another sample, if useful to any:

Code: Select all | Expand
#include "fivewin.ch"
//----------------------------------------------------------------------------//
function Main()
local cWin := "FiveDBU" // or any other name
local hWnd
if !EmptY( hWnd := CaptureWnd( cWin ) )
XImage( hWnd, cWin + " : Capture" )
endif
return nil
//----------------------------------------------------------------------------//
function CaptureWnd( cWin )
local hWnd, hBmp, aRect
hWnd := FindWindow(, cWin )
if Empty( hWnd )
? "Window not found"
else
if IsIconic( hWnd )
ShowWindow( hWnd, 9 )
endif
SetForeGroundWindow( hWnd )
SysRefresh()
SysWait( 1 )
aRect := GetWndRect( hWnd )
hBmp := FWSaveScreen( GetDC( 0 ), aRect[ 1 ]+3, aRect[ 2 ]+8, aRect[ 3 ]-8, aRect[ 4 ]-8 )
endif
return hBmp
//----------------------------------------------------------------------------//

Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Antonio Linares
- Site Admin
- Posts: 42599
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 41 times
- Been thanked: 88 times
- Contact: