Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Printing graphs

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Printing graphs
#9334
Posted by: tomk 2006-12-15 19:03:00
Hi --

Is there such a function as a printdialog function available so we can now print graphs?

tk
Message2.
#9773
Posted by: Jeff Glatt 2007-01-12 18:20:59 Last edited by: Jeff Glatt 2007-06-20 13:30:04 (Total edited 2 times)
There is an rxprint add-on DLL, that contains a function (PrtScreen) to print the contents of a window.

Also, if you'd rather save the window to a .BMP file on disk, PrtScreen takes a fourth arg, the name of a REXX variable to return the bitmap (rather than sending it to the printer). And RXPRINT has two functions, PrtSaveBitmap to save the bitmap to disk, and PrtFreeBitmap to free it when done.

Here's an example to draw a graph, and save it to a .BMP file. When you select the capture menu item, you're prompted to enter the name of the bitmap file to save (ie, MyBitmap.bmp), and it will save a .BMP file.
/*
GUIBEGIN
WINDOW , 36, 126, 400, 200, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , RxGdi Example
    FONT 8, 400, MS Shell Dlg
    MENU
DEND

MENU
    HEADING File
        ITEM Capture, Capture
    <
DEND
GUIEND
*/

LIBRARY rexxgui, rxgdi, rxprint
gdierr = "SYNTAX"
gdiheading = 1
twainerr = "SYNTAX"
totalunits = 10
startx = 5
starty = 5
january = 2
march = 5
july = 10
guierr = "SYNTAX"
guiheading = 1
guiwindowdefaults(, , 0, 'VREDRAW|HREDRAW')
guicreatewindow('NORMAL')
again:
DO FOREVER
  guigetmsg()
  CATCH SYNTAX
    CONDITION('M')
    SIGNAL again

  CATCH HALT
  FINALLY
    guidestroywindow()
END
RETURN

wm_paint:
  gdipaint('Paint', guiwindow)
  DO
    guigetctlplacement(guiwindow, , , 'Width', 'Height')
    gdistockobj("WHITE_BRUSH", "Brush")
    brush = gdisetobj(paint1, brush)
    gdirect(paint1, 0, 0, width, height)
    gdisetobj(paint1, brush)
    gdistockobj("GUI_FONT", "FontHandle")
    gdisetobj(paint1, fonthandle)
    gditext(paint1, "Ij", , 'Height', 'CALCRECT')
    height = height + 5
    gditext(paint1, totalunits, 'Width', , 'CALCRECT')
    gdibkmode(paint1)
    gditextcolor(paint1, gdicolorvalue(200, 70, 40))
    i = 0
    DO totalunits
      gditext(paint1, totalunits - i, startx, (height * i) + starty, '1LINE|RIGHT', width)
      i = i + 1
    END
    width = width + 10 + startx
    xaxis = (height * totalunits) + starty
    gdiline(paint1, width, starty, width, xaxis)
    xaxis = xaxis + 5
    janx = 5 + width
    gditext(paint1, "January", janx, xaxis, '1LINE')
    gditext(paint1, "January", 'JanWidth', , 'CALCRECT|1LINE')
    marx = 40 + janx + janwidth
    gditext(paint1, "March", marx, xaxis, '1LINE')
    gditext(paint1, "March", 'MarWidth', , 'CALCRECT|1LINE') 
    julx = 40 + marx + marwidth
    gditext(paint1, "July", julx, xaxis, '1LINE')
    gditext(paint1, "July", 'JulWidth', , 'CALCRECT|1LINE') 
    xaxis = xaxis - 5
    gdiline(paint1, width, xaxis,  julx + julwidth + 5, xaxis)
    gdistockobj("DKGRAY_BRUSH", "Brush")
    brush = gdisetobj(paint1, brush)
    IF janwidth > 20 THEN janx = janx + (janwidth % 2) - 10
    gdirect(paint1, janx, (height * (totalunits - january)) + starty, janx + 20, xaxis)
    IF marwidth > 20 THEN marx = marx + (marwidth % 2) - 10
    gdirect(paint1, marx, (height * (totalunits - march)) + starty, marx + 20, xaxis)
    IF julwidth > 20 THEN julx = julx + (julwidth % 2) - 10
    gdirect(paint1, julx, (height * (totalunits - july)) + starty, julx + 20, xaxis)
    gdisetobj(paint1, brush)
    CATCH SYNTAX
      BEEP()
    FINALLY
      gdipaint(paint)
  END
  RETURN ""

capture:
  /* Capture GuiWindow's contents to a bitmap */
  err = prtscreen("My document", guiwindow, , "MyBitmap")
  IF err \== 0 THEN guisay(UNIXERROR(err))
  ELSE DO
     /* Get a filename to save the bitmap */
     fn = ''
     guifile('fn', 'OVERWRITE|PATH|SAVE', 'Choose where to save the bitmap', 'Bitmap files (*.bmp) | *.bmp | All files (*.*) | *.*')
     DO
        /* Save the bitmap to disk */
        err = prtsavebitmap(mybitmap, fn)
        IF err \== 0 THEN guisay(UNIXERROR(err))

        CATCH SYNTAX
           CONDITION('M')
     END

     CATCH SYNTAX
     FINALLY
        /* Free the bitmap */
        prtfreebitmap(mybitmap)
  END
  RETURN
Message3.
#9798
Posted by: tomk 2007-01-14 00:09:24
Hi, Jeff ---

Nice job. Only one perhaps difficult request:  allow us to scale the horizontal and
vertical size of the output.

Choosing 'nosize' makes a very small graph in left upper corner of paper.
Omitting 'nosize' fills entire page.

Couldn't get something inbetween with paper border - or maybe this is what page setup is for????

tk
Message4.
#9818
Posted by: el_supremo 2007-01-15 10:04:48
Jeff:
I've been trying to get the bitmap in rxprint sent to the clipboard but the code crashes or does nothing and I can't tell whether the crash is because of my code or because of the random crashes I've been having with reglite recently.

At the beginning of rxprint.rex I've defined the windows clipboard functions like this:

	FUNCDEF("OpenClipboard","32","user32")
	FUNCDEF("EmptyClipboard","32","user32")
	FUNCDEF("SetClipboardData","void,32,void","user32")
	FUNCDEF("CloseClipboard","32","user32")

and I've added this bit of code just before the printsavebitmap():

    openclipboard();
    emptyclipboard();
    /* CF_BITMAP = 2 */
    SAY setclipboarddata(2,mybitmap);
    closeclipboard();


Should this work - does it work for you?
The say statement prints a zero - not a good sign. But I can't add a say to OpenClipboard to find out if it worked because the script crashes. It also crashes if all I do is i=OpenClipboard().

Is MyBitmap a HBITMAP pointer?

Thanks
Pete
Message5.
#9819
Posted by: el_supremo 2007-01-15 10:57:34
To answer my own questions:
The funcdefs should be:

	FUNCDEF("OpenClipboard","32,","user32")
	FUNCDEF("EmptyClipboard","32,","user32")
	FUNCDEF("SetClipboardData","void,32,void","user32")
	FUNCDEF("CloseClipboard","32,","user32")

and then it works!!

So MyBitmap must be HBITMAP or SetClipboardData wouldn't work.

Pete
Message6.
#9821
Posted by: Jeff Glatt 2007-01-15 12:34:47 Last edited by: Jeff Glatt 2007-01-15 12:37:38 (Total edited 1 time)
Yes, the return from PrtScreen is an HBITMAP. I don't believe that you should call PrtFreeBitmap if you successfully put it on the clipboard (but I'd have to check some stuff to verify that).

Hmmm. I didn't think that you needed that extra comma if there are no args to be passed. I'll have to check for a FUNCDEF bug.
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥1,800.00 ·
 
 
¥489.00 ·
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥748.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0