开发学院软件开发VC 支持换肤功能的窗口实例 阅读

支持换肤功能的窗口实例

 2010-06-04 20:39:37 来源:WEB开发网   
核心提示:三、用法这些代码的用法很直接,我包含了一个MFC基于窗口的工程,支持换肤功能的窗口实例(2),关键代码列在下面,顺便提一下,我只在Windows XP环境中进行了测试,我希望听到您的评论,这些代码在单文档的工程里也测试通过了,//defines the following member in the dialog cl

三、用法

这些代码的用法很直接。我包含了一个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环境中进行了测试。我希望听到您的评论,谢谢,请自由使用这些代码...

上一页  1 2 

Tags:支持 功能 窗口

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接