Unstable screenshot acquisition

Unstable screenshot acquisition

Postby Natter » Tue Apr 11, 2023 12:07 pm

Hi,

From time to time I save a screenshot to the clipboard.
Code: Select all  Expand view
 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 ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Unstable screenshot acquisition

Postby Natter » Wed Apr 19, 2023 2: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: Select all  Expand view
#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

 
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Unstable screenshot acquisition

Postby karinha » Wed Apr 19, 2023 3: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: Select all  Expand view

// 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
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Unstable screenshot acquisition

Postby Antonio Linares » Wed Apr 19, 2023 4:40 pm

Dear Natter,

Try with:
Code: Select all  Expand view
 FW_SENDKEY(VK_SNAPSHOT, 1 )
  syswait(0.5)
  FW_SENDKEY(VK_SNAPSHOT)


or

Code: Select all  Expand view
 FW_SENDKEY(VK_SNAPSHOT)
  syswait(0.5)
  FW_SENDKEY(VK_SNAPSHOT, 0 )
regards, saludos

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

Re: Unstable screenshot acquisition

Postby Natter » Thu Apr 20, 2023 7: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
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 47 guests