SkinTestDlg.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // SkinTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SkinTest.h"
  5. #include "SkinTestDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. class CAboutDlg : public CDialog
  13. {
  14. public:
  15. CAboutDlg();
  16. // Dialog Data
  17. //{{AFX_DATA(CAboutDlg)
  18. enum { IDD = IDD_ABOUTBOX };
  19. //}}AFX_DATA
  20. // ClassWizard generated virtual function overrides
  21. //{{AFX_VIRTUAL(CAboutDlg)
  22. protected:
  23. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  24. //}}AFX_VIRTUAL
  25. // Implementation
  26. protected:
  27. //{{AFX_MSG(CAboutDlg)
  28. //}}AFX_MSG
  29. DECLARE_MESSAGE_MAP()
  30. };
  31. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  32. {
  33. //{{AFX_DATA_INIT(CAboutDlg)
  34. //}}AFX_DATA_INIT
  35. }
  36. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CAboutDlg)
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  43. //{{AFX_MSG_MAP(CAboutDlg)
  44. // No message handlers
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CSkinTestDlg dialog
  49. CSkinTestDlg::CSkinTestDlg(CWnd* pParent /*=NULL*/)
  50. : CDialog(CSkinTestDlg::IDD, pParent)
  51. {
  52. //{{AFX_DATA_INIT(CSkinTestDlg)
  53. // NOTE: the ClassWizard will add member initialization here
  54. //}}AFX_DATA_INIT
  55. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  56. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  57. }
  58. void CSkinTestDlg::DoDataExchange(CDataExchange* pDX)
  59. {
  60. CDialog::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CSkinTestDlg)
  62. // NOTE: the ClassWizard will add DDX and DDV calls here
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CSkinTestDlg, CDialog)
  66. //{{AFX_MSG_MAP(CSkinTestDlg)
  67. ON_WM_SYSCOMMAND()
  68. ON_WM_PAINT()
  69. ON_WM_QUERYDRAGICON()
  70. ON_WM_DESTROY()
  71. ON_BN_CLICKED(IDC_NEOSYTLE, OnNeosytle)
  72. ON_BN_CLICKED(IDC_XPSTYLE, OnXpstyle)
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CSkinTestDlg message handlers
  77. BOOL CSkinTestDlg::OnInitDialog()
  78. {
  79. CDialog::OnInitDialog();
  80. // Add "About..." menu item to system menu.
  81. // IDM_ABOUTBOX must be in the system command range.
  82. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  83. ASSERT(IDM_ABOUTBOX < 0xF000);
  84. CMenu* pSysMenu = GetSystemMenu(FALSE);
  85. if (pSysMenu != NULL)
  86. {
  87. CString strAboutMenu;
  88. strAboutMenu.LoadString(IDS_ABOUTBOX);
  89. if (!strAboutMenu.IsEmpty())
  90. {
  91. pSysMenu->AppendMenu(MF_SEPARATOR);
  92. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  93. }
  94. }
  95. // Set the icon for this dialog. The framework does this automatically
  96. // when the application's main window is not a dialog
  97. SetIcon(m_hIcon, TRUE); // Set big icon
  98. SetIcon(m_hIcon, FALSE); // Set small icon
  99. // TODO: Add extra initialization here
  100. m_bFirst = TRUE;
  101. SetSkin( "skin\\neostyle\\theme.ini" );
  102. return TRUE; // return TRUE unless you set the focus to a control
  103. }
  104. void CSkinTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  105. {
  106. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  107. {
  108. CAboutDlg dlgAbout;
  109. dlgAbout.DoModal();
  110. }
  111. else
  112. {
  113. CDialog::OnSysCommand(nID, lParam);
  114. }
  115. }
  116. // If you add a minimize button to your dialog, you will need the code below
  117. // to draw the icon. For MFC applications using the document/view model,
  118. // this is automatically done for you by the framework.
  119. void CSkinTestDlg::OnPaint()
  120. {
  121. if (IsIconic())
  122. {
  123. CPaintDC dc(this); // device context for painting
  124. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  125. // Center icon in client rectangle
  126. int cxIcon = GetSystemMetrics(SM_CXICON);
  127. int cyIcon = GetSystemMetrics(SM_CYICON);
  128. CRect rect;
  129. GetClientRect(&rect);
  130. int x = (rect.Width() - cxIcon + 1) / 2;
  131. int y = (rect.Height() - cyIcon + 1) / 2;
  132. // Draw the icon
  133. dc.DrawIcon(x, y, m_hIcon);
  134. }
  135. else
  136. {
  137. CDialog::OnPaint();
  138. }
  139. }
  140. // The system calls this to obtain the cursor to display while the user drags
  141. // the minimized window.
  142. HCURSOR CSkinTestDlg::OnQueryDragIcon()
  143. {
  144. return (HCURSOR) m_hIcon;
  145. }
  146. #define GetWindowStyle(hwnd) ((DWORD)GetWindowLong(hwnd, GWL_STYLE))
  147. BOOL CALLBACK EnumChildProc( HWND hwnd, // handle to child window
  148. LPARAM lParam // application-defined value
  149. )
  150. {
  151. char classname[200];
  152. CSkinTestDlg *dlg = (CSkinTestDlg *)lParam;
  153. DWORD style;
  154. GetClassName( hwnd, classname, 200 );
  155. style = GetWindowStyle( hwnd );
  156. if ( strcmp( classname, "Button" ) == 0 )
  157. {
  158. style = (UINT)GetWindowLong(hwnd, GWL_STYLE) & 0xff;
  159. if ( style == BS_PUSHBUTTON || style == BS_DEFPUSHBUTTON )
  160. dlg->SubClassButton( hwnd );
  161. }
  162. return TRUE;
  163. }
  164. BOOL CSkinTestDlg::SubClassButton( HWND hwnd )
  165. {
  166. CSkinButton * btn = new CSkinButton();
  167. CWnd* pWnd = CWnd::FromHandlePermanent(hwnd);
  168. if ( pWnd == NULL)
  169. {
  170. btn->SubclassWindow( hwnd );
  171. btn->SetResource( &m_btnres );
  172. return TRUE;
  173. }
  174. return FALSE;
  175. }
  176. BOOL CSkinTestDlg::SetSkin(CString file)
  177. {
  178. m_skinWin.LoadSkin( file );
  179. m_btnres.LoadSkin( file );
  180. if ( m_bFirst )
  181. {
  182. m_skinWin.InstallSkin( this );
  183. EnumChildWindows( m_hWnd, EnumChildProc, (LPARAM)this );
  184. m_bFirst = FALSE;
  185. }
  186. SetWindowPos( 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED );
  187. return TRUE;
  188. }
  189. void CSkinTestDlg::OnDestroy()
  190. {
  191. CDialog::OnDestroy();
  192. // TODO: Add your message handler code here
  193. POSITION pos;
  194. pos = m_wndList.GetHeadPosition();
  195. while( pos )
  196. {
  197. CObject *ob = m_wndList.GetAt(pos);
  198. if ( ob->GetRuntimeClass() == RUNTIME_CLASS(CSkinButton) )
  199. {
  200. delete (CSkinButton*)ob;
  201. }
  202. m_wndList.GetNext(pos);
  203. }
  204. }
  205. void CSkinTestDlg::OnNeosytle()
  206. {
  207. // TODO: Add your control notification handler code here
  208. SetSkin( "skin\\neostyle\\theme.ini" );
  209. }
  210. void CSkinTestDlg::OnXpstyle()
  211. {
  212. // TODO: Add your control notification handler code here
  213. SetSkin( "skin\\xpstyle\\theme.ini" );
  214. }