Insert device context

Insert device context

Postby Natter » Mon Jan 31, 2022 6:28 am

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

Re: Insert device context

Postby Antonio Linares » Mon Jan 31, 2022 7:36 am

Please explain what you are trying to do, thanks

What do you need that for ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41397
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Insert device context

Postby Natter » Mon Jan 31, 2022 7:52 am

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

Re: Insert device context

Postby Antonio Linares » Mon Jan 31, 2022 11:03 am

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
User avatar
Antonio Linares
Site Admin
 
Posts: 41397
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Insert device context

Postby Natter » Mon Jan 31, 2022 11:47 am

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

Re: Insert device context

Postby Antonio Linares » Mon Jan 31, 2022 1:55 pm

Try it this way:

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41397
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Insert device context

Postby Natter » Tue Feb 01, 2022 11:10 am

ON PAINT FWRestScreen( hDC, oDc, 1, 1, 1000, 1000)
This option also does not work
Natter
 
Posts: 1133
Joined: Mon May 14, 2007 9:49 am

Re: Insert device context

Postby Jimmy » Tue Feb 01, 2022 1:28 pm

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 view
  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
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Insert device context

Postby Natter » Tue Feb 01, 2022 2:52 pm

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

Re: Insert device context

Postby Antonio Linares » Tue Feb 01, 2022 4:23 pm

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41397
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Insert device context

Postby Natter » Tue Feb 01, 2022 5:04 pm

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

Re: Insert device context

Postby Jimmy » Tue Feb 01, 2022 7:17 pm

hi,

i "import" Clipboard and use harbour Bos Taurus Function BT_DrawDCtoDC() to get "Part" (Size) of "other" Windows

Code: Select all  Expand view
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 view
   // 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 view
[code][/code]


hope it give you a Idee
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Insert device context

Postby Antonio Linares » Wed Feb 02, 2022 9:06 am

This example works perfectly fine:

Code: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 41397
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Insert device context

Postby nageswaragunupudi » Wed Feb 02, 2022 3:21 pm

Another sample, if useful to any:
Code: Select all  Expand view
#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
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Insert device context

Postby Antonio Linares » Thu Feb 03, 2022 10:38 am

great example!

many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41397
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Antonio Linares and 25 guests