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!

Preview Report IN WINDOW nightmare 2

Status
Not open for further replies.

csr

Programmer
Jul 20, 2000
507
I wish to preview my reports in a window placed on the desktop. So, this is what I thought would do that.
Well, it almost works.

Without going through all my problems with this, does anyone see anything wrong with this function I have created ?


FUNCTION previewReport(cReportName)
LOCAL nPreviewScreenWidth, nPreviewScreenHeight
nPreviewScreenWidth = 130
nPreviewScreenHeight = 50
DEFINE WINDOW wPreview FROM 1,1 TO nPreviewScreenHeight,nPreviewScreenWidth IN DESKTOP
ACTIVATE WINDOW wPreview
REPORT FORM (cReportName) NOCONSOLE PREVIEW IN WINDOW wPreview
RELEASE WINDOWS wPreview
RETURN .t.


Don


 
Well, I am getting no takers on this as it is so ...

Let me begin relating some of the problems ... and see if that sparks some responses.

If I use WINDOW instead of IN WINDOW in my report command I get a large black window with my report placed within it (off to the side a little) with no way to move anything. So that, clearly, is not what I want.

So I am using IN WINDOW.

However, the next obstacle is that the report toolbar is nowhere to be found so I cannot move to various pages.

Also, the report is too far to the right but I cannot "grab" it with the mouse and move it.


Don


 
Well, I am starting to make some progress now ...

It seems that it is a matter of defining the wPreview large enough to contain the report window. Also, if I resize the report window within wPreview, the next time I run the report it comes up at that size. So, that is a plus.

Now, if I could only find a way to get the report toolbar to show up.



Don


 
This doesn't really solve all of your problem, but it is more information for you:

The Print Preview Toolbar is just not in your window.

Using the following code (substituting your variables etc.) gives a functional toolbar.

DEFINE WINDOW wPreview AT 10,10 SIZE 20,40 IN DESKTOP FLOAT
ACTIVATE WINDOW WPREVIEW
REPORT FORM XX TO PRINT PROMPT PREVIEW IN WINDOW wPreview

RELEASE WINDOW WPREVIEW

 
Hi

FUNCTION previewReport
PARAMETERS rptFile

oRepForm = CREATEOBJECT("FORM")
WITH oRepForm
.Caption = "Report Window"
.WindowState = 2
** set properties as you want for DeskTop/TopLevel
.Show()
ENDWITH
REPORT FORM (rptFile) PREVIEW WINDOW (oRepForm.Name) ;
TO PRINTER PROMPT
oRepForm.Release()
RELEASE oRepForm
RETURN .t.

:)

ramani :)
(Subramanian.G)
 
csr,

You may need to make sure that the resource file (foxuser.dbf for instance) that you are including with your application actually has saved a setting to show the preview toolbar. One way to do this is...delete all foxuser.dbf's from your development system and then start VFP (it will recreate the foxuser.dbf), then while in VFP bring up a preview and make sure that the preview toolbar is up and where you want it. Then Set resource off and go find that Foxuser.dbf (that's why we deleted all of them to make finding the right one easier for you). Copy the foxuser files and then open them up and set the appropriate row in it to Readonly - you'll be able to tell which row since it will contain some information regarding the preview toolbar. Then include this resource file with your application. Now, there is another way which involves marking the foxuser file with ReadOnly attribute, but then none of the settings will be saved as your user resizes stuff etc. The reason you need to mark the preview toolbar entry as readonly or the whole file as readonly is because if your user were to close the toolbar while previewing that setting gets saved and the next time they preview a report you have a problem - no toolbar. Sorry for such a long drawnout explanation, couldn't figure out a way to say it in less words.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Ramani ...

I used your concept and it worked pretty well.

I had to create a class from which to build my oRepForm because I need the form to be a desktop form and that property is readonly. So that was fine.

However, I am not sure what the TO PRINTER PROMPT is supposed to do ... it did nothing for me. I think the PREVIEW keyword supercedes that. I do not need that anyway.

The toolbar is still now showing up.

I read through the idea from SLIGHTHAZE and I could do that but I would rather not. Any other suggestions ?



Don


 
TO PRINTER PROMPT will make sure that the user is given the printer dialog box should they click the print button on the print preview screen, that way they can change printers or select the pages to print, etc.

As to the toolbar not showing up, since it is the resource file that is causing the problem I think you are going to be hard pressed to find another solution to your problem. You could I guess create your own preview toolbar with all the functionality that is in the system one and bring that up through code, but seems like alot more work. Is there a reason why you would rather not do the solution as I outlined above?

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
I am beginning to think the TOOLBAR problem is insolvable because my _SCREEN is sized to about one-fourth the normal size and I am using it as the front end (with a menu) to my application.

Nothing is displayed inside the SCREEN. All of my forms are desktop forms and modal.

When I create the oRepForm, it goes over the top of the _SCREEN and hides everything from view. The report goes inside the oRepForm and there is no Print Preview toolbar anywhere to be seen.



Don


 
csr,

Maybe this would help?

Have a Top-Level preview report with a Top-Level application
faq184-2490

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Hi

Make test with this one, if it helps.
**********************************************
PUBLIC oform1
SET STEP ON
oform1=NEWOBJECT("gsreport")
RETURN
**********************************************
DEFINE CLASS gsreport AS form

ShowWindow = 2
DoCreate = .T.
Caption = "gsReport"
WindowState = 2
Name = "gsreport"
creport = ""

PROCEDURE Init
PARAMETERS pReport

IF EMPTY(pReport)
pReport=GETFILE("FRX")
ENDIF
ThisForm.cReport = pReport
IF ! EMPTY(ThisForm.cReport)
_screen.Visible = .f.
This.Visible = .t.
WITH This
.AddProperty('oPreViewBar', .NULL.)
.oPreviewBar = ;
CREATEOBJECT('gsPreViewToolBar',This)
.oPreViewBar.SHOW
.oPreViewBar.Dock(0)
.Refresh()
ENDWITH
wName = ThisForm.Name
REPORT FORM (ThisForm.cReport) ;
PREVIEW IN WINDOW &wName TO PRINTER PROMPT
_screen.Visible = .T.
ENDIF
RETURN .f.
ENDPROC
ENDDEFINE
*
*-- EndDefine: gsreport
**************************************************
*-- Class: gsPreviewToolBar
*-- ParentClass: ToolBar
*-- BaseClass: ToolBar
*
DEFINE CLASS gsPreViewToolBar AS Toolbar

Caption = "Preview"
ShowWindow = 1

ADD OBJECT btnExit AS CommandButton
ADD OBJECT sepExit AS Separator

ADD OBJECT btnDev AS CommandButton
ADD OBJECT sepDev AS Separator

ADD OBJECT sepNav1 AS Separator
ADD OBJECT btnZoom AS CommandButton
ADD OBJECT btnHome AS CommandButton
ADD OBJECT btnPrev AS CommandButton
ADD OBJECT btnGoTo AS CommandButton
ADD OBJECT btnNext AS CommandButton
ADD OBJECT btnEnd AS CommandButton
ADD OBJECT sepNav2 AS Separator

btnExit.Caption = "Exit"
btnExit.ToolTipText = "Close this Report"
btnExit.Width = 50

btnDev.Caption = "Select Printer"
btnDev.ToolTipText = "Select Printer to direct Output"
btnDev.Width = 100

btnZoom.Caption = ""
btnZoom.Picture = "Zoom.BMP"
btnZoom.ToolTipText = "Step Zoom"
btnZoom.Width = 24

btnHome.Caption = ""
btnHome.Picture = "Top.bmp"
btnHome.ToolTipText = "First Page"
btnHome.Width = 24

btnPrev.Caption = ""
btnPrev.Picture = "previous.bmp"
btnPrev.ToolTipText = "Previous Page"
btnPrev.Width = 24

btnGoTo.Caption = ""
btnGoTo.Picture = "Search.bmp"
btnGoTo.ToolTipText = "Go to Page"
btnGoTo.Width = 24

btnNext.Caption = ""
btnNext.Picture = "next.Bmp"
btnNext.ToolTipText = "Next Page"
btnNext.Width = 24

btnEnd.Caption = ""
btnEnd.Picture = "bottom.bmp"
btnEnd.ToolTipText = "Last Page"
btnEnd.Width = 24


PROCEDURE Init
PARAMETERS pForm
This.AddProperty('oForm', .NULL.)
IF PARAMETERS() > 0
This.OForm = pForm
ENDIF
This.SetAll("Height",22,"CommandButton")
ENDPROC

PROCEDURE btnExit.Click
KEYBOARD '{ESC}'
ENDPROC

PROCEDURE btnDev.Click
SYS(1037)
ENDPROC

PROCEDURE btnZoom.Click
KEYBOARD "{L}"
ENDPROC

PROCEDURE btnGoTo.Click
KEYBOARD "{G}"
ENDPROC

PROCEDURE btnHome.Click
KEYBOARD "{Home}"
ENDPROC

PROCEDURE btnPrev.Click
KEYBOARD '{PGUP}'
ENDPROC

PROCEDURE btnNext.Click
KEYBOARD "{PGDN}"
ENDPROC

PROCEDURE btnEnd.Click
KEYBOARD "{END}"
ENDPROC

ENDDEFINE
**************************************************
** EOF
**************************************************


ramani :)
(Subramanian.G)
 
Slighthaze:

My reason (silly I guess) for not wishing to do as your solution suggested is 2-fold.

First - I have doubts that it will result in the toolbar showing up on top of the form I have created because my _SCREEN is not full sized.

Second - (this is the silly part) When I distribute an application I do not wish to distribute anything except the EXE. Nothing else.

However, In writing this answer it has just come to me that I suppose I could include a template file within my EXE and use that to make a copy of the foxuser.dbf file on the users computer. That would also provide me with a mechanism for getting the foxuser.dbf file back to the original value. Does that seem like it could be done ?




Don


 
Ramani:

Thank you very much for your extravagent code example.

I will be storing that away for later examination and possible use. Right now, however, it seems like too much code for this situation.

I think it will be a good learning tool for me. Thanks.



Don


 
ramani,

Nicely done! /art/star.gif for you.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
csr,

When you define the window in desktop, it doesn't belong to the VFP screen anymore. so the Preview window will be covered by your window

To show it, you must set the window parent into your define window.

You can try this if you want. To use this code you must download the file from UT
Then search using ID: 14876

Or you can use FoxTools function to replace FindWTitle but it's a little more complicated


---------------
FUNCTION previewReport(tcReportName)
LOCAL nPreviewScreenWidth, nPreviewScreenHeight
Local loPreview

nPreviewScreenWidth = 130
nPreviewScreenHeight = 50
DEFINE WINDOW wPreview FROM 1,1 TO ;
nPreviewScreenHeight,nPreviewScreenWidth ;
IN DESKTOP
ACTIVATE WINDOW wPreview

loPreview = CreateObject('SetPreviewWindow')
loPreview.cTitle = tcReportName
loPreview.cTitle2 = 'Print Preview'
loPreview.Enabled = .T.
REPORT FORM (tcReportName) NOCONSOLE PREVIEW in WINDOW wPreview
RELEASE WINDOWS wPreview

loPreview = Null
RETURN .t.
EndFunc


Define Class SetPreviewWindow as Timer
#Define c0 chr(0)

Interval = 20
Enabled = .F.
cTitle = ''
cTitle2 = ''
hWnd1 = 0
hWnd2 = 0

Procedure Init
Declare Long FindWTitle in HTWindow ;
String @cTitle, Integer nCase, Long bShow

Declare Long SetParent in User32 ;
Long hWndChild, Long hWndNewParent
EndProc

Procedure Timer
Local lcTitle
lcTitle = This.cTitle + replicate(c0, 80)
If (This.hWnd1 == 0)
This.hWnd1 = FindWTitle(lcTitle, 0, .F.)
endif

If (This.hWnd1 != 0)
If (This.hWnd2 == 0)
lcTitle = This.cTitle2 + replicate(c0, 80)
This.hWnd2 = FindWTitle(lcTitle, 0, .F.)
endif

If (This.hWnd2 != 0)
SetParent(This.hWnd2, This.hWnd1)
This.Enabled = .F.
endif
endif
EndProc

Procedure Destroy
Clear Dlls FindWTitle, SetParent
EndProc
EndDefine
----------


-- AirCon --
 
AirCon:

Thanks for your reply.

This statement sounds like it addresses my problem directly. >>To show it, you must set the window parent into your define window<<

If possible, could you expand a little on what that means ?



Don


 
csr,

Maybe I wasn't make myself clear. What I mean is:

The Preview window still belongs to VFP Main window. VFP is the parent of the Preview window.

Now when you define the window in Desktop, the window doesn't belong to VFP Main Window (VFP is no longer the parent). The Desktop window will be treated by VFP as the TOPMOST window.

When the report form is displaying in your define Desktop Window, the Preview window is shown in VFP Main Window.
While your report is displaying, VFP will wait until Desktop window is close. As the result, the preview window will never be shown or as I mentioned it is covered up by your Desktop Window.

To make the Preview window appear in your Desktop Window, you must set your desktop window as the parent of Preview Window. Or make the window of the report as the parent instead.

As from the example code I gave earlier:

Declare Long SetParent in User32 ;
Long hWndChild, Long hWndNewParent
SetParent(This.hWnd2, This.hWnd1)

Where:
This.hWnd2: is the handle to Preview window
This.hWnd1: is the handle to Report Window
By calling SetParent API, we set the Report Window as the Parent of Preview Window.

I don't know how to explain this in simpler words, but I hope this one is clear enough for you.

-- AirCon --
 
I forgot to mention this:

Preview Window is the same with Report Preview Toolbar
Report Window is the window where the report is displayed

Regards

-- AirCon --
 
AirCon:

Well, this is where I am right now ...

FUNCTION previewReport(cReportName)
oRepForm = CREATEOBJECT(&quot;ReportWindow&quot;)
WITH oRepForm
.name = &quot;ReportWindow&quot;
.WindowState = 2
.Show()
ENDWITH
REPORT FORM (cReportName) NOCONSOLE PREVIEW IN WINDOW ReportWindow TO PRINTER prompt
oRepForm.release()
IF yesNo(&quot;Print Report&quot;)
GO top
REPORT FORM (cReportName) TO PRINTER PROMPT noconsole
endif
RETURN .t.

I have reached a point where I can live without the toolbar. The keyboard will give me the functionality needed except for printing the report. However, I can live with the YesNo question if need be.

However, I am still going to be trying to get that toolbar up and running if possible. So, I am going to try the SetParent method.

SetParent(nWindowHandle1,nWindowHandle2)

where nWindowHandle1 refers to the handle to the Print Preview Toolbar Window (Right ?) and nWindowHandle2 refers to the handle to the Report Window I defined.

The next question is how do I get those handles ?



Don


 
csr,

Yes you right.

Since VFP doesn't have a true Multi thread capability, there are only two option on how you get the handle.

1. The perfect solution is to intercept window activation. But this solution needs to code from a low level language, so I won't discuss it here.

2. Use timer.
The code I gave is already working if you want to try. Then you can learn from it.

Regards

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

Part and Inventory Search

Sponsor

Back
Top