Guidance
指路人
g.yi.org
Software / Reginald / Examples / DrawGraph.rex

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

  
/*
GUIBEGIN
WINDOW , 0, 0, 400, 200, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , RxGdi Example
	FONT 8, 400, MS Shell Dlg
DEND
GUIEND
*/

/* An example of using the RxGDI Add-on DLL to do our own drawing of a graph
 * in a window.
 */

/* Load REXX GUI, and also the RxGdi Add-on libraries */
LIBRARY rexxgui, rxgdi

/* Raise SYNTAX condition for any error that happens with a RxGdi function */
gdierr = "SYNTAX"
gdiheading = 1

/* Assume the total units for the Y axis is 10 */
totalunits = 10

/* The upper left X and Y positions where to draw our graph */
startx = 5
starty = 5

/* The "values" for the months of January, March, and July */
january = 2
march = 5
july = 10

guierr = "SYNTAX"
guiheading = 1

/* Since we'll be doing our own painting of windows, then don't let the
 * operating system automatically erase the window background. We also
 * need our PAINT handler called whenever the window is resized, so we
 * specify the VREDRAW|HREDRAW styles
 */
guiwindowdefaults(, , 0, 'VREDRAW|HREDRAW')

guicreatewindow('NORMAL')

again:
DO FOREVER
	guigetmsg()
	CATCH SYNTAX
			CONDITION('M')
			SIGNAL again

	CATCH HALT
	FINALLY
		guidestroywindow()
END
RETURN


/* Called by Reginald whenever our window needs painting. This handler is
 * tricky. It should never, never create another window nor display a
 * message box. All it should ever do is draw to our window. And that's it.
 */

wm_paint:
	/* Begin our drawing by calling GdiPaint. Pass the handle to our
	 * window where the drawing is to take place. GuiCreateWindow set
	 * the GuiWindow variable to this. We also pass the name of a
	 * variable where we want the Paint handle to be returned. Here
	 * we pass a variable name of "Paint". GdiPaint will also append a
	 * "1" to this name, and set that variable to a Device Context
	 * (which we may need to pass to our Gdi functions).
	 */
	gdipaint('Paint', guiwindow)

	/* If any error happens below, let's have a FINALLY so that we
	 * can call GdiPaint to end painting.
	 */
	DO
		/* Erase our window's background. Use a WHITE brush */
		guigetctlplacement(guiwindow, , , 'Width', 'Height')
		gdistockobj("WHITE_BRUSH", "Brush")
		brush = gdisetobj(paint1, brush)
		gdirect(paint1, 0, 0, width, height)
		gdisetobj(paint1, brush)

		/* Get GUI font */
		gdistockobj("GUI_FONT", "FontHandle")

		/* Select this font into our Device Context */
		gdisetobj(paint1, fonthandle)

		/* Get the height of some typical text given our font, and add a little empty space */
		gditext(paint1, "Ij", , 'Height', 'CALCRECT')
		height = height + 5

		/* Get the width of our largest Y axis label */
		gditext(paint1, totalunits, 'Width', , 'CALCRECT')

		/* Set background drawing mode to TRANSPARENT. The background color isn't used */
		gdibkmode(paint1)

		/* Set the text color to Red = 200, Green = 70, Blue = 40. NOTE: The
		 * highest individual value is 255.
		 */
		gditextcolor(paint1, gdicolorvalue(200, 70, 40))

		/* Draw the units on the Y axis */
		i = 0
		DO totalunits
			gditext(paint1, totalunits - i, startx, (height * i) + starty, '1LINE|RIGHT', width)
			i = i + 1
		END

		/* Add a little space between the Y labels and Y axis */
		width = width + 10 + startx

		/* Draw the graph Y axis */
		xaxis = (height * totalunits) + starty
		gdiline(paint1, width, starty, width, xaxis)

		/* Draw the labels on the X axis */
		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') 

		/* Draw the graph X axis */
		xaxis = xaxis - 5
		gdiline(paint1, width, xaxis,  julx + julwidth + 5, xaxis)

		/* Draw the bars using a DKGRAY_BRUSH brush */
		gdistockobj("DKGRAY_BRUSH", "Brush")
		brush = gdisetobj(paint1, brush)

		/* Draw the january bar. NOTE: Our bar is drawn with a thickness of 20 */
		IF janwidth > 20 THEN janx = janx + (janwidth % 2) - 10
		gdirect(paint1, janx, (height * (totalunits - january)) + starty, janx + 20, xaxis)

		/* Draw the march bar */
		IF marwidth > 20 THEN marx = marx + (marwidth % 2) - 10
		gdirect(paint1, marx, (height * (totalunits - march)) + starty, marx + 20, xaxis)

		/* Draw the july bar */
		IF julwidth > 20 THEN julx = julx + (julwidth % 2) - 10
		gdirect(paint1, julx, (height * (totalunits - july)) + starty, julx + 20, xaxis)

		/* Restore the orig brush */
		gdisetobj(paint1, brush)

		CATCH SYNTAX
			/* This beep is here to alert us if any of the above calls fail. But
			 * we should NOT display a message box here. Never create another
			 * window or message box within a PAINT handler. If we need to inform
			 * another part of our program about this error, we can do a GuiWake()
			 * with some signal that our main message loop will deduce.
			 */
			BEEP()
		FINALLY
			/* End our painting */
			gdipaint(paint)
	END

	/* Don't let Rexx Gui process this event. */
	RETURN ""
掌柜推荐
 
 
¥900.00 ·
 
 
¥880.00 ·
 
 
¥497.00 ·
 
 
¥380.00 ·
 
 
¥980.00 ·
 
 
¥1,080.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:36