Hi guys,
I was tasked to write code based on the following pseudocode. I have no idea where to start
i. Run external exe that will display numbers // this part is straight forward
ii. Once it displayed, pop a dialog box at the edge of the external exe's window // 2 issues. Determining when the external exe appear and positioning my dialog box
iii. If user click Ok on the dialog, create a screenshot and email it // what's the code to do screenshot
TIA
How to capture screen by code
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: How to capture screen by code
For the screenshot this could work. Part of a error log/send function
In the main section :
SetPostErrorAction( { |cErrorLogFileName, oError| MyErrorAction( cErrorLogFileName, oError ) } )
In the main section :
SetPostErrorAction( { |cErrorLogFileName, oError| MyErrorAction( cErrorLogFileName, oError ) } )
Code: Select all | Expand
function MyErrorAction( cErrorLogFileName, oError )
LOCAL cErrScreen:=""
LOCAL cFile := "screen.bmp", cErrScreen:=""
local hBmp := WndBitmap( GetDesktopWindow() )
local hDib := DibFromBitmap( hBmp )
local cErrtext := memoread("error.log")
local nKwaliteit := 72
DibWrite( cFile, hDib )
GloBalFree( hDib )
DeleteObject( hBmp )
// Second option ?
oImage := GdiBmp():New( "screen.bmp" )
oImage:Resize( 600 )
oImage:Save( "small.bmp", 72 )
oImage:End()
msginfo(cErrorLogFileName)
cErrScreen = memoread( "small.bmp" )
xbrowser(oCn)
FWCONNECT oCn HOST cServer USER cUser PASSWORD cPassword DATABASE cDatabase
if oCn == nil
? "Failed to connect"
return nil
endif
oCn:Insert( "errors", "datum,uur,user,error,errorlog", { date(),time(), setup_naam, oError:dEscription,cErrText } )
msginfo("Er is een fout opgetreden in het programma. Gelieve het programma opnieuw te starten")
return NIL
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour
Re: How to capture screen by code
You can try this (by timer)
Code: Select all | Expand
procedore Finf_File()
local st, fl
local oList, oProc
private dim:={{upper(MyExe), "TWINDOW", {}}}
EnumChildWindows( 0, ;
{ | hWn, nLParam | L_Tsk(hWn, "window title" }, 0 ) // optional supplied value
oList:= oWmi:ExecQuery( "select * from Win32_Process where Name = '" + dim[1,1] + "'")
for each oProc in oList // List of similar processes
fl:=ascan(dim[1,3], {|xx|xx[1]=oProc:ProcessId})
if fl>0 //found your exe file
*** you code ***
endif
next
return
Function L_Tsk(hWn, ttl) && CALLBACK EnumChildWindows
local fl
** hWn - handle window
** ttll - window title
DEFAULT ttl:=""
fl:=ascan(dim, {|xx|upper(xx[2])=upper(GetClassName(hWn))}) // process name
if fl>0.and.IsWindowVisible(hWn).and.ttl==GetWindowText(hWn)
aadd(dim[fl,3], {GetWindowProcessID(hCt), hWn})
endif
return .T.
** It would be useful to keep this function in the library **
FUNCTION WMIService() && It would be useful to keep this function in the library
local oLocator
if oWMI == nil
oLocator := CREATEOBJECT( "wbemScripting.SwbemLocator" )
oWMI := oLocator:ConnectServer()
endif
return oWMI
***********************************
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
HB_FUNC( GETWINDOWPROCESSID ) // hWnd --> nProcessId
{
DWORD dwProcessId;
GetWindowThreadProcessId( ( HWND ) hb_parnl( 1 ), &dwProcessId );
hb_retnl( dwProcessId );
}
#pragma ENDDUMP
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: How to capture screen by code
I check if my program is already running : (Maybe put this in a loop and background process)
Code: Select all | Expand
IF IsExeRunning( cFileName( HB_ARGV( 0 ) ) )
msginfo("Program is running")
QUIT
ENDIF
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour