winprint

winprint

davidcook's picture

I'm plotting data using quickwin for the presentation. What I'd like to do is automatically print out the plots from the executable code. I used this line to start the process: status = CLICKMENUQQ(loc(winprint)). The program is waiting for an "OK" in the dialog to continue with the printing. I'd like to generate the command from within the program. Is that possible using winprint?
Thanks,
David

20 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
llynisa's picture

I was hoping that someone who knows the answer would reply because I too would like to do this.

Alan

llynisa's picture

David,
It is a long time since you asked your question, but if you are still interested, I now have a working solution for QuickWin programs. I normally develop programs using a QuickWin maximised text window and a smaller plotting window in which I produce graphs using a routine tacked onto Scigraph to produce rectangular line or scatter plots. When printing them using WinPrint, an annoyance is that the Print Setup dialog box comes up with Portrait as the default, when I almost invariably want to print in Landscape.

So I patched together parts from Norman Lawrence?s ?CVF ? A Guide to Creating Windows Applications?, Chapter 10, Bitmap Graphics and from Steve Lionel?s Fortran_Winprint (when in doubt, plagiarise) and produced a substitute subroutine PrintWin with 4 optional arguments:
1. Draw, which can be set to Normal, Stretch or StretchEven. Default is StretchEven.
2. PrintPos, which can be set to a string eg ?x30y70? to position image in the output as a percentage of page dimensions. Default is ?x0y0? (Top LH corner).
3. Orientation. Default is Landscape (but you could change that).
4. AutoPrint. If set to TRUE, sends job to printer without showing the dialog box. Default FALSE.

It can be called from a Menu via PrinWin, a subroutine without arguments.

If you (or anyone else) are interested, I would be pleased to send a copy. I would just ask for your comments on any bugs or desirable changes.

Regards

Alan

david_jones's picture

I would be interested in trying a copy of your code. Any chance you can attach a file here for general access?

drpierce's picture

Alan

I will appreciate a copy of the code you reference in your post. Please send it to take_the_train@rocketmail.com.

Many thanks
Don

llynisa's picture

David, Don,

I attach (I hope) a file with the source code of PrintWin, plus the source code of an example program using it. The latter source code will not compile for you because it uses various home-brewed utilities. The executable is too large for posting here, but you are welcome to it if you send your E-mail address to me at alan.cruttenden@baesystems.com (I won't be there until Thursday).

I found that I had to hack one pixel off the width of the window or else I got a pesky black line down the right of the printed image. I initially thought that I had taken the width of a window starting at 0 and finishing at N to be N rather than N+1, but that does not seem to be the reason. Any ideas?

I put in an extra option of CustomSize which enables control of the printed image size. It is not well-tested at present, so please tell me of any bugs.

Alan

llynisa's picture


Apologies ? I noticed the first bug about 10s after posting the code: the declaration and setting for PRINTSIZE_DEFAULT in PrintWin should be:


character*8, parameter :: PRINTSIZE_DEFAULT = 'x100y100' ! Def print size full


Fortunately the decoding routine defaults to a full-size image.

On the hidden command to print automatically in PlotXYN in PrintWinProg, I should have noted that it was:

call PrintWin(AutoPrint = .TRUE.)

Alan

david_jones's picture

Thanks for the code ... I have tried PrintWin and have a problem which results in the left hand edge not being printed properly: ie part of plot is truncated. I believe this is because I have drawn a graph having used "setvieworg" to revise the viewport coordinates whereas your code assumes that these are left at the default.

In addition I don't think there is presently a size-option which will allow the routines to produce a direct equivalent to the size that the WINPRINT produces by default. I can only get a very small plot or something which fills the page (in one or both directions).

Hope this helps
David Jones

llynisa's picture

David,

Many thanks for your response. On your first point, I would like to change PrintWin to cater for your method of production of graphics, but have no suitable image to process. Could you please send me enough code to generate an image for testing?

On your second point, at present Printwin requires both Draw to be set to CustomSize and PrintSize to be set to a suitable string for it to work. I think it is a user-friendly improvement to get PrintSize to over-ride Draw when the former is present. So replace the line

if (present(PrintSize) .AND. WDraw == CustomSize) WPrintSize = PrintSize 


by

if (present(PrintSize) .AND. Printsize /= '') then
  WDraw      = CustomSize
  WPrintSize = PrintSize
end if 



Regards

Alan

david_jones's picture

The attached should be an example with a shifted origin.

I think the default winprint behaviour scales the size of the plot an paper in proportion to the size of the window on screen to the whole screen.

David Jones

llynisa's picture

David,

Thanks for that - I shall look at it and hope to get back to you on Monday. You should be able to get the same result as the default WinPrint behaviour if you call PrintWin with:

call PrintWin(Orientation = Portrait)


Of course if you want PrintWin to behave exactly as WinPrint, change the default orientation in the source code to Portrait. Well, the same behaviour excepting how it treats your images at present.

Regards

Alan

llynisa's picture

David,

The fix is straightforward ? just set the viewport origin back to the defaults inside PrintWin. The only misgiving that I have is that this will affect your later use of the graphical image. Let me know how it goes and if necessary I will reset the viewport origin to your values.

Make the following changes:

Add xycoord to the use dflib list plus the declaration

type (xycoord)            :: xy                    ! Previous viewport origin.


Insert before getting the size of window in focus:

!
! Set viewport origin to default.
!
call SetViewOrg(0, 0, xy)



Regards

Alan

david_jones's picture

Alan,

this change does correct the intial printing problem, but then later plotting to the window is affected in my application, so that resetting the origin would be necessary. I am not familiar enough with all the different wondow coordinate system possibilities to know if the use of setvieworg is the only one which would give problems with how you are getting the image area.

In setting up the example I posted I did find another problem you might want to look at ... if the plot is put in a new child window by the simple addition of:
open(8,file='user')
(with or without an iofocus field then the new print facility prints the default (Graphic1) child window, not the 'Unit 8' window.In fact the Graphic1 child window is brought to the front, printed and left at the front. This problem doesn't affect my main aplication because I already have in place various subroutine call to force the focus where required, and I get the right thing printed. It may be that you need to look into other ways of finding the window required for printing. The default printwin seems to get the "topmost" window OK.

Hope this helps,
David Jones

david_jones's picture

Alan

I have just tried the routine with a colour printer and find that I am getting a grey-scale printout. The colour settings in the printer options windows seem to be set OK, and files sent in other ways to the print do print OK in colour. I have checked that the temporary bitmap file you create does contain a colour bitmap. Do you find that your routine works OK for a color print?

David Jones

llynisa's picture

David,

The viewport origin setting is restored by adding a line immmediately after saving to file:

!
! Save window to file and restore viewport origin settings.
!
iret     = SaveImage('Temp.bmp', 0, 0, cxClient, cyClient)
call SetViewOrg(xy.xcoord, xy.ycoord, xy)
!



I tried various ways of grabbing the correct window - if it were a Windows program one could use the Window's handle. But I could only get it to work using Quickwin routines. I'll see what I can do, but perhaps there is someone else out there who can help?

The PrintWin routine was developed using a colour printer, and works correctly both at work and home, so I am curious as to why it is giving you grief. If you would like to have the executable of the program that I used, just let me know your e-mail address. It would be interesting to see if it prints correctly for you.

Alan

llynisa's picture

David,

I have had a rummage around, but PrintWin seems to work OK for me, both on grabbing the correct window and on colours. I have modified your program and it should firstly print out automatically two small black interlaced squares partway down the page: the size depends on the relative resolutions of your screen and printer. Then it should print a single red diamond down towards the bottom RH corner in Landscape.

I am puzzled as to why you are having problems - BTW, I developed it with CVF 6.6B on W2K.

I attach PrintWin v 1.01 and the driving program. The prwin module now contains two example subroutines without arguments PrinWinL & PrinWinP, the latter for those who would like it to behave from a Menu exactly like WinPrint and display the Print Setup dialog with Orientation = Portrait.

Let me know how you are getting on.

Alan.

llynisa's picture

David,

I have now reproduced your reported error that PrintWin, when invoked from a Menu item, does not grab the image in unit 8 in TestSVO.

Although one can get the handle of the correct window using GetFocus, AFAIK there is no explict way of finding the associated unit ? an inverse of GethWndQQ. So I have instituted a search of the units until the correct one is found ? a bit of a kludge, but it works. Can anyone think of a more elegant method? The new code is:

!
! Get unit & handle of window in focus
!
iret = InqFocusQQ(Unit)                    ! Find unit in focus.
hWnd = GetFocus()                          ! Get handle of window in focus.
if (iret == 0) then                        ! If InqFocusQQ succeeds.
  hWnd = GethWndQQ(Unit)                   ! Get handle of unit in focus.
else if (hWnd /= NULL) then
  Unit = -1
  do                                       ! Search for the unit with handle
    Unit = Unit+1                          ! equal to hWnd from GetFocus.
    if (GethWndQQ(Unit) == hWnd) exit
  end do
else
  return                                    ! Failure to get the window in focus.
end if
iret = FocusQQ(Unit)                       ! Regain focus if called from Menu.!



And of course add GetFocus to the user32 list.

On the colour front, I can find no problems - it seems to work OK under all circumstances that I have investigated so far.

Alan

david_jones's picture

Alan

many thanks for your efforts. I have tried your additional code for getting the right window and it seems to work OK for me.

On the question of colour printing, I have discovered the following, which may help. My standard setup has a B/W printer for the default printer, and I selected a colour printer in the printer dialogue ... the print was sent to this printer but in B/W (as said earlier, I checked that the printer options in the dialogue were set to colour). When I set the colour printer as the default printer before starting the plotting program, and then print to this printer, the output is in colour.

David Jones

llynisa's picture

David

Yes, I have found the same behaviour using a B&W printer as default. I have (I hope) produced a solution, and have incorporated it in PrintWin Version 1.10. This has been changed from a procedure to an integer function with return values along the lines of Fortran Winprint. It also displays error messages when appropriate.

I hope that this is the last version, but would not be surprised if you detect another deficiency. Anyway, many thanks for roughing it up ? it has improved the breed.

The source file PrintWin110.f90 (31kB) produced an error when I tried to attach it, so if anybody wants it, ask me on alan.cruttenden@baesystem.com and I will send it to you.

Regards

Alan

llynisa's picture

My apologies to any of you who tried to E-mail me at the address I gave in the last post - it should have read alan.cruttenden@baesystems.com. I will try again to attach the source code for Version 1.11, which includes some mods suggested by Ed Raney and should work for versions of CVF before 6.6, using a mod cribbed from the latest version of Fortran_Winprint. It has not however been tested, so I would welcome it if one of you would do so.

Regards

Alan

Login to leave a comment.