I've created an app to monitor a PC.
Basically it takes a screenshot of desktop window each 30 seconds and uploads it to an FTP server.
I've noted that after 467 iterations, it stops working.
I've tried on different machines with the same result.
Since I need capture the desktop window and not an HMG one, I've made very little modification to BT_BitmapCaptureClientArea() function to make it work with a handle instead an HMG window name.
I've created the simplest possible example to verify the problem... here it is:
Code: Select all
#include "hmg.ch"
*------------------------------------------------------------------------------*
Function Main()
*------------------------------------------------------------------------------*
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE '' ;
MAIN
define button test
row 10
col 10
caption 'test'
action test()
end button
END WINDOW
ACTIVATE WINDOW Win_1
Return
*-----------------------------------------------------------------------------------*
procedure test
*-----------------------------------------------------------------------------------*
local i, hDesktop, nDesktopWidth, nDesktopHeight
hDesktop := BT_SCR_GETDESKTOPHANDLE()
nDesktopWidth := GetDesktopWidth()
nDesktopHeight := GetDesktopHeight()
for i := 1 to 1000
xSaveWindowByHandle ( hDesktop , strzero(i,4) + '.' + 'jpg' , 0 , 0 , nDesktopWidth , nDesktopHeight )
next i
msginfo('fin')
return
*-----------------------------------------------------------------------------------*
FUNCTION xSaveWindowByHandle ( nHandle , cFileName , nRow , nCol , nWidth , nHeight )
*-----------------------------------------------------------------------------------*
LOCAL hBitmap
hBitmap := xBT_BitmapCaptureClientArea ( nHandle , nRow, nCol, nWidth, nHeight)
IF hBitmap <> 0
IF UPPER(RIGHT( cFileName , 4 ) ) == '.GIF'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_GIF )
ELSEIF UPPER(RIGHT( cFileName , 4 ) ) == '.JPG'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_JPG )
ELSEIF UPPER(RIGHT( cFileName , 4 ) ) == '.PNG'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_PNG )
ELSEIF UPPER(RIGHT( cFileName , 4 ) ) == '.BMP'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_BMP )
ENDIF
BT_BitmapRelease (hBitmap)
ENDIF
RETURN hBitmap
Function xBT_BitmapCaptureClientArea ( nHandle , Row, Col, Width, Height)
LOCAL New_hBitmap
LOCAL Max_Width := BT_ClientAreaWidth( nHandle )
LOCAL Max_Height := BT_ClientAreaHeight( nHandle )
bt_FillRectIsNIL (@Row, @Col, @Width, @Height, 0, 0, Max_Width, Max_Height)
bt_AdjustWidthHeightRect (Row, Col, @Width, @Height, Max_Width, Max_Height)
New_hBitmap := BT_BMP_CAPTURESCR ( nHandle , Col, Row, Width, Height, BT_BITMAP_CAPTURE_CLIENTAREA)
Return New_hBitmap