Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Cropping 3

Status
Not open for further replies.

TariqMehmod

Programmer
Mar 4, 2004
100
PK
ear Experts

I have following excel file

aaa_luwzwu.png


I want to create an image based on usedcells (B3:J22)
Is it possible to crop required range then create an image.

I think GDIPLUS can do this, so I found these links but still confuse how to do this.


The codes in this link crop whole screen but not required area

Please help
 
Hmmm

Hides, but is it still running? You would be best to check taskmgr

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
You are right sir, but there is no way to release this still.

 
Did you try the code I posted in my post date-stamped 10 Nov 20 16:08? I think that would work. (I ran it myself without the actual screen capture, and the form was released after the timer had fired.)

Just making the form invisible is not a good solution, because your program will remain in memory indefinitely. If the user runs it multiple times, you will have multiple copies of the program, eventually draining memory. Worse, if the timer is still active, it will continue to fire, even though the form is invisible.

You are so close to a solution. Don't give up now.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sir Mike Lewis, I refer to your post 10 Nov 20 16:08. Post 57

I have modified your following line of code

Code:
img.Capture(THISFORM.HWND)
img.Capture(thisform.HWND)

with
Code:
img.Capture(THISFORM.HWND)
img.Capture(oForm.HWND)

I am pleased that your codes work fine.
Now form is released after timer fires.

Here are complete codes


Code:
 * getting desktop path
loShell = Createobject ('WScript.Shell')
lcDesktop = loShell.SpecialFolders('desktop')

lcXLS =CURDIR()+[Daily.xlsx]
If Empty(lcXLS)
	Return
Endif

LOCAL oForm
    oForm = CREATEOBJECT("Form")

    WITH oForm

        .HEIGHT = 550
        .WIDTH = 360
        .AUTOCENTER=.T.
        .CAPTION=[Dashboard]
        .MINBUTTON=.F.
        .MAXBUTTON=.F.
        .ALWAYSONTOP=.T.

        .NEWOBJECT("ExcelObject","oleExcelObject")  && Add OLE object
        WITH .ExcelObject
            .LEFT = 5
            .TOP = 5
            .WIDTH = .PARENT.WIDTH - 10
            .HEIGHT = .PARENT.HEIGHT - 10
            .VISIBLE = .T.
        ENDWITH

        .NEWOBJECT("Timer1","oTimer")  		
ENDWITH

    oForm.SHOW(1)  && form is modal, so no need for READ EVENTS


DEFINE CLASS oleExcelObject AS OLECONTROL
    OLECLASS ="Excel.Sheet"  && Server name
    OLETYPEALLOWED = 0      && Linked
    DOCUMENTFILE = lcXLS && This file should exist
ENDDEFINE

DEFINE CLASS oTimer AS TIMER							
    INTERVAL=5000

    PROCEDURE TIMER
    THIS.ENABLED = .F.
    DO ScreenShot WITH this.Parent
	this.enabled = .T.
ENDDEFINE

PROCEDURE ScreenShot
LPARAMETERS oForm

#INCLUDE gpImage.h

IF NOT "gpImage" $ SET("Procedure")
    SET PROCEDURE TO gpImage ADDITIVE
ENDIF

GDIP = CREATEOBJECT("gpInit")
img = CREATEOBJECT("gpImage")
*img.Capture(THISFORM.HWND)
img.Capture(oForm.HWND)
LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)
img.Crop(lnLeftBorder, lnTitleHeight + lnTopBorder, ;
img.ImageWidth - (lnLeftBorder * 2), ;
img.ImageHeight - (lnTitleHeight + (lnTopBorder * 2)))
img.SaveasBMP(lcDesktop+'\'+"Dash")
img = NULL
oForm.Release

ENDFUNC


Now the last Issue:

This prg works fine as standalone.
But I want to call this with top level form (showwindow=2).
this prg does not run on that form.

For this I has started a new thread

Link



Thanks again and best regards
 
Phew indeed.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Dear Sir's

My Bad Luck

Here is another issue raised.

When I run above codes FIRST TIME then an image is created on desktop, no issue no error message.
But when I run codes SECOND TIME then this error message appears

bbb_yc6xs3.png


When I use this command within VFP

Code:
 * erase dash file first from desktop
myxfile=(lcDesktop+'\'+"Dash.bmp")
Erase (myxfile)


Then this message appears
aaa_ixquwp.png



and

when I try to manually try to delete this file from desktop then also same error message

The file is deleted after closing VFP.

I think file is being used in memory somewhere.

Now FORM is release but this image file does not release.

Please help
 
The file it is objecting to is Dash.bmp. This is the file that you are creating from the screen shot. When you run the form a second time, it is trying to overwrite the first instance of the file, which for some reason it cannot do.

Is there anything special about the name, Dash.bmp? Could you do something to make the name unique, for example, to append the date and time to it, so that the name would be something like DASH-2020-11-12-08-30? Alternatively, you could prompt the user for a filename; if you use PUTFILE() for that, it will warn the user if they try to overwrite the file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sir if create files as datastamp like DASH-2020-11-12-08-30? then there will be new file every time when use run codes.

so there will be huge file on desktop and as a result use must delete files mannully.

Regards
 
Seems to me that your vfp executable is still running with the file open.

Use taskmgr to check.

Either that or whatsapp has it open

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Actually, you can see that the file is still open in VFP from your screenshot.

This means VFP MUST still be running, a closed program cannot hold a file open.



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Tariq, it looks as if you are running this program from the development environment. I understood that you were planning to run it as a stand-alone executable. Have you tried doing that? If you do, you might find that the problem goes away.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top