漂亮界面

lekuaile 2003-09-27 01:56:43
要做xp风格的界面有什么好方法,如何在标题栏和菜单栏中加背景图片?
...全文
154 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Skt32 2003-09-27
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc.asp?id=529
http://www.vckbase.com/code/downcode.asp?id=1959
Skt32 2003-09-27
  • 打赏
  • 举报
回复
支持换肤功能的窗口实例
译者:李不言
原文来源:codeproject

下载本文示例代码

这个例子展示了如何绘制定制(自绘)窗口框架(包括标题、边框等)。


一、前言
如今,支持定制皮肤功能的软件越来越流行。这样用户就可以自己修改程序的外观。甚至Windows操作系统本身做到这点了。Windows XP提供的主题(theme)技术可以修改窗口、按钮、滚动条等的外观。

最近,我想用MFC设计一个可以换肤的程序。在网上我没有搜索到任何想要的东西,所以我决定自己写一个。这不是一个很难的问题,但是需要对Windows操作系统的绘制窗口的机制比较熟悉。

二、背景
我提供了下面的一些类:

1. CSkinWin----CSkinWin类是一个绘制定制(自绘)窗口的类。它绘制窗口上、下、左、右边框和标题栏按钮如最大化、关闭按钮。为了作到这一点,CSkinWin类从一个ini文件读入配置信息,在ini文件配置窗口各边框的位图。需要指出的是,ini文件的格式是从Windows Blinds(Stardock的杰作)的UIS格式拷贝过来的,因为我希望在我的程序里支持Windows Blinds的主题。

2. CSkinButton---CSkinButton类是绘制定制(自绘)按钮的类。它用四个位图分别代表正常、有焦点、按下和无效状态。位图格式也是Windows Blinds格式,参数在同一个ini文件中定义。因为一个窗口会有多个按钮实例,所以我设计了CSkinButtonResource类来存放定制(自绘)按钮的皮肤。

3. CMyBimtap 等--- 一些相关类,其中有些是来自Codeproject. 尽管我已经不记得这些作者了,但我还是要感谢它们.

三、用法

这些代码的用法很直接。我包含了一个MFC基于窗口的工程,关键代码列在下面。顺便提一下,这些代码在单文档的工程里也测试通过了。 //defines the following member in the dialog class
CSkinButtonResource m_btnres; //skin button resource
CSkinWin m_skinWin; //skin win
BOOL m_bFirst; //first time call
CObList m_wndList; //hold button instance

//In OnInitDialog
m_bFirst = TRUE;
SetSkin( "skin\\neostyle\\theme.ini" );


//SetSkin is a function to change skin
BOOL CSkinTestDlg::SetSkin(CString file)
{
m_skinWin.LoadSkin( file ); //load skin bitmap and parameters
m_btnres.LoadSkin( file );
if ( m_bFirst )
{
//if it''s the first time call, InstallSkin
m_skinWin.InstallSkin( this );
//call EnumChildWindows to subclass all buttons
EnumChildWindows( m_hWnd, EnumChildProc, (LPARAM)this );

m_bFirst = FALSE;
}

//redraw window after change skin
SetWindowPos( 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |SWP_FRAMECHANGED );
return TRUE;
}


//enum child window and take chance to subclass them
#define GetWindowStyle(hwnd) ((DWORD)GetWindowLong(hwnd, GWL_STYLE))
BOOL CALLBACK EnumChildProc( HWND hwnd, // handle to child window
LPARAM lParam // application-defined value
)
{
char classname[200];
CSkinTestDlg *dlg = (CSkinTestDlg *)lParam;
DWORD style;

GetClassName( hwnd, classname, 200 );
style = GetWindowStyle( hwnd );
if ( strcmp( classname, "Button" ) == 0 )
{
style = (UINT)GetWindowLong(hwnd, GWL_STYLE) & 0xff;
if ( style == BS_PUSHBUTTON || style == BS_DEFPUSHBUTTON )
dlg->SubClassButton( hwnd );
}


return TRUE;
}

//subclass push buttons
BOOL CSkinTestDlg::SubClassButton( HWND hwnd )
{
CSkinButton * btn = new CSkinButton();
CWnd* pWnd = CWnd::FromHandlePermanent(hwnd);
if ( pWnd == NULL)
{
btn->SubclassWindow( hwnd );
btn->SetResource( &m_btnres );
return TRUE;
}
return FALSE;
}


//free CSkinButton instances
void CSkinTestDlg::OnDestroy()
{
CDialog::OnDestroy();

// TODO: Add your message handler code here
POSITION pos;
pos = m_wndList.GetHeadPosition();
while( pos )
{
CObject *ob = m_wndList.GetAt(pos);
if ( ob->GetRuntimeClass() == RUNTIME_CLASS(CSkinButton) )
{
delete (CSkinButton*)ob;
}
m_wndList.GetNext(pos);
}
}

四、历史
这是最初版本,我只在Windows XP环境中进行了测试。 我希望听到您的评论,谢谢,请自由使用这些代码...
hawkman2k 2003-09-27
  • 打赏
  • 举报
回复
bluebohe(薄荷) 说的应该是BCG ControlBAR,到网上搜吧,很多!
lekuaile 2003-09-27
  • 打赏
  • 举报
回复
是免费的吗?
lekuaile 2003-09-27
  • 打赏
  • 举报
回复
没找到在哪里下载?能否指点一下
bluebohe 2003-09-27
  • 打赏
  • 举报
回复
使用BCGControl BAR向导可以,BCGControl BAR能从网上下载
milson 2003-09-27
  • 打赏
  • 举报
回复
这个建议你研究一下CBCGLIB德源码

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧