GameOptionPanel.cpp
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 9k
Development Platform:

C/C++

  1. // GameOptionPanel.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "autoupdate.h"
  5. #include "GameOptionPanel.h"
  6. #include "../UPDATEDLL/src/UpdateExport.h"
  7. #include "../engine/Src/KWin32.h"
  8. #include "../engine/Src/KIniFile.h"
  9. #include "../engine/Src/KFilePath.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // GameOptionPanel dialog
  17. const string FullScreenSectorName = "FullScreen";
  18. const string RepresentSectorName  = "Represent";
  19. const string DynaLightSectorName  = "DynamicLight";
  20. const string FullScreenMode    = FullScreenSectorName + "=1";
  21. const string WindowScreenMode  = FullScreenSectorName + "=0";
  22. const string Represent2DMode   = RepresentSectorName + "=2";
  23. const string Represent3DMode   = RepresentSectorName + "=3";
  24. const string DynaLightMode     = DynaLightSectorName + "=1";
  25. const string NotDynaLightMode  = DynaLightSectorName + "=0";
  26. const string ConfileFileName   =  "config.ini";
  27. const string Represent3DModuleFileName ="Represent3.dll";
  28. const string Check_Represent_FunctionName = FN_REPRESENT_IS_MODULE_RECOMMENDED;
  29. const string MessageTitle = "JxoinlineOption";
  30. GameOptionPanel::GameOptionPanel(CWnd* pParent /*=NULL*/)
  31. : CDialog(GameOptionPanel::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(GameOptionPanel)
  34. m_2DOptionValue = -1;
  35. m_FullScreenValue = -1;
  36. m_DynaLightEnableValue = FALSE;
  37. m_txtCapPath = _T("");
  38. //}}AFX_DATA_INIT
  39. }
  40. void GameOptionPanel::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(GameOptionPanel)
  44. DDX_Control(pDX, IDC_WindowOption, m_WindowOptionCtl);
  45. DDX_Control(pDX, IDC_3DOption, m_3DOptionCtl);
  46. DDX_Control(pDX, IDC_FullScreen, m_FullScreenCtl);
  47. DDX_Control(pDX, IDC_2DOption, m_2DOptionCtl);
  48. DDX_Control(pDX, IDC_DynaLightEnable, m_DynaLightEnableCtl);
  49. DDX_Radio(pDX, IDC_2DOption, m_2DOptionValue);
  50. DDX_Radio(pDX, IDC_FullScreen, m_FullScreenValue);
  51. DDX_Check(pDX, IDC_DynaLightEnable, m_DynaLightEnableValue);
  52. DDX_Text(pDX, IDC_TXT_CAPPATH, m_txtCapPath);
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(GameOptionPanel, CDialog)
  56. //{{AFX_MSG_MAP(GameOptionPanel)
  57. ON_BN_CLICKED(IDC_OK, OnOk)
  58. ON_BN_CLICKED(IDC_3DOption, On3DOptionSelected)
  59. ON_BN_CLICKED(IDC_2DOption, On2DOption)
  60. ON_WM_DESTROY()
  61. ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
  62. ON_BN_CLICKED(IDC_CANCEL, OnCancel)
  63. ON_BN_CLICKED(IDC_BTN_CAPPATH, OnBtnCappath)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. // GameOptionPanel message handlers
  68. void GameOptionPanel::OnOk() 
  69. {
  70. // TODO: Add your control notification handler code here
  71. UpdateData();
  72. try
  73. {
  74. //写入config.ini文件
  75. char aConfigPath[MAX_PATH] ={0};
  76. g_GetRootPath(aConfigPath);
  77. strcat(aConfigPath, "\");
  78. strcat(aConfigPath, ConfileFileName.c_str());
  79. char aCapPath[MAX_PATH] = {0};
  80. if (m_txtCapPath == "")
  81. g_GetRootPath(aCapPath);
  82. else
  83. strcpy(aCapPath, m_txtCapPath.GetBuffer(1));
  84. WritePrivateProfileString("Client","CapPath",aCapPath, aConfigPath);
  85. if (m_2DOptionCtl.GetCheck())
  86. {
  87. WritePrivateProfileString("Client","Represent","2", aConfigPath);
  88. WritePrivateProfileString("Client","DynamicLight","0", aConfigPath); 
  89. }
  90. else
  91. {
  92. WritePrivateProfileString("Client","Represent","3", aConfigPath);
  93. if (m_DynaLightEnableCtl.GetCheck())
  94. WritePrivateProfileString("Client","DynamicLight","1", aConfigPath);
  95. else
  96. WritePrivateProfileString("Client","DynamicLight","0", aConfigPath);
  97. }
  98. if (m_FullScreenCtl.GetCheck())
  99. WritePrivateProfileString("Client","FullScreen","1", aConfigPath);
  100. else
  101. WritePrivateProfileString("Client","FullScreen","0", aConfigPath);
  102. CDialog::OnOK();
  103. }
  104. catch(exception Error)
  105. {
  106. MessageBox(Error.what(),MessageTitle.c_str(),MB_ICONERROR);
  107. }
  108. }
  109. void GameOptionPanel::OnCancel() 
  110. {
  111. // TODO: Add your control notification handler code here
  112. CDialog::OnCancel();
  113. }
  114. void GameOptionPanel::On3DOptionSelected() 
  115. {
  116. // TODO: Add your control notification handler code here
  117. m_DynaLightEnableCtl.EnableWindow();
  118. }
  119. void GameOptionPanel::On2DOption() 
  120. {
  121. // TODO: Add your control notification handler code here
  122. m_DynaLightEnableCtl.EnableWindow(FALSE);
  123. m_DynaLightEnableCtl.SetCheck(0);
  124. }
  125. BOOL GameOptionPanel::OnInitDialog() 
  126. {
  127. CDialog::OnInitDialog();
  128. // TODO: Add extra initialization here
  129.     
  130. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  131. if(m_hIcon != NULL)
  132. {
  133. SetIcon(m_hIcon,FALSE);
  134. SetIcon(m_hIcon, TRUE);
  135. }
  136. else
  137. {
  138. DisplayErrorInfo(string("LoadIcon(IDR_MAINFRAME) 出错") );
  139. }
  140. //读取config.ini文件
  141. char aConfigPath[MAX_PATH] ={0};
  142. g_GetRootPath(aConfigPath);
  143. strcat(aConfigPath, "\");
  144. strcat(aConfigPath, ConfileFileName.c_str());
  145. char aCapPath[MAX_PATH] = {0};
  146. GetPrivateProfileString("Client","CapPath","",aCapPath, MAX_PATH, aConfigPath);
  147. if (aCapPath[0] == '')
  148. g_GetRootPath(aCapPath);
  149. m_txtCapPath = aCapPath;
  150. UpdateData(false);
  151. int nRepresentValue = GetPrivateProfileInt("Client","Represent", 3, aConfigPath);
  152. if( nRepresentValue == 2 )
  153. {
  154. m_2DOptionCtl.SetCheck(1);
  155. m_3DOptionCtl.SetCheck(0);
  156. m_DynaLightEnableCtl.SetCheck(0);
  157. m_DynaLightEnableCtl.EnableWindow(false);
  158. }
  159. else
  160. {
  161. m_2DOptionCtl.SetCheck(0);
  162. m_3DOptionCtl.SetCheck(1);
  163. m_DynaLightEnableCtl.EnableWindow();
  164. int nDynamicLight = GetPrivateProfileInt("Client","DynamicLight", 1, aConfigPath);
  165. if (nDynamicLight == 0)
  166. m_DynaLightEnableCtl.SetCheck(0);
  167. else
  168. m_DynaLightEnableCtl.SetCheck(1);
  169. }
  170. int nFullScreenValue = GetPrivateProfileInt("Client","FullScreen", 1, aConfigPath);
  171. if (nFullScreenValue == 0)
  172. {
  173. m_FullScreenCtl.SetCheck(0);
  174. m_WindowOptionCtl.SetCheck(1);
  175. }
  176. else
  177. {
  178. m_FullScreenCtl.SetCheck(1);
  179. m_WindowOptionCtl.SetCheck(0);
  180. }
  181. return TRUE;  // return TRUE unless you set the focus to a control
  182. // EXCEPTION: OCX Property Pages should return FALSE
  183. }
  184. void GameOptionPanel::OnDestroy() 
  185. {
  186. CDialog::OnDestroy();
  187. // TODO: Add your message handler code here
  188. DeleteObject(m_hIcon);
  189. }
  190. void GameOptionPanel::OnDefault() 
  191. {
  192. try
  193. {
  194. HMODULE Represent3DModule  = LoadLibrary(Represent3DModuleFileName.c_str());
  195. if(Represent3DModule == NULL)
  196. {
  197. string ErrorInfo = string("调入动态库'") +Represent3DModuleFileName + string("'出错");
  198. throw exception (ErrorInfo.c_str());
  199. }
  200. fnRepresentIsModuleRecommended Check_Represent; 
  201. Check_Represent =(fnRepresentIsModuleRecommended) GetProcAddress(Represent3DModule,Check_Represent_FunctionName.c_str());
  202. if(Check_Represent == NULL)
  203. {
  204. FreeLibrary(Represent3DModule);
  205. string ErrorInfo = string("取得函数地址'") +Check_Represent_FunctionName + string("'出错");
  206. throw exception (ErrorInfo.c_str());
  207. }
  208. char aCapPath[MAX_PATH] = {0};
  209. g_GetRootPath(aCapPath);
  210. m_txtCapPath = aCapPath;
  211. UpdateData(false);
  212. if((Check_Represent)())
  213. {
  214. m_2DOptionCtl.SetCheck(0);
  215. m_3DOptionCtl.SetCheck(1);
  216. m_DynaLightEnableCtl.SetCheck(1);
  217. m_DynaLightEnableCtl.EnableWindow();
  218. }
  219. else
  220. {
  221. m_2DOptionCtl.SetCheck(1);
  222. m_3DOptionCtl.SetCheck(0);
  223. m_DynaLightEnableCtl.SetCheck(0);
  224. m_DynaLightEnableCtl.EnableWindow(false);
  225. }
  226. m_FullScreenCtl.SetCheck(1);
  227. m_WindowOptionCtl.SetCheck(0);
  228. if(!FreeLibrary(Represent3DModule))
  229. {
  230. string ErrorInfo = string("释放模块'") +Represent3DModuleFileName + string("'出错");
  231. throw exception (ErrorInfo.c_str());
  232. }
  233. }
  234. catch(exception& Error)
  235. {
  236. DisplayErrorInfo(string(Error.what()));
  237. CDialog::OnCancel();
  238. }
  239. }
  240. void GameOptionPanel::OnBtnCappath() 
  241. {
  242. UpdateData();
  243. LPITEMIDLIST pidlRoot=NULL; 
  244. SHGetSpecialFolderLocation(m_hWnd,CSIDL_DESKTOP,&pidlRoot); 
  245. BROWSEINFO bi;   //必须传入的参数,下面就是这个结构的参数的初始化 
  246. //CString strDisplayName;   //用来得到,你选择的活页夹路径,相当于提供一个缓冲区 
  247. bi.hwndOwner=GetSafeHwnd();   //得到父窗口Handle值 
  248. bi.pidlRoot=pidlRoot;   //这个变量就是我们在上面得到的. 
  249. bi.pszDisplayName=NULL;//strDisplayName.GetBuffer(MAX_PATH+1);   //得到缓冲区指针, 
  250. bi.lpszTitle="浏览文件夹";   //设置标题 
  251. bi.ulFlags=0;   //设置标志 
  252. bi.lpfn=NULL; 
  253. bi.lParam=0; 
  254. bi.iImage=0;   //上面这个是一些无关的参数的设置,最好设置起来, 
  255. LPITEMIDLIST pIIL =SHBrowseForFolder(&bi);   //打开对话框 
  256. if(pIIL == NULL)return;
  257. //strDisplayName.ReleaseBuffer();   //和上面的GetBuffer()相对应 
  258. TCHAR szInitialDir[MAX_PATH];
  259. BOOL bRet = ::SHGetPathFromIDList(pIIL, (char*)&szInitialDir);
  260. m_txtCapPath = szInitialDir;
  261. UpdateData(false);
  262. }