- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am tring to animate graphics. When I run my program it executes the code but only the last frame shows up. There is a delay which I assume is because it is "drawing" the frames. So I must not be doing something that will update the window for each frame.
Here is a portion of my code that does the animation. The routine gtest does the actual drawing of the frame.
case (IDM_GRAPH_CYCLE)
do i=1,nhours
pdate = dates1(nhours)
ptime = times1(nhours)
newdata = .true.
call gtest (hWnd)
retlog = UpdateWindow(hWnd)
call sleep(100)
enddo
ret = InvalidateRect (hWnd, NULL_RECT, .TRUE.)
MainWndProc = 0
return
Here is a portion of my code that does the animation. The routine gtest does the actual drawing of the frame.
case (IDM_GRAPH_CYCLE)
do i=1,nhours
pdate = dates1(nhours)
ptime = times1(nhours)
newdata = .true.
call gtest (hWnd)
retlog = UpdateWindow(hWnd)
call sleep(100)
enddo
ret = InvalidateRect (hWnd, NULL_RECT, .TRUE.)
MainWndProc = 0
return
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK here is the code again. I hope it comes out better.
case (IDM_GRAPH_CYCLE) do i=1,nhours pdate = dates1(nhours) ptime = times1(nhours) newdata = .true. call gtest (hWnd) retlog = UpdateWindow(hWnd) call sleep(100) enddo ret = InvalidateRect (hWnd, NULL_RECT, .TRUE.) MainWndProc = 0 return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's almost good -- you should move InvalidateRect before UpdateWindow; UpdateWindow updates only if there's something to update -- you have to tell what it is with InvalildateRect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav,
That worked great !! It is now cycling through the frames. However it is not smooth. It shows each frame as it is drawn. Do I need to do some sort of double buffering ? If so how do I do that. Thanks
That worked great !! It is now cycling through the frames. However it is not smooth. It shows each frame as it is drawn. Do I need to do some sort of double buffering ? If so how do I do that. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Double-buffering improves the animation, surely. You should use:
to create buffer DC. Your WM_PAINT handler should have, apart from
BeginPaint/EndPaint, only:
Always draw on hBufferDC and you can do it whenever you need update (not on WM_PAINT). Only ensure that you call InvalidateRect when you do the drawing.
Of course, take care that of proper creation/destruction (DeleteDC) of hBufferDC -- usually, you create it only once and destroy it at program end.
HTH
Jugoslav
hBufferDC = CreateCompatibleDC(hWindowDC, iWidth, iHeight) hBmp = CreateCompatibleBitmap(hWindowDC) iSt = SelectObject(hBufferDC, hBmp)
to create buffer DC. Your WM_PAINT handler should have, apart from
BeginPaint/EndPaint, only:
hDC = BeginPaint(hWnd, ps) iSt = BitBlt(hDC, ps%rcPaint%Left, ps%RcPaint%Top, & ps%rcPaint%Right-ps%rcPaint%Left, ps%rcPaint%Bottom-ps%rcPaint%Top, & hBufferDC, ps%rcPaint%Left, ps%rcPaint%Top,SRCCOPY)
Always draw on hBufferDC and you can do it whenever you need update (not on WM_PAINT). Only ensure that you call InvalidateRect when you do the drawing.
Of course, take care that of proper creation/destruction (DeleteDC) of hBufferDC -- usually, you create it only once and destroy it at program end.
HTH
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page