Insert device context

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

Insert device context

Post by Natter »

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 ?
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: Insert device context

Post by Antonio Linares »

Please explain what you are trying to do, thanks

What do you need that for ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Insert device context

Post by Natter »

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 :cry:
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: Insert device context

Post by Antonio Linares »

Could you post your source code here so we can test it and help you to make it work ? thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Insert device context

Post by Natter »

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
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: Insert device context

Post by Antonio Linares »

Try it this way:

ON PAINT FWRestScreen( hDC, oDc, 1, 1, 1000, 1000)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Insert device context

Post by Natter »

ON PAINT FWRestScreen( hDC, oDc, 1, 1, 1000, 1000)
This option also does not work
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: Insert device context

Post by Jimmy »

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

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

Re: Insert device context

Post by Natter »

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
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: Insert device context

Post by Antonio Linares »

Please remove the TRANSPARENT clause and try it again, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Insert device context

Post by Natter »

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 ?
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: Insert device context

Post by Jimmy »

hi,

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
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: Insert device context

Post by Antonio Linares »

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


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Insert device context

Post by nageswaragunupudi »

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

//----------------------------------------------------------------------------//
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: Insert device context

Post by Antonio Linares »

great example!

many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply