I want a graph to appear in the listbox AFTER I click OK to
process some data. This code uses READ/DATA. How can I make
this graph show only AFTER I click OK?
Steve Geisler
[email protected]
------------------
process some data. This code uses READ/DATA. How can I make
this graph show only AFTER I click OK?
Code:
'============================================= #COMPILE EXE #REGISTER NONE #DIM ALL #INCLUDE "win32api.inc" '============================================= %AbsMinPts = 1 %AbsMaxPts = 200 %MaxCols = 2 %GraphThick = 1 %XMargin = 100 %YMargin = 100 %Radius = 2 %BorderThick = 1 %GMargin = 5 GLOBAL gX#(),gY#() GLOBAL gMinPts AS INTEGER ' Array minimum index GLOBAL gMaxPts AS INTEGER ' Array maximum index GLOBAL gXMin#,gYMin#,gXMax#,gYMax# 'Min and Max of the arrays GLOBAL hDlg& GLOBAL hBox& DECLARE SUB graph DECLARE SUB plot '============================================= SUB graph LOCAL i AS INTEGER,xTemp$,yTemp$ gMinPts = %AbsMinPts : gMaxPts = %AbsMaxPts DIM gX(gMinPts : gMaxPts) DIM gY(gMinPts : gMaxPts) gMaxPts = gMinPts i = gMinPts WHILE i <= DATACOUNT xTemp = READ$(i) yTemp = READ$(i+1) gX(gMaxPts) = VAL(TRIM$(xTemp)) gY(gMaxPts) = VAL(TRIM$(yTemp)) IF gMaxPts = gMinPts THEN gXMin = gX(gMaxPts) : gXMax = gX(gMaxPts) 'Set the data Min and Max gYMin = gY(gMaxPts) : gYMax = gY(gMaxPts) ELSE SELECT CASE gY(gMaxPts) CASE < gYMin gYMin = gY(gMaxPts) CASE > gYMax gYMax = gY(gMaxPts) END SELECT END IF i = i + %MaxCols INCR gMaxPts WEND DECR gMaxPts REDIM PRESERVE gX(gMinPts : gMaxPts) REDIM PRESERVE gY(gMinPts : gMaxPts) ARRAY SORT gX(),TAGARRAY gY() gXMin = gX(gMinPts) gXMax = gX(gMaxPts) DATA 0, 134.67 DATA 1, 101.45 DATA 2, 98.45 DATA 3, 154.70 DATA 4, 189.87 DATA 5, 94.56 DATA 6, 89.23 DATA 7, 78.12 DATA 8, 99.99 END SUB '-------------------------------------------- SUB plot LOCAL LpPaint AS PaintStruct LOCAL hDC&,hBrush&,hPen&,WinX&,WinY&,i&,Colr&,j& LOCAL r AS RECT ' For Window dimensions LOCAL X0&,Y0&,X1&,Y1& ' Temporary origin to draw FROM LOCAL XMarg&,YMarg&,GMarg&,XWide&,YWide& LOCAL XUnit#,YUnit# hBox& = GetDlgItem(hDlg,103) GetClientRect hBox&, r WinX = r.nRight - r.nLeft 'Get windows dimensions WinY = r.nBottom - r.nTop hDC = BeginPaint(hBox&, LpPaint) '---------- 'Initializations XMarg = WinX/%XMargin 'Margins are 10% of the Window YMarg = WinY/%YMargin GMarg = WinY*(%GMargin/100) XWide = WinX - 2*XMarg YWide = WinY - 2*YMarg XUnit = (gXMax-gXMin) / CSNG(XWide-(2*GMarg)) YUnit = (gYMax-gYMin) / CSNG(YWide-(2*GMarg)) '---------- 'For the border hPen = CreatePen(%PS_SOLID, %BorderThick, %Black) SelectObject hDC, hPen MoveToEx hDC, XMarg, YMarg, BYVAL %NULL LineTo hDC, XMarg+XWide, YMarg MoveToEx hDC, XMarg+XWide, YMarg, BYVAL %NULL LineTo hDC, XMarg+XWide, YMarg+YWide MoveToEx hDC, XMarg+XWide, YMarg+YWide, BYVAL %NULL LineTo hDC, XMarg, YMarg+YWide MoveToEx hDC, XMarg, YMarg+YWide, BYVAL %NULL LineTo hDC, XMarg, YMarg '---------- 'For the graph Colr = %Red hPen = CreatePen(%PS_SOLID, %GraphThick, Colr) SelectObject hDC, hPen XMarg = XMarg+GMarg 'i.e. the inside margins between the border YMarg = YMarg-GMarg ' and the actual graph X0 = XMarg + CLNG ( (gX(gMinPts)-gXMin) / XUnit ) 'First point Y0 = Ymarg + (YWide - CLNG ( (gY(gMinPts)-gYMin) / YUnit ) ) Ellipse hDC, X0-%Radius, Y0-%Radius, X0+%Radius, Y0+%Radius FOR j = gMinPts TO gMaxPts 'And the points thereafter X1 = XMarg + CLNG ( (gX(j)-gXMin) / XUnit ) 'Point TO which to draw Y1 = YMarg + (YWide - CLNG ( (gY(j)-gYMin) / YUnit ) ) ' becomes next origin MoveToEx hDC, X0, Y0, BYVAL %NULL 'Move to start LineTo hDC, X1, Y1 ' and draw line from it to next Ellipse hDC, X1-%Radius, Y1-%Radius, X1+%Radius, Y1+%Radius X0 = X1 'Point FROM which to draw Y0 = Y1 'Origin point NEXT j '---------- 'Clean up EndPaint hDC, LpPaint DeleteObject hPen END SUB '-------------------------------------------- CALLBACK FUNCTION DlgProc SELECT CASE CBMSG CASE %WM_COMMAND SELECT CASE CBCTL CASE %IDOK ' Do some FUNCTUONS and SUBS here ' to get actual data. Not READ/DATA. '<========== Want to display graph ' at this point. With click ' of OK. CASE %IDCANCEL: DIALOG END CBHNDL, 0 END SELECT CASE %WM_PAINT graph Plot END SELECT END FUNCTION '-------------------------------------------- FUNCTION PBMAIN() AS LONG DIM Result AS LONG ' ** Create a new dialog template DIALOG NEW %HWND_DESKTOP,"" , 0, 0, 500, 360,%WS_CAPTION _ OR %WS_SYSMENU OR %WS_MAXIMIZE OR %DS_CENTER, 0 TO hDlg ' ** Add controls to it CONTROL ADD BUTTON, hDlg, %IDOK, "OK", 630, 255, 40, 14, %BS_DEFAULT CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 630, 280, 40, 14, 0 CONTROL ADD LISTBOX,hDlg,103, ,20,12,440,310, _ 'graph here %WS_HSCROLL OR %WS_VSCROLL OR %LBS_NOINTEGRALHEIGHT,%WS_EX_CLIENTEDGE ' ** Display the dialog DIALOG SHOW MODAL hDlg CALL DlgProc TO Result END FUNCTION
[email protected]
------------------
Comment