|
Post by David Drake on Apr 20, 2020 13:57:28 GMT -5
I created a fun experimental US national radar tool. It downloads the latest mosaic images from the National Weather Service then animates them in a graphics window. It's slow, clunky, buggy, and crashes regularly, and was really fun to make. I incorporated Alyce Watson's image323.dll because I needed to load and manipulate GIF files. Yes, I know there's a smaller DLL out there for loading, and I know I could have used the NVIEWDLL dll, but I'm working on another version that loads local radars and needed to be able to create a masked bitmap (maybe I'll post it later). All that to say, because there's a DLL involved, I packaged the radar file, DLL and Alyce's demo code for the DLL into a zip that you can download from my website, the rewarmed Liberated Code Foundry. Direct link to file: www.kkb9.com/lcf/downloads/nexrad.zipCheers! - David
|
|
|
Post by Rod on Apr 21, 2020 4:06:42 GMT -5
I am afraid it locks up my PC and I need CtrlAltDel Taskmanager to get control back. It seems to be locked in the fetchmin loop and does not seem to get anywhere near the 300 loop limit. It just presents a blank white screen.
|
|
|
Post by honkytonk on Apr 21, 2020 5:21:40 GMT -5
" if fetchMin<>-1 then a=a+9:htmlFile$ = httpget$(radFilename$(a))"--> Type mismatch ....httpget$(val(radFilename$(a))) And: #1 #im #2 Protection Violation
|
|
|
Post by David Drake on Apr 21, 2020 7:19:26 GMT -5
Not sure what's happening. The code works on my machine. Where I run into problems is after a few updates it crashes. Well, let's call it an alpha version. What comes before alpha?
|
|
|
Post by Rod on Apr 21, 2020 8:22:28 GMT -5
I was wondering if it is the date time calculation. Perhaps not. Can you take the time from the web site and use that to backtrack ? A simple SCAN in the midst of the loop would let people break out if it has gone pear shaped.
Yep the httpget$ is coming back with a 404 not found return and your code just keeps looping.
|
|
|
Post by Brandon Parker on Apr 21, 2020 20:57:55 GMT -5
Seems to work fine on my laptop, and looks pretty nice.
{:0)
Brandon Parker
|
|
|
Post by David Drake on Apr 22, 2020 17:54:01 GMT -5
At least one problem is here:
currentSecondsUTC=time$("seconds")+5*60*60
I hard-coded the time differential between my time zone (CDT) and GMT, which is +5 hours. If you change the "5" in this to indicate your particular time differential, maybe it will work.
|
|
|
Post by Rod on Apr 23, 2020 2:39:34 GMT -5
Ok, fixing the time got it running. However its burning memory. Each time it sets off to get another set of gifs it ads about 20mb memory use. So it will crash eventually. Its an interesting project. The date stamp on the files is annoying, they should publish the current time to make it easier to get the file spec. However the biggest change I would make is to dump the .dll and the masking and the gif conversion. The LBPE has all the code you need. There is an API load image example which will load the .gif file directly. There are also examples of using the blitter and TransparentBlt avoids the need for masking. If I get some time I will try and pull an example together.
|
|
|
Post by Rod on Apr 23, 2020 6:16:01 GMT -5
You are probably quite happy with the code. However it is possible to load .gif files directly and to draw them directly without masking provided they do actually have a white background layer. They are supposed to.
All of this code is straight out the LBPE.
nomainwin WindowWidth=600 WindowHeight=282 UpperLeftX=DisplayWidth/2 UpperLeftY=DisplayWidth/2 graphicbox #1.gb, 0,0,600,282 open "Radar" for window as #1 #1 "trapclose [quit]"
'open the windows .dll required for transparentBlt open "msimg32.dll" for dll as #m open "gdiplus.dll" for dll as #gdip
' set up our bitmaps, open device contexts and store our bitmaps in them #1.gb "down ;fill cyan ; color red ; place 300 140 ; circle 100" #1.gb "getbmp background 0 0 600 282" #1.gb "fill white ; place 300 140 ; color green ; backcolor green ; boxfilled 320 160" #1.gb "getbmp overlay1 0 0 600 282" #1.gb "fill white ; place 250 140 ; color green ; backcolor green ; boxfilled 270 160" #1.gb "getbmp overlay2 0 0 600 282" #1.gb "fill white ; place 200 140 ; color green ; backcolor green ; boxfilled 120 160" #1.gb "getbmp overlay3 0 0 600 282"
' displayDC is our graphics screen/graphicbox displayDC=GetDC(hwnd(#1.gb))
' backgroundDC is a copy of the background in memory backgroundDC=CreateCompatibleDC(displayDC) hBitmap=hbmp("background") oldBmp=SelectObject(backgroundDC,hBitmap)
' sourceDC is a bitmap held in memory from which we get all our graphics sourceDC=CreateCompatibleDC(displayDC) hBitmap=hbmp("overlay1") oldBmp=SelectObject(sourceDC,hBitmap)
' flip background on screen call StretchBlt,displayDC,0,0,600,282,backgroundDC,0,0,600,282
' flip the overlay onscreen using white as the mask color call TransparentBlt,displayDC,0,0,600,282,sourceDC,0,0,600,282,255+255*256+255*256^2
'set up a repetative call to [draw] timer 200, [draw] wait
[draw] ' flip background onscreen to erase old drawing call StretchBlt,displayDC,0,0,600,282,backgroundDC,0,0,600,282
' flip the current overlay onscreen using white as the mask color call TransparentBlt,displayDC,0,0,600,282,sourceDC,0,0,600,282,255+255*256+255*256^2
'now use GDIPlus to load the next .gif directly to memory 'I just load the same .gif each time you would need to cycle 'Through the file set
'The greatest trouble I had creating the demo was learning 'how to create a .gif with a white background! 'I hope it works on your .gif files. They do say there 'is a backgroud white layer, if the gif has that the code works.
hBmp=LoadImgFromFile("rad0.gif") if hBmp<>0 then oldBmp=SelectObject(sourceDC,hBmp) 'loadbmp "pic",hBmp 'unloadbmp "pic" 'Because LB doesnt delete it for us calldll #gdi32,"DeleteObject",hBmp as ulong, ret as ulong else notice "Could not load the image file!" end if wait
[quit] timer 0 call ReleaseDC hwnd(#1), displayDC call ReleaseDC hwnd(#1), bufferDC call ReleaseDC hwnd(#1), backgroundDC call ReleaseDC hwnd(#1), sourceDC call DeleteDC displayDC call DeleteDC bufferDC call DeleteDC backgroundDC call DeleteDC sourceDC close #1 close #m close #gdip end
'=============================Dan Teel's GDIP Functions============================ function wchar$(string$) for i = 1 to len(string$) wchar$=wchar$+mid$(string$,i,1)+chr$(0) next i wchar$=wchar$+chr$(0)+chr$(0) end function
function LoadImgFromFile(file$) struct dword,a as ulong gdistart$=chr$(1) for i = 1 to 15 gdistart$=gdistart$+chr$(0) next i calldll #gdip,"GdiplusStartup",dword as struct,gdistart$ as ptr,status as ulong token=dword.a.struct if status<>0 then LoadImgFromFile=0
else wFileLoc$=wchar$(file$) calldll #gdip,"GdipCreateBitmapFromFile", _ wFileLoc$ as ptr,dword as struct,status as ulong hPic=dword.a.struct if status<>0 then LoadImgFromFile=0 else calldll #gdip,"GdipCreateHBITMAPFromBitmap", _ hPic as ulong,dword as struct,0 as ulong,status as ulong hBmp=dword.a.struct if status<>0 then LoadImgFromFile=0 else LoadImgFromFile=hBmp end if calldll #gdip,"GdipDisposeImage",hPic as ulong,ret as ulong end if calldll #gdip,"GdiplusShutdown",token as ulong,ret as ulong end if end function
'=============================Alyce's Window and DC functions================================= Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As Ulong,_ 'window or control handle GetDC As Ulong 'returns device context End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",_ hWnd As Ulong,_ 'window or control handle hDC As Ulong,_ 'handle of DC to delete result As Long End Sub
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As Ulong,_ 'window DC CreateCompatibleDC As Ulong 'memory DC End Function
Sub DeleteDC hDC CallDLL #gdi32, "DeleteDC",_ hDC As Ulong,_ 'memory DC to delete result As Boolean End Sub
Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2 CallDLL #gdi32, "SetStretchBltMode",_ hDCdest As Ulong,_ 'device context _COLORONCOLOR As Long,_ 'color reduction mode result As Long CallDLL #gdi32, "StretchBlt",_ hDCdest As Ulong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As Ulong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source _SRCCOPY As Ulong,_ 'dwRasterOperation result As Boolean End Sub
Sub TransparentBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2,crTransparent calldll #m, "TransparentBlt",_ hDCdest As Ulong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As Ulong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source crTransparent as long,_ 'color to make transparent result as boolean end sub
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As Ulong,_ 'memory device context hObject As Ulong,_ 'handle of object SelectObject As Ulong 'returns previously selected object End Function
|
|