commands.cpp
来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,435 行 · 第 1/4 页
CPP
1,435 行
#endif const CComBSTR sharedLib(sharedLibText + CString(" $(QTDIR)\\lib\\qtmain.lib")); const CComBSTR defLibs( "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib" ); const CComBSTR sysLibs( "kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib imm32.lib wsock32.lib winspool.lib winmm.lib" ); CComBSTR threadLib; CComBSTR correctLib; CComBSTR configname; pConfig->get_Name(&configname); CString config = (CString)configname; if ( config.Right(5) == "Debug" ) { threadLib = "/MLd"; correctLib = "/MDd"; } else { threadLib = "/ML"; correctLib = "/MD"; } VERIFY_OK(pConfig->AddToolSettings( compiler, dllDefine, CComVariant(VARIANT_FALSE) )); if ( useThreads ) VERIFY_OK(pConfig->AddToolSettings( compiler, CComBSTR("/D QT_THREAD_SUPPORT"), CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( compiler, incPath, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( linker, defLibs, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( linker, sysLibs, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( linker, CComBSTR("$(QTDIR)\\lib\\qt-mt.lib"), CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( linker, CComBSTR("$(QTDIR)\\lib\\qt.lib"), CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( linker, sharedLib, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( compiler, threadLib, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( compiler, correctLib, CComVariant(VARIANT_FALSE) )); m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded Qt shared library") );}void CCommands::addStaticSettings( CComPtr<IConfiguration> pConfig, bool useThreads ){ const CComBSTR compiler("cl.exe"); const CComBSTR linker("link.exe"); LPCTSTR dllDefs; dllDefs = "/D QT_DLL"; const CComBSTR dllDefine( dllDefs ); const CComBSTR incPath(" /I$(QTDIR)\\include"); CComBSTR staticLib = useThreads ? "$(QTDIR)\\lib\\qt-mt.lib" : "$(QTDIR)\\lib\\qt.lib"; staticLib += CComBSTR(" $(QTDIR)\\lib\\qtmain.lib"); CString version; try { CStdioFile file( CString(_T(getenv("QTDIR")) + CString("\\.qmake.cache")), CFile::modeRead ); CString line; BOOL eof; do { eof = !file.ReadString( line ); if ( eof ) break; if ( line.Find( "QMAKE_QT_VERSION_OVERRIDE=" ) != -1 ) { version = line.Right(3); break; } } while ( !eof ); } catch ( CFileException* e ) { char err[256]; e->GetErrorMessage( (char*)&err, 255, NULL ); ::MessageBox( NULL, err, "Error", MB_OK ); } CString sharedLibText;#if defined(QT_TRIAL) if ( useThreads ) sharedLibText = CString("$(QTDIR)\\lib\\qt-mteval") + version + CString(".lib"); else sharedLibText = CString("$(QTDIR)\\lib\\qteval") + version + CString(".lib");#else if ( useThreads ) sharedLibText = CString("$(QTDIR)\\lib\\qt-mt") + version + CString(".lib"); else sharedLibText = CString("$(QTDIR)\\lib\\qt") + version + CString(".lib");#endif const CComBSTR sharedLib(sharedLibText); CComBSTR threadLib; CComBSTR correctLib; CComBSTR configname; pConfig->get_Name(&configname); CString config = (CString)configname; if ( config.Right(5) == "Debug" ) { threadLib = "/MLd"; correctLib = "/MDd"; } else { threadLib = "/ML"; correctLib = "/MD"; } const CComBSTR defLibs( "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib" ); const CComBSTR sysLibs( "kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib imm32.lib wsock32.lib winspool.lib winmm.lib" ); VERIFY_OK(pConfig->RemoveToolSettings( compiler, dllDefine, CComVariant(VARIANT_FALSE) )); if ( useThreads ) VERIFY_OK(pConfig->AddToolSettings( compiler, CComBSTR("/D QT_THREAD_SUPPORT"), CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( compiler, incPath, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( linker, defLibs, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( linker, sysLibs, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( linker, sharedLib, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( linker, staticLib, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->RemoveToolSettings( compiler, threadLib, CComVariant(VARIANT_FALSE) )); VERIFY_OK(pConfig->AddToolSettings( compiler, correctLib, CComVariant(VARIANT_FALSE) )); m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded Qt static library") );}void CCommands::addMOC( CComQIPtr<IBuildProject, &IID_IBuildProject> pProject, CString file ){ CString fileext; CString filename; CString filepath; CString inputfile; CString mocfile; CString fileToMoc; const CString moccommand = "%qtdir%\\bin\\moc.exe "; splitFileName( file, filepath, filename, fileext ); bool specialFile = FALSE; if ( !fileext.IsEmpty() && fileext[0] == 'c' ) { fileToMoc = filepath + filename + ".moc"; mocfile = filepath + filename + ".moc"; specialFile = TRUE; } else { fileToMoc = filepath + file; mocfile = filepath + "moc_"+ filename + ".cpp"; } // Add the files to the project if ( pProject->AddFile( CComBSTR(fileToMoc), CComVariant(VARIANT_TRUE) ) == S_OK ) m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded "+file) ); if ( pProject->AddFile( CComBSTR(mocfile), CComVariant(VARIANT_TRUE) ) == S_OK ) m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded "+mocfile) ); // Get the list of configurations in the active project CComQIPtr<IConfigurations, &IID_IConfigurations> pConfigs; if ( getConfigurations( pProject, pConfigs ) != S_OK ) { m_pApplication->PrintToOutputWindow( CComBSTR("FAILED TO ADD MOC!") ); return; } if ( !fileext.IsEmpty() && fileext[0] == 'c' ) { fileToMoc = filepath + filename + ".moc"; mocfile = "$(InputDir)\\$(InputName).moc"; specialFile = TRUE; } else { fileToMoc = filepath + file; mocfile = "$(InputDir)\\moc_$(InputName).cpp"; } inputfile = "$(InputDir)\\$(InputName)." + fileext; // Add the moc step to the file long cCount; VERIFY_OK( pConfigs->get_Count(&cCount)); for (long c = 0; c < cCount; c++ ) { CComVariant Varc = c+1; CComPtr<IConfiguration> pConfig; VERIFY_OK(pConfigs->Item(Varc, &pConfig)); VERIFY_OK(pConfig->AddCustomBuildStepToFile(CComBSTR(fileToMoc), CComBSTR(moccommand + inputfile + " -o " + mocfile), CComBSTR(mocfile), CComBSTR("MOCing "+file+"..."), CComVariant(VARIANT_FALSE))); m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded MOC preprocessor") ); } if ( specialFile ) {// VERIFY_OK(pConfig->AddFileDependency( CComBSTR(mocfile), CComBSTR(filepath+file))); }}void CCommands::addUIC( CComQIPtr<IBuildProject, &IID_IBuildProject> pProject, CString file ){ CString fileext; CString filename; CString filepath; splitFileName( file, filepath, filename, fileext ); const CString uiFile(filepath + file); const CString impFile(filepath + filename + ".cpp"); const CString decFile(filepath + filename + ".h"); const CString incFile( filename+".h" ); const CString mocFile(filepath + "moc_" + filename + ".cpp"); const CString uiccommand("%qtdir%\\bin\\uic.exe "); const CString moccommand("%qtdir%\\bin\\moc.exe "); // Add the file and the all output to the project if ( pProject->AddFile( CComBSTR(uiFile), CComVariant(VARIANT_TRUE) ) == S_OK ) m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded "+uiFile) ); if ( pProject->AddFile( CComBSTR(impFile), CComVariant(VARIANT_TRUE) ) == S_OK ) m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded "+impFile) ); if (pProject->AddFile( CComBSTR(decFile), CComVariant(VARIANT_TRUE) ) == S_OK ) m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded "+decFile) ); if (pProject->AddFile( CComBSTR(mocFile), CComVariant(VARIANT_TRUE) ) == S_OK ) m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded "+mocFile) ); // Get the list of configurations in the active project CComQIPtr<IConfigurations, &IID_IConfigurations> pConfigs; if ( getConfigurations( pProject, pConfigs ) != S_OK ) { m_pApplication->PrintToOutputWindow( CComBSTR("FAILED TO ADD UIC!") ); } // Add the moc step to the file long cCount; VERIFY_OK( pConfigs->get_Count(&cCount)); for (long c = 0; c < cCount; c++ ) { CComVariant Varc = c+1; CComPtr<IConfiguration> pConfig; VERIFY_OK(pConfigs->Item(Varc, &pConfig)); CComBSTR command = uiccommand+"$(InputPath) -o $(InputDir)\\$(InputName).h\n" + uiccommand+"$(InputPath) -i $(InputName).h -o $(InputDir)\\$(InputName).cpp\n" + moccommand+"$(InputDir)\\$(InputName).h -o $(InputDir)\\moc_$(InputName).cpp"; CComBSTR output = "$(InputDir)\\$(InputName).h\n$(InputDir)\\$(InputName).cpp\n$(InputDir)\\moc_$(InputName).cpp"; VERIFY_OK(pConfig->AddCustomBuildStepToFile(CComBSTR(uiFile), command, output, CComBSTR("UICing "+file+"..."), CComVariant(VARIANT_FALSE))); m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded UIC preprocessor step") ); }}CString CCommands::replaceTemplateStrings( const CString& t, const CString& classheader, const CString& classname, const CString& instance, const CString& instcall, const CString& projekt, const CString& runapp){ CString r = t; r.Replace( "$QMSDEVCLASSHEADER", classheader ); r.Replace( "$QMSDEVCLASSNAME", classname ); r.Replace( "$QMSDEVINSTANCE", instance ); r.Replace( "$QMSDEVINSTCALL", instcall ); r.Replace( "$QMSDEVPROJECTNAME", projekt ); r.Replace( "$QMSDEVRUNAPP", runapp ); return r;}void CCommands::runDesigner( const CString &file ){ CString path; CString command; path = getenv("QTDIR"); if ( path.IsEmpty() ) { // Get the location from the registry CRegKey key; char* value = new char[256]; unsigned long length; if (key.Open(HKEY_CURRENT_USER, "Software\\Trolltech\\Qt Designer") == ERROR_SUCCESS) { length = 255; key.QueryValue( value, "PathToExe", &length ); path = value; length = 255; key.QueryValue( value, "NameOfExe", &length ); command = value; key.Close(); } else { ::MessageBox(NULL, "Can't locate Qt Designer", "Error", MB_OK | MB_ICONINFORMATION); return; } delete[] value; } else { command = "designer.exe"; path+="\\bin"; } // Run the designer with options -client and "file" if ( spawnl(_P_NOWAIT, path+"\\"+command, command, "-client", file, 0 ) == -1 ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE)); ::MessageBox(NULL, "Failed to run Qt Designer: "+command, "Start Designer", MB_OK | MB_ICONINFORMATION); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); }}void CCommands::runLinguist( const CString &file ){ CString path; CString command; path = getenv("QTDIR"); if ( path.IsEmpty() ) { // Get the location from the registry CRegKey key; char* value = new char[256]; unsigned long length; if (key.Open(HKEY_CURRENT_USER, "Software\\Trolltech\\Qt Linguist") == ERROR_SUCCESS) { length = 255; key.QueryValue( value, "PathToExe", &length ); path = value; length = 255; key.QueryValue( value, "NameOfExe", &length ); command = value; key.Close(); } else { ::MessageBox(NULL, "Can't locate Qt Linguist", "Error", MB_OK | MB_ICONINFORMATION); return; } delete[] value; } else { command = "linguist.exe"; path+="\\bin"; } // Run the linguist with option "file" if ( spawnl(_P_NOWAIT, path+"\\"+command, command, file, 0 ) == -1 ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE)); ::MessageBox(NULL, "Failed to run Qt Linguist: "+command, "Start Designer", MB_OK | MB_ICONINFORMATION); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); }}/////////////////////////////////////////////////////////////////////////////// Ccommands-MethodenSTDMETHODIMP CCommands::QMsDevStartDesigner() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString file; CString filepath; CString filename; CString fileext; // Get the active file file = getActiveFileName(); splitFileName( file, filepath, filename, fileext ); // Check if we can use the file if ( file.IsEmpty() || fileext != "ui" ) file = "NewDialog.ui"; runDesigner( filepath + file ); return S_OK;}STDMETHODIMP CCommands::QMsDevUseQt(){ AFX_MANAGE_STATE(AfxGetStaticModuleState()); m_pApplication->PrintToOutputWindow( CComBSTR("Adding Qt support to project") ); // Check for active Project CComQIPtr<IBuildProject, &IID_IBuildProject> pProject; if ( getActiveProject( pProject ) != S_OK ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE)); if ( ::MessageBox( NULL, "There is no active project.\nDo you want to create a new Qt Project?", "Use Qt in project", MB_YESNOCANCEL | MB_ICONQUESTION ) == IDYES ) QMsDevNewQtProject(); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_FALSE; } bool shared; bool threaded = getGlobalQtSettings( shared ); // Get the list of configurations in the active project CComQIPtr<IConfigurations, &IID_IConfigurations> pConfigs; if ( getConfigurations( pProject, pConfigs ) != S_OK ) return S_FALSE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?