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

界面编程

开发平台:

Visual C++

  1. // MainFrm.cpp : CMainFrame 类的实现
  2. //
  3. #include "stdafx.h"
  4. #include "WebGet.h"
  5. #include "RTMenu.h"
  6. #include "MainFrm.h"
  7. #include "RTSplitterWnd.h"
  8. #include "SkinSelectDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // CMainFrame
  13. IMPLEMENT_DYNAMIC(CMainFrame, CRTFrameWnd)
  14. BEGIN_MESSAGE_MAP(CMainFrame, CRTFrameWnd)
  15. ON_WM_CREATE()
  16. ON_WM_SETFOCUS()
  17. ON_MENUXP_MESSAGES()
  18. ON_NOTIFY(TCN_SELCHANGE,IDC_TabTaskMgr,OnTabTaskMgrSelChange)
  19. ON_COMMAND(ID_SkinSetting, OnShowSelectSkinDlg)
  20. ON_MESSAGE(WM_SETSKIN,OnSelectedSkin)
  21. ON_MESSAGE(WM_SKINENABLE,OnEnableSkin)
  22. END_MESSAGE_MAP()
  23. static UINT indicators[] =
  24. {
  25. ID_SEPARATOR      // 状态行指示器
  26. };
  27. // CMainFrame 构造/销毁
  28. CMainFrame::CMainFrame()
  29. {
  30. EnableSkin = FALSE;
  31. EnableSDITitleBar = TRUE;
  32. EnableSDIBorder = TRUE;
  33. EnableDLGTitleBar = TRUE;
  34. EnableDLGBorder = TRUE;
  35. EnableDlgBack = TRUE;
  36. EnableMenuBar = TRUE;
  37. }
  38. CMainFrame::~CMainFrame()
  39. {
  40. if(m_hVerCursor != NULL)DestroyCursor(m_hVerCursor);
  41. if(m_hHorCursor != NULL)DestroyCursor(m_hHorCursor);
  42. }
  43. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  44. {
  45. if (CRTFrameWnd::OnCreate(lpCreateStruct) == -1)
  46. return -1;
  47. //LoadCursor for class CRTSplitterWnd
  48. ICONINFO ii;
  49. ii.fIcon = FALSE;
  50. ii.hbmMask = LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_SP_VER_MASK));
  51. ii.hbmColor= LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_SP_VER_CUR));
  52. ii.xHotspot = 9;
  53. ii.yHotspot = 8;
  54. m_hVerCursor = (HCURSOR)CreateIconIndirect(&ii);
  55. DeleteObject(ii.hbmColor);
  56. DeleteObject(ii.hbmMask);
  57. ii.fIcon = FALSE;
  58. ii.hbmMask = LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_SP_HOR_MASK));
  59. ii.hbmColor= LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_SP_HOR_CUR));
  60. ii.xHotspot = 8;
  61. ii.yHotspot = 8;
  62. m_hHorCursor = (HCURSOR)CreateIconIndirect(&ii);
  63. DeleteObject(ii.hbmColor);
  64. DeleteObject(ii.hbmMask);
  65. CRTSplitterWnd::RTSetCursor(m_hVerCursor,m_hHorCursor);
  66. //load skin setting
  67. LoadSkin();
  68. UseSkin(EnableSkin);
  69. if (!m_ToolBarFileDown.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | CBRS_TOP
  70.  | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  71.  !m_ToolBarFileDown.LoadToolBar(IDR_TOOLBARFILEDOWN))
  72. {
  73. TRACE0("未能创建工具栏1n");
  74. return -1;      // 未能创建
  75. }
  76. if (!m_ToolBarWebDown.CreateEx(this, TBSTYLE_FLAT, WS_CHILD  | CBRS_TOP
  77.  | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  78.  !m_ToolBarWebDown.LoadToolBar(IDR_TOOLBARWEBDOWN))
  79. {
  80. TRACE0("未能创建工具栏2n");
  81. return -1;      // 未能创建
  82. }
  83. if (!m_ToolBarWebMgr.CreateEx(this, TBSTYLE_FLAT, WS_CHILD |CBRS_TOP
  84.  | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  85.  !m_ToolBarWebMgr.LoadToolBar(IDR_TOOLBARWEBMGR))
  86. {
  87. TRACE0("未能创建工具栏3n");
  88. return -1;      // 未能创建
  89. }
  90. if (!m_wndStatusBar.Create(this) ||
  91. !m_wndStatusBar.SetIndicators(indicators,
  92.   sizeof(indicators)/sizeof(UINT)))
  93. {
  94. TRACE0("未能创建状态栏n");
  95. return -1;      // 未能创建
  96. }
  97. CRTMenu::SetXPLookNFeel(this);
  98. CRTMenu::SetXPLookNFeel(this,::GetSystemMenu(m_hWnd,FALSE));
  99. m_Splitter.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,AFX_IDW_PANE_FIRST);
  100. m_LeftForm.Create(CLeftForm::IDD,&m_Splitter);
  101. m_RightForm.Create(CRightForm::IDD,&m_Splitter);
  102. m_LeftForm.m_RightForm = &m_RightForm;
  103. m_RightForm.m_LeftForm = &m_LeftForm;
  104. m_Splitter.SetVertical(&m_LeftForm,&m_RightForm);
  105. m_ToolBarFileDown.ShowWindow(SW_SHOW);
  106. m_bAutoMenuEnable = FALSE;
  107. return 0;
  108. }
  109. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  110. {
  111. if( !CRTFrameWnd::PreCreateWindow(cs) )
  112. return FALSE;
  113. // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
  114. // 样式
  115. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  116. cs.lpszClass = AfxRegisterWndClass(0);
  117. return TRUE;
  118. }
  119. // CMainFrame 诊断
  120. #ifdef _DEBUG
  121. void CMainFrame::AssertValid() const
  122. {
  123. CFrameWnd::AssertValid();
  124. }
  125. void CMainFrame::Dump(CDumpContext& dc) const
  126. {
  127. CFrameWnd::Dump(dc);
  128. }
  129. #endif //_DEBUG
  130. // CMainFrame 消息处理程序
  131. void CMainFrame::OnSetFocus(CWnd* /*pOldWnd*/)
  132. {
  133. }
  134. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  135. {
  136. // 否则,执行默认处理
  137. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  138. }
  139. void CMainFrame::UseSkin(BOOL IsEnable)
  140. {
  141. m_Skin.UseSkin(IsEnable);
  142. EnableSkin = IsEnable;
  143. CRTFrameWnd::EnableSkin(IsEnable,EnableSDIBorder,EnableSDITitleBar);
  144. CRTDialog::EnableSkin(IsEnable,EnableDLGBorder,EnableDlgBack,EnableDLGTitleBar);
  145. CRTMenu::EnableSkin(EnableMenuBar);
  146. }
  147. BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle , CWnd* pParentWnd , CCreateContext* pContext)
  148. {
  149. if(!CRTFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
  150. return FALSE;
  151. CRTMenu::UpdateMenuBar(this);
  152. return TRUE;
  153. }
  154. void CMainFrame::OnUpdateFrameMenu(HMENU hMenuAlt)
  155. {
  156. CRTFrameWnd::OnUpdateFrameMenu(hMenuAlt);
  157. CRTMenu::UpdateMenuBar(this);
  158. }
  159. BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  160. {
  161. return CRTFrameWnd::OnNotify(wParam, lParam, pResult);
  162. }
  163. afx_msg void CMainFrame::OnTabTaskMgrSelChange(NMHDR *pNMHDR, LRESULT *pResult)
  164. {
  165. int sel = TabCtrl_GetCurSel(pNMHDR->hwndFrom);
  166. if(sel == 0)
  167. {
  168. m_ToolBarFileDown.ShowWindow(SW_SHOW);
  169. m_ToolBarWebDown.ShowWindow(SW_HIDE);
  170. m_ToolBarWebMgr.ShowWindow(SW_HIDE);
  171. }
  172. else if(sel == 1)
  173. {
  174. m_ToolBarFileDown.ShowWindow(SW_HIDE);
  175. m_ToolBarWebDown.ShowWindow(SW_SHOW);
  176. m_ToolBarWebMgr.ShowWindow(SW_HIDE);
  177. }
  178. else
  179. {
  180. m_ToolBarFileDown.ShowWindow(SW_HIDE);
  181. m_ToolBarWebDown.ShowWindow(SW_HIDE);
  182. m_ToolBarWebMgr.ShowWindow(SW_SHOW);
  183. }
  184. RecalcLayout();
  185. }
  186. void CMainFrame::OnShowSelectSkinDlg()
  187. {
  188. CSkinSelectDlg dlgSkin(this);
  189. dlgSkin.EnableSDIBorder = EnableSDIBorder;
  190. dlgSkin.EnableSDITitleBar = EnableSDITitleBar;
  191. dlgSkin.EnableDLGBorder = EnableDLGBorder;
  192. dlgSkin.EnableDlgBack = EnableDlgBack;
  193. dlgSkin.EnableDLGTitleBar = EnableDLGTitleBar;
  194. dlgSkin.EnableMenuBar = EnableMenuBar;
  195. dlgSkin.m_SkinFile = SkinFile;
  196. dlgSkin.bEnableSkin = EnableSkin;
  197. if(IDOK == dlgSkin.DoModal())
  198. {
  199. strcpy(SkinFile,dlgSkin.m_SkinFile);
  200. SaveSkin();
  201. }
  202. else
  203. {
  204. LoadSkin();
  205. Invalidate();
  206. SendMessage(WM_NCPAINT,1,0);
  207. }
  208. }
  209. LRESULT CMainFrame::OnSelectedSkin(WPARAM wParam,LPARAM lParam)
  210. {
  211. UseSkin((BOOL)wParam);
  212. if(((BOOL)wParam))
  213. {
  214. LPCTSTR lpSkinFile = (LPCTSTR)lParam;
  215. strcpy(SkinFile,lpSkinFile);
  216. m_Skin.Load(lpSkinFile);
  217. }
  218. else
  219. {
  220. strcpy(SkinFile,"...");
  221. }
  222. Invalidate();
  223. SendMessage(WM_NCPAINT,1,0);
  224. return 0;
  225. }
  226. void CMainFrame::LoadSkin(void)
  227. {
  228. //Load skin.ini
  229. char path[MAX_PATH];
  230. ZeroMemory(path,MAX_PATH);
  231. char AppPath[MAX_PATH];
  232. ZeroMemory(AppPath,MAX_PATH);
  233. int nlen = GetModuleFileName(NULL,AppPath,MAX_PATH);
  234. while(nlen > 0)
  235. {
  236. if(AppPath[nlen] == '\')
  237. {
  238. AppPath[nlen] = NULL;
  239. break;
  240. }
  241. else
  242. {
  243. AppPath[nlen] = NULL;
  244. }
  245. nlen --;
  246. }
  247. ZeroMemory(path,MAX_PATH);
  248. strcpy(path,AppPath);
  249. strcat(path,"\skin.ini");
  250. m_SkinFile.Open(path);
  251. //sin setting
  252. CRTXmlItem* pItem = m_SkinFile.GetItem("Skin");
  253.     if(pItem != NULL)
  254. {
  255. EnableSkin = pItem->GetKeyValueBool("UseSkin");
  256. LPCTSTR lpSkinFile = pItem->GetKeyValue("SkinFile");
  257. if(lpSkinFile != NULL)
  258. {
  259. m_Skin.Load(lpSkinFile);
  260. strcpy(SkinFile,lpSkinFile);
  261. }
  262. }
  263. else
  264. {
  265. pItem = new CRTXmlItem("Skin");
  266. m_SkinFile.AddItem(pItem);
  267. }
  268. pItem = m_SkinFile.GetItem("SDI");
  269. if(pItem != NULL)
  270. {
  271. EnableSDIBorder = pItem->GetKeyValueBool("Border");
  272. EnableSDITitleBar=pItem->GetKeyValueBool("TitleBar");
  273. }
  274. else
  275. {
  276. pItem = new CRTXmlItem("SDI");
  277. m_SkinFile.AddItem(pItem);
  278. }
  279. pItem = m_SkinFile.GetItem("Dialog");
  280. if(pItem != NULL)
  281. {
  282. EnableDLGBorder = pItem->GetKeyValueBool("Border");
  283. EnableDLGTitleBar=pItem->GetKeyValueBool("TitleBar");
  284. EnableDlgBack   = pItem->GetKeyValueBool("Back");
  285. }
  286. else
  287. {
  288. pItem = new CRTXmlItem("Dialog");
  289. m_SkinFile.AddItem(pItem);
  290. }
  291. pItem = m_SkinFile.GetItem("Menu");
  292. if(pItem != NULL)
  293. {
  294. EnableMenuBar = pItem->GetKeyValueBool("Enable");
  295. }
  296. else
  297. {
  298. pItem = new CRTXmlItem("Menu");
  299. m_SkinFile.AddItem(pItem);
  300. }
  301. //set skin
  302. UseSkin(EnableSkin);
  303. }
  304. void CMainFrame::SaveSkin(void)
  305. {
  306. CRTXmlItem* pItem = m_SkinFile.GetItem("Skin");
  307.     if(pItem != NULL)
  308. {
  309. pItem->SetKeyValue("UseSkin",(DWORD)EnableSkin);
  310. pItem->SetKeyValue("SkinFile",SkinFile);
  311. }
  312. pItem = m_SkinFile.GetItem("SDI");
  313. if(pItem != NULL)
  314. {
  315. pItem->SetKeyValue("Border",(BOOL)EnableSDIBorder);
  316. pItem->SetKeyValue("TitleBar",(BOOL)EnableSDITitleBar);
  317. }
  318. pItem = m_SkinFile.GetItem("Dialog");
  319. if(pItem != NULL)
  320. {
  321. pItem->SetKeyValue("Border",(BOOL)EnableDLGBorder);
  322. pItem->SetKeyValue("TitleBar",(BOOL)EnableDLGTitleBar);
  323. pItem->SetKeyValue("Back",(BOOL)EnableDlgBack);
  324. }
  325. pItem = m_SkinFile.GetItem("Menu");
  326. if(pItem != NULL)
  327. {
  328. pItem->SetKeyValue("Enable",(BOOL)EnableMenuBar);
  329. }
  330. m_SkinFile.Save();
  331. }
  332. LRESULT CMainFrame::OnEnableSkin(WPARAM wParam,LPARAM lParam)
  333. {
  334. switch(wParam)
  335. {
  336. case IDC_chkDlgBack:
  337. EnableDlgBack = (BOOL)lParam;
  338. break;
  339. case IDC_chkDlgBorder:
  340. EnableDLGBorder = (BOOL)lParam;
  341. break;
  342. case IDC_chkDlgTitleBar:
  343. EnableDLGTitleBar = (BOOL)lParam;
  344. break;
  345. case IDC_chkSDIBorder:
  346. EnableSDIBorder = (BOOL)lParam;
  347. break;
  348. case IDC_chkSDITitleBar:
  349. EnableSDITitleBar = (BOOL)lParam;
  350. break;
  351. case IDC_chkMenuBar:
  352. EnableMenuBar = (BOOL)lParam;
  353. break;
  354. }
  355. UseSkin(EnableSkin);
  356. Invalidate();
  357. SendMessage(WM_NCPAINT,1,0);
  358. return 0;
  359. }