⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commands.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    const CComBSTR correctLibR("/MD");    VERIFY_OK(pConfig->AddToolSettings( compiler, dllDefine, 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, staticLib, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->AddToolSettings( linker, sharedLib, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->RemoveToolSettings( compiler, threadLibD, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->AddToolSettings( compiler, correctLibD, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->RemoveToolSettings( compiler, threadLibR, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->AddToolSettings( compiler, correctLibR, CComVariant(VARIANT_FALSE) ));    m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded Qt shared library") );}void CCommands::addStaticSettings( CComPtr<IConfiguration> pConfig ){    CString libname;    bool useThreads = getGlobalSettings( libname );        const CComBSTR compiler("cl.exe");    const CComBSTR linker("link.exe");    LPCTSTR dllDefs;    if ( useThreads )	dllDefs = "/D QT_DLL /D QT_THREAD_SUPPORT";    else	dllDefs = "/D QT_DLL";    const CComBSTR dllDefine( dllDefs );	    const CComBSTR incPath(" /I$(QTDIR)\\include");    const CComBSTR staticLib("$(QTDIR)\\lib\\qt.lib");    CString sharedLibText = CString("$(QTDIR)\\lib\\") + libname;    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" );    VERIFY_OK(pConfig->RemoveToolSettings( compiler, dllDefine, 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) ));    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 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";    }    // 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+"$(InputDir)\\$(InputName)."+fileext+" -o "+mocfile), 					  CComBSTR(mocfile), CComBSTR("Moc'ing $(InputName)."+fileext+" ..."), 					  CComVariant(VARIANT_FALSE)));	m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded MOC preprocessor") );    }    // CANTDO: add dependency to .moc-file    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 uic 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("Uic'ing $(InputName).ui ..."), 	    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 designer location from the registry	CRegKey key;	char* value = new char[256];	unsigned long length;	if (key.Open(HKEY_CURRENT_USER, "Software\\Trolltech\\Qt\\Qt GUI 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 GUI 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 GUI Designer: "+command, 			   "Start Designer", MB_OK | MB_ICONINFORMATION);	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    } else {	m_pApplication->PrintToOutputWindow( CComBSTR("Qt Designer started...") );    }}/////////////////////////////////////////////////////////////////////////////// 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 )	return S_FALSE;    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));    int result = ::MessageBox(NULL, "Do you want to use Qt in a shared library?", "Question", MB_YESNOCANCEL | MB_ICONQUESTION );    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    if ( result == IDCANCEL )	return S_OK;    // TODO:Get the highest qt library version in $(QTDIR)\lib    // Get the list of configurations in the active project    CComQIPtr<IConfigurations, &IID_IConfigurations> pConfigs;    if ( getConfigurations( pProject, pConfigs ) != S_OK )	return S_FALSE;    // Add the specific settings to compiler and linker        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));	if ( result == IDYES )	    addSharedSettings( pConfig );	else	    addStaticSettings( pConfig );    }    return S_OK;    m_pApplication->PrintToOutputWindow( CComBSTR("Finished!\n") );}STDMETHODIMP CCommands::QMsDevAddMOCStep(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));    // Check for active Project    CComQIPtr<IBuildProject, &IID_IBuildProject> pProject;    if ( getActiveProject( pProject ) != S_OK ) {	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));	::MessageBox(NULL, "Can't find an active project!", "QMsDev", MB_OK | MB_ICONINFORMATION );	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_FALSE;    }    CString file;    CString fileext;    CString filename;    CString filepath;    file = getActiveFileName();    if ( file.IsEmpty() ) {	CFileDialog fd( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 	    "Header files (*.h; *.hxx; *.hpp)|*.h; *.hxx; *.hpp|"	    "Implementation files (*.c; *.cpp; *.cxx)|*.c; *.cpp; *.cxx|"	    "C++ files (*.h; *.hxx; *.hpp; *.c; *.cpp; *.cxx)|*.h; *.hxx; *.hpp; *.c; *.cpp; *.cxx|"	    "All Files (*.*)|*.*||", NULL);	int result = fd.DoModal();        	if ( result == IDCANCEL ) {	    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	    return S_OK;	}	file = fd.GetPathName();    }    splitFileName( file, filepath, filename, fileext );    m_pApplication->PrintToOutputWindow( CComBSTR("Add MOC buildstep for "+file+"...") );    addMOC( pProject, filepath+file );    m_pApplication->PrintToOutputWindow( CComBSTR("Finished!\n") );        VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    return S_OK;}STDMETHODIMP CCommands::QMsDevAddUICStep(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));    CString file;    CString fileext;    CString filename;    CString filepath;    // Check for active Project    CComQIPtr<IBuildProject, &IID_IBuildProject> pProject;    if ( getActiveProject( pProject ) != S_OK ) {	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));	::MessageBox(NULL, "Can't find an active project!", "QMsDev", MB_OK | MB_ICONINFORMATION );	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_FALSE;    }    file = getActiveFileName();    splitFileName( file, filepath, filename, fileext );    if ( file.IsEmpty() || fileext != "ui" ) {	CFileDialog fd( TRUE, NULL, NULL, OFN_HIDEREADONLY, 	    "User Interface File (*.ui)|*.ui|"	    "All Files (*.*)|*.*||", NULL);	int result = fd.DoModal();	if ( result == IDCANCEL ) {	    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	    return S_OK;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -