[windev] scrolling windows and device contexts and such...
David Little
dlittle at coade.com
Sun Mar 8 20:25:32 GMT 2009
I wrote an EasterEgg a long time ago that scrolls 'credits'. I made one
giant bitmap, showed page one with a BitBlt, then use ScrollDC() in a
loop that contains a message handler, so both the window repaints and
the rest of the app processes its messages - kind of a hack
multi-threaded app. Anyway, here's the loop, which sounds to me like
just what you asked for:
for (int y = 0; y < dyScroll && m_bShowing; y++)
{
DWORD dwTickTock;
cdcClient.ScrollDC(0, -1, rcScroll, NULL, NULL, NULL);
if (y < rcMemory.Height())
cdcClient.BitBlt( rcClient.left, rcClient.bottom
- 1, rcClient.right, 1, &cdcMem, 0,
y, SRCCOPY );
else
cdcClient.BitBlt( rcClient.left, rcClient.bottom
- 1, rcClient.right, 1, &cdcScreenMem,
0, y - rcMemory.Height(), SRCCOPY );
while(( dwTickTock = GetTickCount()) - dwTicks <
dwScrollTime )
{
if (!IsWindowVisible())
{
m_bShowing = FALSE;
// Stop the message scrolling
continue;
}
MSG msg;
while(::PeekMessage(&msg, NULL, 0, 0,
PM_REMOVE))
{
if (msg.message == WM_DESTROY)
{
PostMessage(WM_DESTROY);
// So the message makes it into my queue
m_bShowing = FALSE;
// Stop the message scrolling
continue;
}
if
(!AfxGetApp()->PreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
AfxGetApp()->OnIdle(0); // Update user
interface
AfxGetApp()->OnIdle(1); // Free temp
objects
}
}
dwTicks = dwTickTock;
}
Regards
- David Little
- Houston, TX
-----Original Message-----
From: windev-bounces at windev.org [mailto:windev-bounces at windev.org] On
Behalf Of Stephen Hazel
Sent: Saturday, March 07, 2009 1:33 PM
To: Windev
Subject: [windev] scrolling windows and device contexts and such...
Env: msvc7? (2002); c++; Win32 (no MFC); XP,etc
Ok, I need the help of you win32 gurus again.
my app is displaying bitmaps of scanned sheet music.
A bitmap per page of sheet music. (well, a bitmap per half page of
music).
I display 2 at a time StretchBlt'd to top and bottom halves of a window.
I need to scroll the next one in smoothly so you don't lose your place.
And I need the scrolling to not burn much cpu.
I'm in a pretty tight midi event dumping loop.
Now, if i understand win32 correctly, a display device context has no
size
beyond what's currently displayed on the monitor.
You can scroll a window and what's there gets scooted, but the "moved
from" area
is just invalidated and the code called by wm_paint redraws it.
So there's no such thing as a "bigger canvas" that's larger than the
window and you
just say "scroll!" and wherever the window is positioned over the
canvas, bam,
it's done for you.
So the way you do it is a memory device context that has a bitmap that
holds
this "full canvas of bits" and wherever you scroll to, you calc the area
of
this memory device context that's SHOWing and you blt it on screen.
I might StretchBlt 3 bitmaps into the memory device context+bitmap then
do a scrollwindowex() (no erase,no inval) and straight blt of new area?
Am I on the right track here?
Does anybody know if ScrollWindowEx's smooth scrolling option comes back
immediately or comes back after the scroll delay time has passed?
My app has 2 threads - the main gui one and a midi processing loop one.
I might have to move the scrolling to the gui thread somehow.
Now, I'm StretchBlt'ing the 2 bitmap halves repeatedly to scroll
and it's sucking cpu :(
(I guess that's for me to deal with)
Thanks much for any ideas :)
...Steve
--
Windev mailing list at Windev at windev.org
Lost your password? Need to unsubscribe or change your delivery
options?
Go to http://lists.windev.org/mailman/listinfo/windev
--
Search the Windev Archives - www.windev.org
More information about the Windev
mailing list