340 likes | 807 Views
PC43. What's New with user32 and comctl32 in Win32. Raymond Chen Programmer Microsoft Corporation. Eight Things You Didn't Know You Had And one essay. Double-buffered painting Cross-fade animation helpers List view tiles List view grouping Cue banners and empty text
E N D
PC43 What's New with user32 and comctl32 in Win32 Raymond Chen Programmer Microsoft Corporation
Eight Things You Didn't Know You HadAnd one essay • Double-buffered painting • Cross-fade animation helpers • List view tiles • List view grouping • Cue banners and empty text • Images next to menu items • Icon scaling • Foreground activation is like love
Double-Buffering Helpers • // WM_CREATE • BufferedPaintInit(); • // WM_DESTROY • BufferedPaintUnInit(); • // WM_PAINT • hdc = BeginPaint(hwnd, &ps); • hBuffer = BeginBufferedPaint(…, &hdc); • PaintContent(hwnd, hdc); • EndBufferedPaint(hBuffer, TRUE); • EndPaint(hwnd, &ps);
demo Double Buffering
Double-Buffering Traps • Not filling your background • Not suppressing WM_ERASEBKGND • Remote Desktop / Terminal Services
Advanced Double-Buffering • BP_BUFFERFORMAT • BP_PAINTPARAMS • dwFlags • prcExclude • pBlendFunction • GetBufferedPaintBits() • BufferedPaintSetAlpha()
Cross-Fade Animation Helpers • // WM_PAINT • if (!BufferedPaintRenderAnimation(…)) { • parms.dwDuration = ANIMATION_DURATION; • hBuffer=BeginBufferedAnimation(…, • &hdcFrom, &hdcTo); • if (hdcFrom) paint into hdcFrom; • if (hdcTo) paint into hdcTo; • EndBufferedAnimation(hBuffer, TRUE); • }
Painting With Cross-Fades • Identify and isolate states • Draw based on state as parameter • Maintain last-drawn and current states • BufferedPaintStopAllAnimations
Animating And Not Animating • // WM_PAINT • if (!BufferedPaintRenderAnimation(…)) { • parms.dwDuration = ANIMATION_DURATION; • if (m_curState == m_drawnState) • parms.dwDuration = 0; • hBuffer=BeginBufferedAnimation(…, • &hdcFrom, &hdcTo); • if (hdcFrom) • PaintState(hdcFrom, m_drawnState); • if (hdcTo) • PaintState(hdcTo, m_curState); • EndBufferedAnimation(hBuffer, TRUE); • m_drawnState = m_curState; • }
demo Cross Fade Animation
Oops: Windows 7 Content • Windows 7 animation engine • Windows 7: New Text and Graphics APIs • You just missed it • But you can still catch the hands-on lab
List View Tiles • Richer item view than icon and label • Easier to read than report view but takes up more space • ListView_SetView(LV_VIEW_TILE)
demo List View Tiles
Controlling List View Tiles • Specify how many additional lines of text you want to display in the tile • For each item, specify which columns you want to show as additional text • Usually the same for each item • Optionally set fixed tile size and margins
demo List View Tiles: Round 2
List View Extended Tiles • They don’t work • Sorry
Windows XP List View Grouping • Create groups (ListView_InsertGroup) • Put each item into a group (iGroupId) • Turn on grouping (ListView_EnableGroupView)
demo List View Grouping
Grouping Traps • Don’t forget to assign items to groups • Create groups before adding items to them • Don't give two groups the same ID
Windows Vista List View Grouping • Group subtitles (LVGF_SUBTITLE) • Group footers (LVGF_FOOTER) • Collapsible groups (LVGS_COLLAPSIBLE) • Group command links (LVN_LINKCLICK) • Enumerating group contents (LVNI_SAMEGROUPONLY | LVNI_VISIBLEORDER)
demo List View Grouping:Round 2
Grouping Insanity • Prerequisites for group descriptions • Group header image list • Group must have a title image • Group header must be centered • If you know what’s good for you • Don’t actually use a title image
demo List View Grouping:The Insanity
Cue Banners • EM_SETCUEBANNER • CB_SETCUEBANNER
Empty Text • LVN_GETEMPTYMARKUP
Alpha-Blended Menu Bitmaps • MENUITEMINFO.hbmItem and MIIM_BITMAP • 32bpp PARGB format supported in Vista via DIBSECTION • Don’t forget to DeleteObject it
demo Menu Bitmaps
Icon Scaling • LoadIconWithScaleDown implement a new scaling algorithm • Icon must include images at sizes 16, 32, 48, 256 • LoadImage/Icon still use old algorithm • SHDefExtractIcon uses new algorithm
Foreground Activation Is Like Love • You can share it with others • You cannot steal it • SetForegroundWindow • AllowSetForegroundWindow • CoAllowSetForegroundWindow
Evals & Recordings Please fill out your evaluation for this session at: This session will be available as a recording at: www.microsoftpdc.com
Q&A Please use the microphones provided
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.