SkinSelectDlg.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:6k
源码类别:

界面编程

开发平台:

Visual C++

  1. // SkinSelectDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WebGet.h"
  5. #include "SkinSelectDlg.h"
  6. #include "RTXmlFile.h"
  7. #include "RTText.h"
  8. // CSkinSelectDlg 对话框
  9. IMPLEMENT_DYNAMIC(CSkinSelectDlg, CRTDialog)
  10. CSkinSelectDlg::CSkinSelectDlg(CWnd* pParent)
  11. : CRTDialog(CSkinSelectDlg::IDD, pParent)
  12. {
  13. }
  14. CSkinSelectDlg::~CSkinSelectDlg()
  15. {
  16. }
  17. void CSkinSelectDlg::DoDataExchange(CDataExchange* pDX)
  18. {
  19. CRTDialog::DoDataExchange(pDX);
  20. DDX_Control(pDX, IDC_LIST1, m_SkinList);
  21. DDX_Control(pDX, IDOK, m_ButtonOK);
  22. DDX_Control(pDX, IDC_SkinGroup, m_SkinGroup);
  23. DDX_Control(pDX, IDC_CtrlGroup, m_ControlGroup);
  24. DDX_Control(pDX, IDC_chkSDIBorder, m_chkSDIBorder);
  25. DDX_Control(pDX, IDC_chkSDITitleBar, m_chkSDITitleBar);
  26. DDX_Control(pDX, IDC_chkDlgBack, m_chkDlgBack);
  27. DDX_Control(pDX, IDC_chkDlgBorder, m_chkDlgBorder);
  28. DDX_Control(pDX, IDC_chkDlgTitleBar, m_chkDlgTitleBar);
  29. DDX_Control(pDX, IDC_chkMenuBar, m_chkMenuBar);
  30. DDX_Control(pDX, IDCANCEL, m_ButtonCancel);
  31. }
  32. BEGIN_MESSAGE_MAP(CSkinSelectDlg, CRTDialog)
  33. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnLvnItemchangedList1)
  34. ON_BN_CLICKED(IDC_chkDlgBack, OnBnClickedchkdlgback)
  35. ON_BN_CLICKED(IDC_chkDlgBorder, OnBnClickedchkdlgborder)
  36. ON_BN_CLICKED(IDC_chkDlgTitleBar, OnBnClickedchkdlgtitlebar)
  37. ON_BN_CLICKED(IDC_chkMenuBar, OnBnClickedchkmenubar)
  38. ON_BN_CLICKED(IDC_chkSDIBorder, OnBnClickedchksdiborder)
  39. ON_BN_CLICKED(IDC_chkSDITitleBar, OnBnClickedchksdititlebar)
  40. END_MESSAGE_MAP()
  41. // CSkinSelectDlg 消息处理程序
  42. BOOL CSkinSelectDlg::OnInitDialog()
  43. {
  44. CRTDialog::OnInitDialog();
  45. m_ImgList.Create(16,16,ILC_COLOR,0,0);
  46. DWORD exStyle = m_SkinList.GetExStyle();
  47. exStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
  48. exStyle &= ~LVS_EX_CHECKBOXES;
  49. m_SkinList.SetExtendedStyle(exStyle);
  50. m_SkinList.SetImageList(&m_ImgList,LVSIL_STATE);
  51. m_SkinList.InsertColumn(0,"",LVCFMT_LEFT,0);
  52. m_SkinList.InsertColumn(1,"名称",LVCFMT_LEFT,260);
  53. m_SkinList.InsertColumn(2,"文件路径",LVCFMT_LEFT,0);
  54. int i = 0;
  55. int items = 0;
  56. items = m_SkinList.InsertItem(i++,"");
  57. m_SkinList.SetItemText(items,1,"Windows缺省");
  58. m_SkinList.SetItemText(items,2,"...");
  59. m_SkinList.SetItemData(items,(DWORD_PTR)FALSE);
  60. char AppPath[MAX_PATH];
  61. int nLen = GetModuleFileName(NULL,AppPath,MAX_PATH) - 1;
  62. while(nLen >= 0)
  63. {
  64. if(AppPath[nLen] == '\')
  65. {
  66. AppPath[nLen] = NULL;
  67. break;
  68. }
  69. nLen --;
  70. }
  71. char SkinPath[MAX_PATH];
  72. ZeroMemory(SkinPath,MAX_PATH);
  73. strcpy(SkinPath,AppPath);
  74. strcat(SkinPath,"\Skin");
  75. char SkinFind[MAX_PATH];
  76. ZeroMemory(SkinFind,MAX_PATH);
  77. strcpy(SkinFind,SkinPath);
  78. strcat(SkinFind,"\*.*");
  79. WIN32_FIND_DATA wfd;
  80. HANDLE hFind = FindFirstFile(SkinFind,&wfd);
  81. if(hFind == NULL)return TRUE;
  82. BOOL bSkinFind = FALSE;
  83. m_SkinFile = m_SkinFile.Trim();
  84. do{
  85. if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
  86. {
  87. if(wfd.cFileName[0] == '.')continue;
  88. char SkinFile[MAX_PATH];
  89. ZeroMemory(SkinFile,MAX_PATH);
  90. strcpy(SkinFile,SkinPath);
  91. strcat(SkinFile,"\");
  92. strcat(SkinFile,wfd.cFileName);
  93. strcat(SkinFile,"\skin.ini");
  94. CRTXmlFile xmlFile;
  95. if(!xmlFile.Open(SkinFile))continue;
  96. CRTXmlItem *pItem = xmlFile.GetItem("Skin");
  97. if(pItem == NULL)continue;
  98. LPCTSTR lpName = pItem->GetKeyValue("Name");
  99. if(lpName == NULL)continue;
  100. items = m_SkinList.InsertItem(i,"");
  101. m_SkinList.SetItemText(items,1,lpName);
  102. m_SkinList.SetItemText(items,2,SkinFile);
  103. m_SkinList.SetItemData(items,(DWORD_PTR)TRUE);
  104. if(bEnableSkin && CRTText::Compare(m_SkinFile,SkinFile))
  105. {
  106. bSkinFind = TRUE;
  107. m_SkinList.SetItemState(items,LVIS_SELECTED,LVIS_SELECTED);
  108. }
  109.             i++;
  110. }
  111. }while(FindNextFile(hFind,&wfd));
  112. FindClose(hFind);
  113. if(!bSkinFind)m_SkinList.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  114. if(EnableSDIBorder)m_chkSDIBorder.SetCheck(BST_CHECKED);
  115. if(EnableSDITitleBar)m_chkSDITitleBar.SetCheck(BST_CHECKED);
  116. if(EnableDLGBorder)m_chkDlgBorder.SetCheck(BST_CHECKED);
  117. if(EnableDlgBack)m_chkDlgBack.SetCheck(BST_CHECKED);
  118. if(EnableDLGTitleBar)m_chkDlgTitleBar.SetCheck(BST_CHECKED);
  119. if(EnableMenuBar)m_chkMenuBar.SetCheck(BST_CHECKED);
  120. return TRUE; 
  121. }
  122. void CSkinSelectDlg::OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult)
  123. {
  124. LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
  125. if(pNMLV->uChanged == LVIF_STATE && pNMLV->uNewState)
  126. {
  127. BOOL bEnable = (BOOL)m_SkinList.GetItemData(pNMLV->iItem);
  128. char SkinFile[MAX_PATH];
  129. int nLen = m_SkinList.GetItemText(pNMLV->iItem,2,SkinFile,MAX_PATH);
  130. SkinFile[nLen] = NULL;
  131. GetParent()->SendMessage(WM_SETSKIN,(WPARAM)bEnable,(LPARAM)SkinFile);
  132. Invalidate();
  133. SendMessage(WM_NCPAINT,1,0);
  134. if(!bEnable)
  135. {
  136. m_chkMenuBar.SetCheck(BST_UNCHECKED);
  137. OnBnClickedchkmenubar();
  138. }
  139. else
  140. {
  141. m_chkMenuBar.SetCheck(BST_CHECKED);
  142. OnBnClickedchkmenubar();
  143. }
  144. }
  145. *pResult = 0;
  146. }
  147. void CSkinSelectDlg::OnBnClickedchkdlgback()
  148. {
  149. BOOL bEnable = FALSE;
  150. if(BST_CHECKED == m_chkDlgBack.GetCheck())
  151. bEnable = TRUE;
  152. GetParent()->SendMessage(WM_SKINENABLE,IDC_chkDlgBack,bEnable);
  153. Invalidate();
  154. SendMessage(WM_NCPAINT,1,0);
  155. }
  156. void CSkinSelectDlg::OnBnClickedchkdlgborder()
  157. {
  158. BOOL bEnable = FALSE;
  159. if(BST_CHECKED == m_chkDlgBorder.GetCheck())
  160. bEnable = TRUE;
  161. GetParent()->SendMessage(WM_SKINENABLE,IDC_chkDlgBorder,bEnable);
  162. Invalidate();
  163. SendMessage(WM_NCPAINT,1,0);
  164. }
  165. void CSkinSelectDlg::OnBnClickedchkdlgtitlebar()
  166. {
  167. BOOL bEnable = FALSE;
  168. if(BST_CHECKED == m_chkDlgTitleBar.GetCheck())
  169. bEnable = TRUE;
  170. GetParent()->SendMessage(WM_SKINENABLE,IDC_chkDlgTitleBar,bEnable);
  171. Invalidate();
  172. SendMessage(WM_NCPAINT,1,0);
  173. }
  174. void CSkinSelectDlg::OnBnClickedchkmenubar()
  175. {
  176. BOOL bEnable = FALSE;
  177. if(BST_CHECKED == m_chkMenuBar.GetCheck())
  178. bEnable = TRUE;
  179. GetParent()->SendMessage(WM_SKINENABLE,IDC_chkMenuBar,bEnable);
  180. Invalidate();
  181. SendMessage(WM_NCPAINT,1,0);
  182. }
  183. void CSkinSelectDlg::OnBnClickedchksdiborder()
  184. {
  185. BOOL bEnable = FALSE;
  186. if(BST_CHECKED == m_chkSDIBorder.GetCheck())
  187. bEnable = TRUE;
  188. GetParent()->SendMessage(WM_SKINENABLE,IDC_chkSDIBorder,bEnable);
  189. Invalidate();
  190. SendMessage(WM_NCPAINT,1,0);
  191. }
  192. void CSkinSelectDlg::OnBnClickedchksdititlebar()
  193. {
  194. BOOL bEnable = FALSE;
  195. if(BST_CHECKED == m_chkSDITitleBar.GetCheck())
  196. bEnable = TRUE;
  197. GetParent()->SendMessage(WM_SKINENABLE,IDC_chkSDITitleBar,bEnable);
  198. Invalidate();
  199. SendMessage(WM_NCPAINT,1,0);
  200. }