11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13. Adding Special Features to Application<br />

Also, when WM_SETTEXT or WM_SYSCOMMAND messages are received, the caption needs to be updated. So<br />

within the two message handlers, message WM_NCPAINT is sent to the mainframe window:<br />

LONG CMainFrame::OnSetText(WPARAM wParam, LPARAM lParam)<br />

{<br />

SendMessage(WM_NCPAINT, 0, 0);<br />

return (LRESULT)TRUE;<br />

}<br />

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)<br />

{<br />

CFrameWnd::OnSysCommand(nID, lParam);<br />

if(::IsWindow(GetSafeHwnd()))SendMessage(WM_NCPAINT, 0, 0);<br />

}<br />

Figure 13-5 shows the result of the above implementation.<br />

Figure 13-5. Customized caption bar<br />

13.6 Irregular Shape Window<br />

Theoretically speaking, all windows created in Windows system must be rectangular. This satisfies<br />

our needs most of the time. However, sometimes it would be more preferable to let windows have irregular<br />

shapes. For example, in multimedia type applications, sometimes we need to implement a special elliptical<br />

(or more complex shape) “callout” window with a pointer pointing to an object, with the explanation of the<br />

object displayed within the ellipse. The user may feel free to resize or move this window, and edit the text<br />

within it (Figure 13-6).<br />

Problem<br />

Figure 13-6. Irregular shape window<br />

To implement such type of window, we can let the application paint only within the elliptical area and<br />

leave the rest area unchanged.<br />

However, this will cause problem when the user moves or resizes the window. Although only the<br />

elliptical area is painted, the window is essentially rectangular. By default, the portion not covered by the<br />

405

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!