Older Version Newer Version

rtrussell rtrussell Oct 7, 2013

Code which produces a scrollable line graph in a graphicbox. [[code format="vb"]]The original version ran too fast on a modern PC so I have made a small modification so that the scrolling speed is determined by the timer. [[code format="lb"]] nomainwin WindowHeight = 350 WindowWidth = 550 graphicbox #main.graphicbox, 15, 15, 510, 290 open "experiment" for window as #main print #main.graphicbox, "down; fill white" print #main.graphicbox, "place 20 20" print #main.graphicbox, "\Graph control:" print #main.graphicbox, "place 20 40" print #main.graphicbox, "\<<< >>>" print #main, "trapclose [quit]" print #main.graphicbox, "when leftButtonDown [shift]" print #main.graphicbox, "when leftButtonUp [null]" print #main.graphicbox, "flush" hWnd = hwnd(#main.graphicbox) CallDLL #user32, "GetDC", hWnd As long, hDC As long CallDLL #gdi32,"CreateCompatibleDC", hDC As long, memDC As long calldll #gdi32, "CreateCompatibleBitmap", _ hDC As Long, _ 3000 As Long, _ 150 As Long, _ hBuffer as Long CallDLL #gdi32,"SelectObject",_ memDC As long,_ hBuffer As long,_ oldObject As long CallDll #gdi32, "GetStockObject", _WHITE_PEN as long, hpen as long CallDll #gdi32, "SelectObject",_ memDC as long,_ hpen as long, _ Hpobj as long struct Ppos,xlast as long, ylast as long CallDll #gdi32, "MoveToEx",_ memDC as long,_ 0 as long,_ 0 as long,_ Ppos as struct,_ setstart as boolean for traces = 1 to 100 stepper = traces * 30 dataplot = 10 + int(rnd(1)*60) CallDll #gdi32, "LineTo",_ memDC as long,_ stepper as long,_ dataplot as long,_ linedone as boolean next traces dwRop = hexdec("00CC0020") takefrom = 1400 call bitblock hDC, 160, 100, 300, 150, memDC, takefrom, 0, dwRop, breturnvalue #main.graphicbox, "getbmp KeepIt 160 100 300 150"; #main.graphicbox, "drawbmp KeepIt 160 100; flush"; [null] timer 0 wait [shift] scantimer 10, [tick] wait [tick] if (MouseY>26 and MouseY<43) then if if (MouseX>17 and MouseX<45) then goto [mleft] if if (MouseX>83 and MouseX<108) then goto [mright] end if wait [mright] if (takefrom < 2700) then takefrom takefrom = takefrom + 1 call call bitblock hDC, 160, 100, 300, 150, memDC, takefrom, 0, dwRop, breturnvalue end if goto [shift]wait [mleft] if (takefrom > 0) then takefrom takefrom = takefrom - 1 call call bitblock hDC, 160, 100, 300, 150, memDC, takefrom, 0, dwRop, breturnvalue end if goto [shift]wait sub bitblock destDC, tox, toy, wide, high, fromDC, fromx, fromy, variety, breturnvalue calldll #gdi32, "BitBlt", _ destDC As Long, _ tox As Long, _ toy As Long, _ wide As Long, _ high As Long, _ fromDC As Long, _ fromx As Long, _ fromy As Long, _ variety As Long, _ result as Long end sub [quit] CallDLL #gdi32, "DeleteDC",_ memDC As long,_ DCdeleted As Boolean CallDll #user32, "ReleaseDC",_ hWnd as long,_ hDC as long,_ DCreleased as long close #main end [[code]]