FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Unstable screenshot acquisition
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Unstable screenshot acquisition
Posted: Tue Apr 11, 2023 12:07 PM
Hi,

From time to time I save a screenshot to the clipboard.
Code (fw): Select all Collapse
  SendKey(VK_SNAPSHOT)
  syswait(0.1)

  OpenClipboard (getdesktopwindow())
  hBmp:= GetClpData(2) && CF_BITMAP
  CloseClipboard()
? hBmp
..............
DeleteObject(hBmp)
For some reason, it works unstable. If 1-2 times I get a working screenshot handle (hBmp), then the screenshot handle is 0. What could be the problem ?
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Unstable screenshot acquisition
Posted: Wed Apr 19, 2023 02:16 PM
When you double-click on this window, a screenshot is created. The problem is that this screenshot is normally created only on the current screen. If I choose any other screen, then the screenshot will be zero size. :(
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main
private oWnd, oFrg, oTm

  DEFINE WINDOW oWnd
  ACTIVATE WINDOW oWnd  ON INIT (ShowWindow(oWnd:hWnd,3), Frg_Sel())
return nil

procedure Frg_Sel  
local oCl

  if valtype(oFrg)!="O"
    DEFINE DIALOG oFrg FROM 0,0 TO 300,300  PIXEL ;
           STYLE nOR(WS_POPUP, WS_THICKFRAME) ;
           COLOR CLR_BLACK, RGB(152, 251, 152) RESIZABLE

    ACTIVATE DIALOG oFrg  ON INIT oFrg:nOpacity:=100 NOWAIT CENTER

    oFrg:Move(400, 600, 300, 300)

    SetWindowPos(oFrg:hWnd,-1,0,0,0,0,3)

    oFrg:bLDblClick:={||Frg_Cut()} 
    oFrg:bRClicked:={||oWnd:End()} 

    oFrg:Cargo:={0, 0, .F., {}} 

    oFrg:bLClicked := { | nRow, nCol | oFrg:Cargo[1]:= nRow, oFrg:Cargo[2]:= nCol, ;
                     oFrg:Cargo[3] := .T., oFrg:oCursor := cursorhand() }
    oFrg:bMMoved = { | nRow, nCol | iif( oFrg:Cargo[3], oFrg:Move( oFrg:nTop + ;
         nRow -  oFrg:Cargo[1], oFrg:nLeft + nCol -  oFrg:Cargo[2],,, .T. ),) }

    oFrg:bLButtonUp := { || oFrg:Cargo[3] := .F., oFrg:oCursor := nil }

  else
    oFrg:Show()
  endif

  Chk_Frg()
return

procedure Frg_Cut
local hBmp

  RELEASE TIMER oTm

  oFrg:Cargo[3] := .F.
  oFrg:oCursor := nil

  syswait(0.1)
  oFrg:Hide()

  SendKey(VK_SNAPSHOT)
  syswait(0.1)

  OpenClipboard (getdesktopwindow())
  hBmp:= GetClpData(2) // CF_BITMAP
  CloseClipboard()
? hBmp

  DeleteObject(hBmp)

  Frg_Sel()
return

procedure Chk_Frg //always in the foreground

  if valtype(oTm)!="O"
    oWnd:Hide()
    SetWindowPos(oFrg,-1,0,0,0,0,3)

    DEFINE TIMER oTm  OF oWnd  INTERVAL 1000  ACTION Chk_Frg()
    oTm:Activate()
  endif

  SetForeGroundWindow(oFrg)
return
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Unstable screenshot acquisition
Posted: Wed Apr 19, 2023 03:55 PM
https://forums.fivetechsupport.com/viewtopic.php?f=3&t=17946&p=94733&hilit=dibfrombitmap&sid=4145d4cab4353c133fcf645a3fabcfed&sid=475b5970acea408a72316edfff46f630#p94733

https://forums.fivetechsupport.com/viewtopic.php?f=6&t=17947&p=93824&hilit=dibfrombitmap&sid=4145d4cab4353c133fcf645a3fabcfed&sid=475b5970acea408a72316edfff46f630#p93824

https://forums.fivetechsupport.com/viewtopic.php?f=17&t=12423&p=62361&hilit=dibfrombitmap&sid=4145d4cab4353c133fcf645a3fabcfed&sid=475b5970acea408a72316edfff46f630#p62361

https://forums.fivetechsupport.com/viewtopic.php?f=6&t=7096&p=32369&hilit=dibfrombitmap&sid=4145d4cab4353c133fcf645a3fabcfed&sid=475b5970acea408a72316edfff46f630#p32369
Code (fw): Select all Collapse
// Capturar Tela desde FiveWin.

#include "Fivewin.ch"

FUNCTION Main()

   LOCAL oWnd, oBrush

   DEFINE BRUSH oBrush STYLE "NULL"

   SysWait( 0.3 )

   DEFINE WINDOW oWnd FROM 0, 0 TO GetSysMetrics( 1 ), GetSysMetrics( 0 ) ;
      PIXEL STYLE WS_POPUP BRUSH oBrush

   oWnd:Show()

   DibWrite( "SCREEN.BMP", DibFromBitmap( WndBitmap( oWnd:hWnd ) ) )

   // para ver lo capturado
   ShellExecute( GetActiveWindow(), NIL, cFilePath( GetModuleFileName( GetInstance() ) ) + "SCREEN.BMP", '', '', 5 )

RETURN NIL
// fin / end
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Unstable screenshot acquisition
Posted: Wed Apr 19, 2023 04:40 PM
Dear Natter,

Try with:
Code (fw): Select all Collapse
  FW_SENDKEY(VK_SNAPSHOT, 1 )
  syswait(0.5)
  FW_SENDKEY(VK_SNAPSHOT)
or
Code (fw): Select all Collapse
  FW_SENDKEY(VK_SNAPSHOT)
  syswait(0.5)
  FW_SENDKEY(VK_SNAPSHOT, 0 )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Unstable screenshot acquisition
Posted: Thu Apr 20, 2023 07:18 AM
Thank you, Antonio! Both options work fine. When changing the screen - the first time I always get a screenshot of zero size, but then everything is fine. :D

Continue the discussion