注:本文为本人原创,转载请注明出处 http://blog.csdn.net/DavidHsing/,谢谢!
一直以来,倾心于 Nullsoft Install System 安装程序,想实现上面的横幅 (banner) 效果。
Delphi 等爱好者就不要继续往下看了,第三方的组件 TmxGradientBckgndPanel 完全可以满足你们的要求(如果不知道,看看 GOSURF)。本文所述的是采用 Visual C++ 来实现。先来张效果图看看:
可能这时有的 VC 爱好者会说,这还不容易,CStatic 不就搞定了?呵呵,不是说这么不行,只是如果要实现我下面所说的这些功能的话,CStatic 不容易;而且,别人拿 Spy++ 一看,CStatic,不专业 :) 既然选择了 VC,那我们就该来有点深度的,试试把它组件化如何?
于是,我也在 baidu 上狂 google,结果除了 CodeProject 上有篇文章有点帮助之外,其他一无所获。没办法,只好自己动手了。经过一番折腾,总算圆满的画上了一个句号。发上来纪念一下,呵呵
使用这个组件 XDialogHeader,很容易,要实现上图的效果,核心只需要两三句话。like this:
... {
CDialog::OnInitDialog();
//初始化对话框
m_XDialogHeader.SetCaptionText(_T("Registered File Types on this computer"));
m_XDialogHeader.SetDescriptionText(_T("Displaying all registered file types for this computer below."));
m_XDialogHeader.MakeDialogHeader(this);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
当然,这里只是基本的设置了标题和描述的文本内容,还有很多高级选项没有启用,比如:
void SetBackgroundColor( const COLORREF crColor);
BOOL SetBitmap( const UINT nBitmapID);
BOOL SetBitmap( const LPCTSTR lpszPathName);
void SetBitmapAlignment( const UINT uAlignment = DEFAULT_DH_BITMAP_ALIGNMENT);
void SetBitmapStyle( const UINT nStyle = DEFAULT_DH_BITMAP_STYLE);
void SetBottomStyle( const UINT uStyle = DEFAULT_DH_BOTTOM_STYLE);
void SetCaptionFontColor( const COLORREF crColor);
void SetCaptionFontFace( const LPCTSTR lpszFaceName = DEFAULT_DH_CAPTION_FONT_FACE);
void SetCaptionFontSize( const int nSize = DEFAULT_DH_CAPTION_FONT_SIZE);
void SetCaptionOffset( const int nOffset = DEFAULT_DH_CAPTION_OFFSET);
void SetCaptionText( const LPCTSTR lpszText = _T( "" ));
void SetDescriptionFontColor( const COLORREF crColor);
void SetDescriptionFontFace( const LPCTSTR lpszFaceName = DEFAULT_DH_DESCRIPTION_FONT_FACE);
void SetDescriptionFontSize( const int nSize = DEFAULT_DH_DESCRIPTION_FONT_SIZE);
void SetDescriptionOffset( const int nOffset = DEFAULT_DH_DESCRIPTION_OFFSET);
void SetDescriptionText( const LPCTSTR lpszText = _T( "" ));
void SetGradientColorFlag(BOOL bFlag);
void SetGradientStartColor( const COLORREF crColor);
void SetGradientEndColor( const COLORREF crColor);
void SetHeaderHeight( const int nHeight = DEFAULT_DH_HEADER_HEIGHT);
void SetIcon( const HICON hIcon = NULL);
void SetIconAlignment( const UINT uAlignment = DEFAULT_DH_ICON_ALIGNMENT);
void SetIconOffset( const int nOffset = DEFAULT_DH_ICON_OFFSET);
void SetTextAlignment( const UINT uAlignment = DEFAULT_DH_TEXT_ALIGNMENT);
上面的函数名称比较好理解,基本望文生义就可以了。主要就是设置字体的各种样式;位图的样式(拉伸、平铺等);对话框底部的样式(边框线等);设置背景色;设置渐变色等。