MainFrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:11k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "ResourceEditor.h"
  22. #include "ResourceExport.h"
  23. #include "ResourceImport.h"
  24. #include "ResourceEditorDoc.h"
  25. #include "MainFrm.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMainFrame
  33. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  34. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  35. //{{AFX_MSG_MAP(CMainFrame)
  36. ON_WM_CREATE()
  37. ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
  38. ON_COMMAND(ID_FILE_CHANGELOCATION, OnFileChangelocation)
  39. //}}AFX_MSG_MAP
  40. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  41. ON_XTP_CREATECONTROL()
  42. ON_XTP_EXECUTE(ID_FILE_OPEN, OnFileOpen)
  43. ON_COMMAND(ID_FILE_IMPORT_DLL, OnFileImportDll)
  44. END_MESSAGE_MAP()
  45. static UINT indicators[] =
  46. {
  47. ID_SEPARATOR,           // status line indicator
  48. ID_INDICATOR_CAPS,
  49. ID_INDICATOR_NUM,
  50. ID_INDICATOR_SCRL,
  51. };
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMainFrame construction/destruction
  54. CMainFrame::CMainFrame()
  55. {
  56. // TODO: add member initialization code here
  57. }
  58. CMainFrame::~CMainFrame()
  59. {
  60. }
  61. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  62. {
  63. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  64. return -1;
  65. ScanResources();
  66. // Create Status bar.
  67. // Important: All control bars including the Status Bar
  68. // must be created before CommandBars....
  69. if (!m_wndStatusBar.Create(this) ||
  70. !m_wndStatusBar.SetIndicators(indicators,
  71. sizeof(indicators)/sizeof(UINT)))
  72. {
  73. TRACE0("Failed to create status barn");
  74. return -1;      // fail to create
  75. }
  76. // Initialize the command bars
  77. if (!InitCommandBars())
  78. return -1;
  79. XTPImageManager()->SetMaskColor(XTPImageManager()->GetBitmapMaskColor(IDR_MAINFRAME));
  80. CXTPImageManager::m_bAutoResample = TRUE;
  81. // Get a pointer to the command bars object.
  82. CXTPCommandBars* pCommandBars = GetCommandBars();
  83. if(pCommandBars == NULL)
  84. {
  85. TRACE0("Failed to create command bars object.n");
  86. return -1;      // fail to create
  87. }
  88. // Add the menu bar
  89. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  90. _T("Menu Bar"), IDR_MAINFRAME);
  91. if(pMenuBar == NULL)
  92. {
  93. TRACE0("Failed to create menu bar.n");
  94. return -1;      // fail to create
  95. }
  96. // Create ToolBar
  97. CXTPToolBar* pToolBar = (CXTPToolBar*)
  98. pCommandBars->Add(_T("Standard"), xtpBarTop);
  99. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  100. {
  101. TRACE0("Failed to create toolbarn");
  102. return -1;
  103. }
  104. m_MTIClientWnd.Attach(this, TRUE);
  105. // Set Office 2003 Theme
  106. CXTPPaintManager::SetTheme(xtpThemeWhidbey);
  107. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  108. m_wndPreview.Create(_T("STATIC"), 0, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, 100);
  109. // Initialize the docking pane manager and set the
  110. // initial them for the docking panes.  Do this only after all
  111. // control bars objects have been created and docked.
  112. m_paneManager.InstallDockingPanes(this);
  113. // Set Office 2003 Theme
  114. m_paneManager.SetTheme(xtpPaneThemeVisualStudio2005);
  115. // Create docking panes.
  116. m_paneManager.CreatePane(
  117. IDR_PANE_PREVIEW, CRect(0, 0, 200, 150), xtpPaneDockBottom);
  118. return 0;
  119. }
  120. void CMainFrame::ScanResources()
  121. {
  122. m_arrResources.RemoveAll();
  123. CFileFind finder;
  124. BOOL bWorking = finder.FindFile(theApp.m_strTranslatingPath + "*.xml");
  125. while (bWorking)
  126. {
  127. bWorking = finder.FindNextFile();
  128. CXTPPropExchangeXMLNode xmlNode(TRUE, 0, _T("resource"));
  129. if (xmlNode.LoadFromFile(finder.GetFilePath()))
  130. {
  131. CString strLanguage;
  132. PX_String(&xmlNode, _T("Language"), strLanguage);
  133. if (!strLanguage.IsEmpty())
  134. {
  135. CResourceInfo resInfo;
  136. resInfo.strLanguage = strLanguage;
  137. resInfo.strPath = finder.GetFilePath();
  138. int nInsert = 0;
  139. for (; nInsert < (int)m_arrResources.GetSize(); nInsert++)
  140. {
  141. if (m_arrResources[nInsert].strLanguage > strLanguage)
  142. break;
  143. }
  144. m_arrResources.InsertAt(nInsert, resInfo);
  145. }
  146. }
  147. }
  148. }
  149. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  150. {
  151. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  152. return FALSE;
  153. cs.lpszClass = _T("XTPMainFrame");
  154. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  155. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  156. return TRUE;
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CMainFrame diagnostics
  160. #ifdef _DEBUG
  161. void CMainFrame::AssertValid() const
  162. {
  163. CMDIFrameWnd::AssertValid();
  164. }
  165. void CMainFrame::Dump(CDumpContext& dc) const
  166. {
  167. CMDIFrameWnd::Dump(dc);
  168. }
  169. #endif //_DEBUG
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CMainFrame message handlers
  172. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  173. {
  174. if (wParam == XTP_DPN_SHOWWINDOW)
  175. {
  176. // get a pointer to the docking pane being shown.
  177. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  178. if (!pPane->IsValid())
  179. {
  180. pPane->Attach(&m_wndPreview);
  181. }
  182. return TRUE; // handled
  183. }
  184. return FALSE;
  185. }
  186. void CMainFrame::ShowDialogPreview(CXTPPropExchangeXMLNode* pResource, DWORD dwId)
  187. {
  188. pResource->InternalAddRef();
  189. XTPResourceManager()->SetResourceManager(new CXTPResourceManagerXML(pResource));
  190. LPCDLGTEMPLATE pTemplate = XTPResourceManager()->LoadDialogTemplate(dwId);
  191. if (pTemplate)
  192. {  
  193. m_wndPreview.ShowDialog(pTemplate);
  194. }
  195. XTPResourceManager()->SetResourceManager(new CXTPResourceManager());
  196. }
  197. void CMainFrame::ClearPreview()
  198. {
  199. m_wndPreview.ClearPreview();
  200. }
  201. void CMainFrame::ShowMenuPreview(CXTPPropExchangeXMLNode* pResource, DWORD dwId, XTP_RESOURCEMANAGER_LANGINFO* pLangInfo)
  202. {
  203. pResource->InternalAddRef();
  204. XTPResourceManager()->SetResourceManager(new CXTPResourceManagerXML(pResource));
  205. CMenu menu;
  206. if (XTPResourceManager()->LoadMenu(&menu, dwId))
  207. {
  208. m_wndPreview.ShowMenu(&menu, pLangInfo);
  209. }
  210. XTPResourceManager()->SetResourceManager(new CXTPResourceManager());
  211. }
  212. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  213. {
  214. if (lpCreateControl->bToolBar)
  215. {
  216. if (lpCreateControl->nID == ID_FILE_OPEN)
  217. {
  218. CXTPControlComboBox* pComboOpen = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  219. pComboOpen->SetWidth(150);
  220. pComboOpen->SetStyle(xtpComboLabel);
  221. lpCreateControl->pControl = pComboOpen;
  222. return TRUE;
  223. }
  224. }
  225. return FALSE;
  226. }
  227. void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI) 
  228. {
  229. CXTPControlComboBox* pControl = DYNAMIC_DOWNCAST(CXTPControlComboBox, CXTPControl::FromUI(pCmdUI));
  230. if (pControl && !pControl->HasFocus())
  231. {
  232. if (pControl->GetCount() != m_arrResources.GetSize())
  233. {
  234. pControl->ResetContent();
  235. for (int i = 0; i < m_arrResources.GetSize(); i++)
  236. {
  237. pControl->AddString(m_arrResources[i].strLanguage);
  238. }
  239. }
  240. int nCurSel = -1;
  241. CDocument* pDocument = GetActiveFrame()->GetActiveDocument();
  242. if (pDocument)
  243. {
  244. CString strPath = pDocument->GetPathName();
  245. for (int i = 0; i < m_arrResources.GetSize(); i++)
  246. {
  247. if (m_arrResources[i].strPath == strPath)
  248. {
  249. nCurSel = i;
  250. break;
  251. }
  252. }
  253. }
  254. pControl->SetCurSel(nCurSel);
  255. }
  256. }
  257. void CMainFrame::OnFileOpen(NMHDR* pNMHDR, LRESULT* pResult)
  258. {
  259. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  260. CXTPControlComboBox* pControl = DYNAMIC_DOWNCAST(CXTPControlComboBox, tagNMCONTROL->pControl);
  261. if (pControl)
  262. {
  263. int nCurSel = pControl->GetCurSel();
  264. if (nCurSel >= 0 && nCurSel < m_arrResources.GetSize())
  265. {
  266. theApp.OpenDocumentFile(m_arrResources[nCurSel].strPath);
  267. }
  268. *pResult = 1; // Handled;
  269. }
  270. }
  271. void CMainFrame::OnFileChangelocation() 
  272. {
  273. // Get the current (if any) text that is displayed in
  274. // the edit control, this will be the initial path for the
  275. // browse dialog to start from.
  276. CString strPath = theApp.m_strTranslatingPath;
  277. // Instantiate a browse for folder dialog object
  278. CXTBrowseDialog browseDlg;
  279. browseDlg.SetOwner(m_hWnd);
  280. browseDlg.SetTitle(_T("Choose translation directory"));
  281. browseDlg.SetSelPath((TCHAR*)(LPCTSTR)strPath);
  282. if( browseDlg.DoModal() == IDOK ) 
  283. {
  284. theApp.m_strTranslatingPath = browseDlg.GetSelPath();
  285. theApp.m_strTranslatingPath += _T("\");
  286. ScanResources();
  287. }
  288. }
  289. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  290. {
  291. m_paneManager.OnSetPreviewMode(bPreview);
  292. CXTPMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  293. }
  294. void CMainFrame::OnFileExportAll() 
  295. {
  296. for (int i = 0; i < m_arrResources.GetSize(); i++)
  297. {
  298. const CResourceInfo& ri = m_arrResources[i];
  299. CXTPPropExchangeXMLNode* pResources = new CXTPPropExchangeXMLNode(TRUE, 0, _T("resource"));
  300. pResources->LoadFromFile(ri.strPath);
  301. CString strOutput = ri.strPath;
  302. strOutput.Replace(_T(".xml"), _T(".rc"));
  303. CResourceExport re;
  304. re.ExportRc(pResources, strOutput);
  305. delete pResources;
  306. }
  307. }
  308. void CMainFrame::OnFileImportAll() 
  309. {
  310. CFileFind finder;
  311. BOOL bWorking = finder.FindFile(theApp.m_strTranslatingPath + _T("*.dll"));
  312. while (bWorking)
  313. {
  314. bWorking = finder.FindNextFile();
  315. CString strPath = finder.GetFilePath();
  316. CResourceImport ri;
  317. if (ri.Import(strPath))
  318. {
  319. CString strOutput = strPath;
  320. strOutput.Replace(_T(".dll"), _T(".xml"));
  321. ri.m_pResources->SaveToFile(strOutput);
  322. }
  323. }
  324. }
  325. void CMainFrame::OnFileImportDll() 
  326. {
  327. CString strFilter = _T("Executable Files (*.exe;*.dll;*.ocx)|*.dll;*.exe;*.ocx|All files (*.*)|*.*||");
  328. CFileDialog fd(TRUE, _T("dll"), NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, strFilter);
  329. if (fd.DoModal() != IDOK)
  330. return;
  331. CResourceImport ri;
  332. if (!ri.Import(fd.GetPathName()))
  333. return;
  334. POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
  335. CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(pos);
  336. CResourceEditorDoc* pDocument = (CResourceEditorDoc*)pTemplate->CreateNewDocument();
  337. CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDocument, NULL);
  338. pTemplate->SetDefaultTitle(pDocument);
  339. if (!pDocument->AssignResource(ri.m_pResources))
  340. {
  341. pFrame->DestroyWindow();
  342. return;
  343. }
  344. ri.m_bDelete = FALSE;
  345. pTemplate->InitialUpdateFrame(pFrame, pDocument, TRUE);
  346. }