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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delay Closing of Word (Print Screen) 1

Status
Not open for further replies.

lashwarj

IS-IT--Management
Nov 1, 2000
1,067
US
I have a dll that does a print screen using the cut copy paste into word. It then automates a close on word, but if its printing to a slow printer it gives the "Word is currently printing do you wish to close" crap, ha ha ha. Is there a way to delay the word.release command.


DEFINE CLASS p_screen AS CUSTOM OLEPUBLIC
Name = "p_screen"
ScreenPrinted = .F.
oWordObj = ""
PROCEDURE ScreenCapture
This.ReleaseWord()
This.ScreenPrinted = .T.
DECLARE INTEGER keybd_event IN Win32API ;
INTEGER, INTEGER, INTEGER, INTEGER
VK_SNAPSHOT = 44
=keybd_event(VK_SNAPSHOT, 1, 0, 0)
This.oWordObj=CREATEOBJECT("Word.Application")
This.oWordObj.Documents.Add
This.oWordObj.ActiveDocument.PageSetup.Orientation = 1
WITH This.oWordObj.WordBasic
.EditPaste
.FilePrint
.FileClose(2)
ENDWITH
RELEASE keybd_event, vk_snapshot
ENDPROC
PROCEDURE ReleaseWord
IF This.ScreenPrinted
This.oWordObj.Quit
This.oWordObj = ""
This.ScreenPrinted = .F.
ENDIF
ENDPROC
PROCEDURE Destroy
This.ReleaseWord()
ENDPROC
ENDDEFINE
 
I hope this works :)

DEFINE CLASS p_screen AS CUSTOM OLEPUBLIC
Name = "p_screen"
ScreenPrinted = .F.
oWordObj = ""
hWord = 0

PROCEDURE ScreenCapture
This.ReleaseWord()
This.ScreenPrinted = .T.
DECLARE INTEGER keybd_event IN Win32API ;
INTEGER, INTEGER, INTEGER, INTEGER
VK_SNAPSHOT = 44
=keybd_event(VK_SNAPSHOT, 1, 0, 0)
This.oWordObj=CREATEOBJECT("Word.Application")

Do while (This.hWord == 0)
This.hWord = FindWindow('OpusApp', Null)
&& Don't change the case of "OpusApp"
&& type in exactly like it
enddo

This.oWordObj.Documents.Add
This.oWordObj.ActiveDocument.PageSetup.Orientation = 1
WITH This.oWordObj.WordBasic
.EditPaste
.FilePrint
.FileClose(2)
ENDWITH
* RELEASE keybd_event, vk_snapshot
RELEASE vk_snapshot
CLEAR DLLS keybd_event
&& use this to release DLL (VFP7 or later)
&& for VFP6 and earlier use CLEAR DLLS.
ENDPROC

Procedure Init
Declare Long FindWindow in User32 String, String
Endproc

PROCEDURE ReleaseWord
IF This.ScreenPrinted
This.oWordObj.Quit
This.oWordObj = ""
This.hWord = 0
This.ScreenPrinted = .F.
ENDIF
ENDPROC
PROCEDURE Destroy
Do while (FindWindow('OpusApp', Null) == This.hWord)
= inkey(0.1)
enddo
This.ReleaseWord()
CLEAR DLLS
ENDPROC
ENDDEFINE


-- AirCon --
 
Nope still gives me the word is currently printing. In my call for the dll i have a command button with this code

oPScreen = CREATEOBJECT("olepscrn.p_screen")
oPScreen.ScreenCapture()
RELEASE oPScreen


But that only releases the dll correct.
 
Ahh...sorry. I missed the whole point

You can trap the printing message with this.

PROCEDURE ReleaseWord
IF This.ScreenPrinted
Do while (This.oWordObj.BackgroundPrintingStatus == 1)
= inkey(0.1)
enddo
This.oWordObj.Quit
This.oWordObj = ""
This.ScreenPrinted = .F.
ENDIF
ENDPROC


But that only releases the dll correct

RELEASE command will release any type of variables from memory, including object type variables.
In your case, yes, it releases VFP DLL. However for object type, there are some occation RELEASE only release the variable but not the object itself (the pointer still alive). Then you will get a memory leak. To make sure VFP clean up the whole things, assign it to NULL first then release it.

MyObject = NULL
Release MyObject


-- AirCon --
 
That still leaves winword.exe running in the backround though. Also, is there a way to open the printer choser
 
Should there be a =.T. in the IF This.ScreenPrinted
 
It should be no problem. I'm not sure what is happening but try to change Destroy procedure to Unload Procedure

Let me know how it works

-- AirCon --
 
Ahh.. I think I know (maybe :) )

oPScreen = CREATEOBJECT("olepscrn.p_screen")
oPScreen.ScreenCapture()
RELEASE oPScreen

When the object process the Destroy event, all other event already destroyed. So either change the Destroy to Release event, or you can do this

oPScreen = CREATEOBJECT("olepscrn.p_screen")
oPScreen.ScreenCapture()
oPScreen.ReleaseWord()
RELEASE oPScreen

Hope it works

-- AirCon --
 
Perfect, BINGO, nailed it, SWEET !!!!!!!!!!!!!!!
 
just one last thing, is there a way to show the printer select
 
Try this:

oWordObj.Dialogs(88).Show()

-- AirCon --
 
Sorry :)

Change this code:
WITH This.oWordObj.WordBasic
.EditPaste
.FilePrint
.FileClose(2)
ENDWITH

Into this:
WITH This.oWordObj
.WordBasic.EditPaste
.Visible = .T.
.Dialogs(88).Show()
.WordBasic.FileClose(2)
ENDWITH



-- AirCon --
 
ahhhhhh i see, you cant have the best of both worlds though huh, hide the main window and recieve just the printer dialog
 
Well.. you can, but VFP screen won't be refresh (locked) until the print dialog is close. Try this:


WITH This.oWordObj
.WindowState = 2
.WordBasic.EditPaste

This.oFinder = CreateObject('MyFinder')
This.oFinder.cTitle = 'Print'
This.oFinder.Enabled = .T.

.Dialogs(88).Show()
.WordBasic.FileClose(2)
.Visible = .F.
.WindowState = 1
ENDWITH


Define Class MyFinder as Timer
Interval = 20
Enabled = .F.
cTitle = ''

Procedure Init
Declare Long FindWindow in User32 String, String
Declare BringWindowToTop in User32 Long nhWnd
EndProc

Procedure Timer
Local lnhWnd
lnhWnd = FindWindow(Null, This.cTitle)
If (lnhWnd != 0)
This.Enabled = .F.
BringWindowToTop(lnhWnd)
endif
EndProc

Procedure Destroy
Clear Dlls FindWindow, BringWindowToTop
EndProc
EndDefine


-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top