www.pudn.com > c02 vc6.rar > C02IDE.cpp
// C02IDE.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "C02IDE.h" #include "MainFrm.h" #include "C02IDEDoc.h" #include "C02IDEView.h" #include "ChildFrm.h" #include#include "WorkspaceView.h" #include "KSFileDialog.h" #include "editcmd.h" #include "ProjectNew.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //CRichEditCtrl myeditctrl; int i_usermode=0; int i_newblankfile=0; AddFunc * functionadd=NULL; // CObArray * proinfstru=NULL; CObArray projectinfo; CObArray oa_error; // CObArray projectfile; FileList * m_pfile=NULL; fileitem fileitemarray[30]; // AddFunc *functionadd=NULL; CObArray a_searchinfo; //保存搜索信息 // int idxcurwnd=0; int n_filenumber=0; int n_funcnumber=0; int allcanshunum=0; int addcanshunum=0; // CObArray a_searchinfo; CTabFileDoc* m_pDocFile=NULL; CTabClassDoc* m_pDocClass=NULL; int gotoline=0; CString findstring; int findstringcurhang; int findstringcurlie; cursel curselpos; int m_nItem=0; int m_nSubItem=0; CMapPtrToPtr m_mappro; ///////////////////////////////////////////////////////////////////////////// // CC02IDEApp BEGIN_MESSAGE_MAP(CC02IDEApp, CWinApp) //{{AFX_MSG_MAP(CC02IDEApp) ON_COMMAND(ID_FILE_NEWPRO,OnProjectNew) ON_COMMAND(ID_FILE_NEW, OnFileNew) ON_COMMAND(ID_FILE_NEWC02,OnFileNewC02) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_COMMAND(ID_FILE_SAVE_ALL, OnFileSaveAll) ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateFileMruFile1) ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFileEx) //}}AFX_MSG_MAP // Standard file based document commands // ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) // Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CC02IDEApp construction CC02IDEApp::CC02IDEApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_pMainFrame = NULL; } ///////////////////////////////////////////////////////////////////////////// // The one and only CC02IDEApp object CC02IDEApp theApp; ///////////////////////////////////////////////////////////////////////////// // CC02IDEApp initialization BOOL CC02IDEApp::InitInstance() { // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("CodeJockey")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. m_pDocTemplate = new CMultiDocTemplate( IDR_C02IDETYPE, RUNTIME_CLASS(CC02IDEDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CC02IDEView)); m_pDocTemplate->SetContainerInfo(IDR_C02IDETYPE_CNTR_IP); AddDocTemplate(m_pDocTemplate); /* m_pDocWorkspTemplate = new CMultiDocTemplate( IDR_C02IDE_VITYPE, RUNTIME_CLASS(CC02IDEDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CWorkspaceView)); AddDocTemplate(m_pDocWorkspTemplate); */ // create main MDI Frame window m_pMainFrame = new CMainFrame; if (!m_pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = m_pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); // pMainFrame->ShowWindow(m_nCmdShow); // pMainFrame->UpdateWindow(); struct ProjectList * firstpro=NULL; firstpro=new ProjectList; firstpro->str_projectname="project1"; firstpro->proinfstru.RemoveAll(); // projectinfo.RemoveAll(); projectinfo.InsertAt(0,(CObject*)firstpro); // projectfile.InsertAt(0,(CObject*)firstpro); // gotofuncname=""; gotoline=0; findstring=""; findstringcurhang=0; findstringcurlie=-1; curselpos.n_min=0; curselpos.n_max=0; _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: void UpdateFont(); CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA CFont m_Font; // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) virtual BOOL OnInitDialog(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) // m_C02IDEDisclaimer = _T(""); //}}AFX_DATA_INIT // m_C02IDEDisclaimer.LoadString(IDS_DISCLAIMER); // UpdateFont(); } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) // DDX_Control(pDX, IDC_STATIC_MAILME, m_staticEmail); // DDX_Control(pDX, IDC_STATIC_DISCLAIMER, m_staticDisclaimer); // DDX_Control(pDX, IDC_STATIC_ADDRESS, m_staticAddress); // DDX_Text(pDX, IDC_C02IDE_DISCLAIMER, m_C02IDEDisclaimer); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CAboutDlg::UpdateFont() { /* NONCLIENTMETRICS ncm; memset(&ncm, 0, sizeof(NONCLIENTMETRICS)); ncm.cbSize = sizeof(NONCLIENTMETRICS); VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)); ncm.lfMessageFont.lfWeight = 700; m_Font.CreateFontIndirect(&ncm.lfMessageFont); */ } BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); // set the hyperlinks and static font. // m_staticEmail.SetURL(_T("mailto:kstowell@codejockeys.com")); // m_staticAddress.SetURL(_T("http://www.codejockeys.com/kstowell/")); // m_staticDisclaimer.SetFont(&m_Font); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } ///////////////////////////////////////////////////////////////////////////// // App command to run the dialog void CC02IDEApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CC02IDEApp commands void CC02IDEApp::OnFileNew() { // m_pDocTemplate->OpenDocumentFile(NULL); gotoline=0; findstring=""; findstringcurhang=0; findstringcurlie=-1; // strreplacewith=""; CWinApp::OnFileNew(); CCJMDIFrameWnd *pFrame = (CCJMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CCJMDIChildWnd *pChild = (CCJMDIChildWnd *) pFrame->GetActiveFrame(); FileList * m_pnewfile; m_pnewfile=new FileList; TCHAR* ch_wndtitle=NULL; int n=pChild->GetWindowText(ch_wndtitle,100); m_pnewfile->m_pChildWnd= pChild; ProjectList *curpro; curpro=new ProjectList; curpro=(ProjectList*)(projectinfo.GetAt(0)); int n_file=curpro->proinfstru.GetSize(); CString str_newfilename=_T(""); if(n!=0) m_pnewfile->str_filename=ch_wndtitle; else { i_newblankfile++; str_newfilename.Format("%d",i_newblankfile);//n_file str_newfilename="new file "+str_newfilename; m_pnewfile->str_filename=str_newfilename; pChild->SetWindowText(str_newfilename); // pChild->SetWindowText(str_newfilename); } curpro->proinfstru.Add((CObject *)m_pnewfile); // CObArray curproob; projectinfo.RemoveAll(); projectinfo.InsertAt(0,(CObject *)curpro); m_pnewfile->str_proname=_T("1"); m_mappro.SetAt(pChild->GetSafeHwnd(),(void*&)m_pnewfile); m_pDocFile->UpdateTabView(); m_pDocClass->UpdateTabView(); CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; m_pfile=m_pnewfile; m_pmainFrame->updatecomfile(); } void CC02IDEApp::OnFileOpen() { CString Filter; Filter = "All Source files (*.c, *.cpp, *.h *.hpp, " " *.rc,*.txt)|*.c;*.cpp;*.h;*.hpp;*.rc;*.txt|"; Filter += "All Files (*.*)|*.*|"; Filter += "Header Files (*.h;*.hpp)|*.h;*.hpp|"; Filter += "Source Files (*.c;*.cpp)|*.c;*.cpp|"; Filter += "Resource Files (*.rc)|*.rc|"; Filter += "Text Files (*.txt)|*.txt|"; CFileDialog fd(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, Filter); m_bAutoReturn = AfxGetApp()->GetProfileInt(_T("C02IDE Settings"), _T("Auto Return"), TRUE); // CFileDialog fd(TRUE); if(fd.DoModal()==IDCANCEL) return; ProjectList *curpro; curpro=new ProjectList; curpro=(ProjectList*)(projectinfo.GetAt(0)); CC02IDEApp *pApp = (CC02IDEApp *)AfxGetApp(); pApp->OpenDocumentFile(fd.m_ofn.lpstrFile); //用MFC的方法建立一个新视 gotoline=0; findstring=""; findstringcurhang=0; findstringcurlie=-1; // strreplacewith=""; CCJMDIFrameWnd *m_pFrame = (CCJMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CCJMDIChildWnd *m_pChild = (CCJMDIChildWnd *) m_pFrame->GetActiveFrame(); FileList * m_pnewfile; m_pnewfile=new FileList; int n_file=curpro->proinfstru.GetSize(); //声明文件节点 struct fileitem m_pcurnode; for (int j=0;j<=n_file-1;j++) { //取得文件节点信息的第j个项 m_pcurnode=fileitemarray[j]; //如果节点的窗口指针等于当前活动窗口指针 if(m_pcurnode.m_pchildf==m_pChild) return ; } TCHAR* ch_wndtitle=NULL; CString str_newfilename=_T(""); m_pChild->GetWindowText(str_newfilename); //(ch_wndtitle; m_pnewfile->m_pChildWnd= m_pChild; // m_pnewfile->funcinfstru=NULL; if(str_newfilename!=_T("")) m_pnewfile->str_filename=str_newfilename; else { str_newfilename.Format("%d",n_file); str_newfilename="no title file"+str_newfilename; m_pnewfile->str_filename=str_newfilename; // pChild->SetWindowText(str_newfilename); } curpro->proinfstru.Add((CObject *)m_pnewfile); projectinfo.RemoveAll(); projectinfo.InsertAt(0,(CObject *)curpro); m_pnewfile->str_proname=_T("1"); m_mappro.SetAt(m_pChild->GetSafeHwnd(),(void*&)m_pnewfile); // projectfile.InsertAt(0,(CObject*)curpro); m_pDocClass->UpdateTabView(); m_pDocFile->UpdateTabView(); CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; // CWorkspaceView* m_ptab=(CWorkspaceView*)m_pmainFrame->m_wndWorkspace; m_pfile=m_pnewfile; m_pmainFrame->updatecomfile(); } /* void CC02IDEApp::OnFileSaveAs() { CString Filter; Filter = "All Source files (*.c, *.cpp, *.h *.hpp, " " *.rc)|*.c;*.cpp;*.h;*.hpp;*.rc|"; Filter += "Header Files (*.h;*.hpp)|*.h;*.hpp|"; Filter += "Source Files (*.c;*.cpp)|*.c;*.cpp|"; Filter += "Resource Files (*.rc)|*.rc|"; Filter += "Text Files (*.txt)|*.txt|"; Filter += "All Files (*.*)|*.*||"; CFileDialog cfd(false, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, Filter); if (cfd.DoModal () == IDCANCEL) return; // GetDocument()->OnSaveDocument (cfd.m_ofn.lpstrFile); // GetDocument()->SetPathName(cfd.m_ofn.lpstrFile, TRUE); } */ void CC02IDEApp::OnFilePrintSetup() { CPageSetupDialog psd; if (psd.DoModal () == IDCANCEL) return; CString strDev = psd.GetDeviceName (); HANDLE hPrinter; DWORD dwBytesNeeded, dwBytesReturned; TCHAR szDev[128]; strcpy (szDev, (LPCSTR) strDev); OpenPrinter (szDev, &hPrinter, NULL); GetPrinter(hPrinter, 2, NULL, 0, &dwBytesNeeded); PRINTER_INFO_2 *pInfo2 = (PRINTER_INFO_2*)GlobalAlloc(GPTR, dwBytesNeeded); if (GetPrinter(hPrinter, 2, (BYTE *)pInfo2, dwBytesNeeded, &dwBytesReturned) == 0) { GlobalFree(pInfo2); ClosePrinter(hPrinter); return; } pInfo2->pDevMode = psd.GetDevMode (); DWORD dwResult = SetPrinter (hPrinter, 2, (BYTE *) pInfo2, 0); if (!dwResult) { TCHAR Message[256]; dwResult = GetLastError (); if (dwResult == 5) strcpy (Message,_T("Access to printer denied")); else sprintf (Message, "Error %d setting printer", dwResult); AfxMessageBox (Message, MB_OK); } ClosePrinter (hPrinter); } void CC02IDEApp::OnFileSaveAll() { // TODO: Add your command handler code here POSITION pos = GetFirstDocTemplatePosition (); ASSERT (pos); CDocTemplate *pDocTempl = GetNextDocTemplate (pos); pos = pDocTempl->GetFirstDocPosition (); while (pos) { CC02IDEDoc *pDoc = (CC02IDEDoc*) pDocTempl->GetNextDoc (pos); ASSERT (pDoc); CString sDocPath = pDoc->GetPathName (); if (pDoc->IsModified ()) pDoc->DoSave (sDocPath); } } int CC02IDEApp::ExitInstance() { _CrtDumpMemoryLeaks(); // TODO: Add your specialized code here and/or call the base class m_mappro.RemoveAll(); return CWinApp::ExitInstance(); } void CC02IDEApp::OnUpdateFileMruFile1(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if (pCmdUI->m_pSubMenu!=NULL) { return; } CWinApp::OnUpdateRecentFileMenu(pCmdUI); return; } BOOL CC02IDEApp::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate) { CKSFileDialog dlgFile(bOpenFileDialog); dlgFile.SetAppPointer(this); dlgFile.SetStringFilter("Edit Files(*.edt)|*.edt|Rich Text Format(*.rtf)|*.rtf|Text File(*.txt)|*.txt|All Files(*.*)|*.*"); dlgFile.SetMyParent(AfxGetMainWnd()); return dlgFile.DoPromptFileName(fileName,nIDSTitle,lFlags,bOpenFileDialog, pTemplate); } void CC02IDEApp::OnFileNewC02() { OnFileNew(); CString str_FileName = _T("ExampleC02.txt"); CFileException fileException; CStdioFile myFile; if(!myFile.Open(str_FileName,CFile::modeRead|CFile::typeText)) return; // myFile.Write( szBuffer, sizeof( szBuffer ) ); // myFile.Seek( 0, CFile::begin ); CCJMDIFrameWnd *pFrame = (CCJMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CCJMDIChildWnd *pChild = (CCJMDIChildWnd *) pFrame->GetActiveFrame(); CString str_get=_T(""); //获得当前活动视图 CCrystalEditView* m_pexpandview=NULL; m_pexpandview=(CCrystalEditView*)pChild->GetActiveView(); BOOL m_bend=TRUE; // CRichEditView *pView = (CRichEditView *)pChild->GetActiveView(); // CRichEditCtrl& m_pctrl=pView->GetRichEditCtrl(); CPoint ptCursorPos; do { m_bend=myFile.ReadString(str_get); str_get= str_get+_T("\r\n"); // str_get=szBuffer; // VERIFY(m_pexpandview->ReplaceSelection(str_get)); ptCursorPos = m_pexpandview->GetCursorPos(); int x,y; m_pexpandview->m_pTextBuffer->InsertText(m_pexpandview, ptCursorPos.y, ptCursorPos.x, str_get, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; m_pexpandview->SetSelection(ptCursorPos, ptCursorPos); m_pexpandview->SetAnchor(ptCursorPos); m_pexpandview->SetCursorPos(ptCursorPos); m_pexpandview->EnsureVisible(ptCursorPos); //m_pexpandview->getrich // m_pexpandview->ReplaceSelection(str_get); }while(m_bend!=NULL); myFile.Close(); // m_bAutoMenuEnable=FALSE; } BOOL CC02IDEApp::OnOpenRecentFileEx(UINT nID) { CWinApp::OnOpenRecentFile( nID); ProjectList *curpro; curpro=new ProjectList; curpro=(ProjectList*)(projectinfo.GetAt(0)); gotoline=0; findstring=""; findstringcurhang=0; findstringcurlie=-1; // strreplacewith=""; CCJMDIFrameWnd *m_pFrame = (CCJMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CCJMDIChildWnd *m_pChild = (CCJMDIChildWnd *) m_pFrame->GetActiveFrame(); FileList * m_pnewfile; m_pnewfile=new FileList; int n_file=curpro->proinfstru.GetSize(); //声明文件节点 struct fileitem m_pcurnode; for (int j=0;j<=n_file-1;j++) { //取得文件节点信息的第j个项 m_pcurnode=fileitemarray[j]; //如果节点的窗口指针等于当前活动窗口指针 if(m_pcurnode.m_pchildf==m_pChild) return TRUE; } TCHAR* ch_wndtitle=NULL; CString str_newfilename=_T(""); m_pChild->GetWindowText(str_newfilename); //(ch_wndtitle; m_pnewfile->m_pChildWnd= m_pChild; // m_pnewfile->funcinfstru=NULL; if(str_newfilename!=_T("")) m_pnewfile->str_filename=str_newfilename; else { str_newfilename.Format("%d",n_file); str_newfilename="no title file";//+str_newfilename; m_pnewfile->str_filename=str_newfilename; // pChild->SetWindowText(str_newfilename); } curpro->proinfstru.Add((CObject *)m_pnewfile); projectinfo.RemoveAll(); projectinfo.InsertAt(0,(CObject *)curpro); m_pnewfile->str_proname=_T("1"); m_mappro.SetAt(m_pChild->GetSafeHwnd(),(void*&)m_pnewfile); // projectfile.InsertAt(0,(CObject*)curpro); m_pDocClass->UpdateTabView(); m_pDocFile->UpdateTabView(); CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; // CWorkspaceView* m_ptab=(CWorkspaceView*)m_pmainFrame->m_wndWorkspace; m_pfile=m_pnewfile; m_pmainFrame->updatecomfile(); return TRUE; } void CC02IDEApp::OnProjectNew() { CProjectNew * p_newpro; p_newpro=new CProjectNew; p_newpro->Create(IDD_DIALOGPROJECT); p_newpro->ShowWindow(SW_SHOW); }