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

📄 commands.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// Commands.cpp : Implementierungsdatei//#include "stdafx.h"#include <afxdlgs.h>#include "QMsDev.h"#include "Commands.h"#include "newqtprojectdialog.h"#include "qmsdevtemplates.h"#include <direct.h>#include <process.h>#include <windows.h>#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifstatic bool dontOpen = FALSE;/////////////////////////////////////////////////////////////////////////////// CCommandsCCommands::CCommands(){    m_pApplication = NULL;    m_pApplicationEventsObj = NULL;    m_pDebuggerEventsObj = NULL;}CCommands::~CCommands(){    ASSERT (m_pApplication != NULL);    m_pApplication->Release();}void CCommands::SetApplicationObject(IApplication* pApplication){    // Diese Funktion geht davon aus, dass AddRef bereits auf pApplication angewendet wurde,    //  was CDSAddIn durch den Aufruf von QueryInterface direkt vor dem Aufruf dieser    //  Funktion bereits erledigt hat.    m_pApplication = pApplication;    // Ereignis-Handler f黵 Anwendung erzeugen    XApplicationEventsObj::CreateInstance(&m_pApplicationEventsObj);    m_pApplicationEventsObj->AddRef();    m_pApplicationEventsObj->Connect(m_pApplication);    m_pApplicationEventsObj->m_pCommands = this;    // Ereignis-Handler f黵 Debugger erzeugen    CComPtr<IDispatch> pDebugger;    if (SUCCEEDED(m_pApplication->get_Debugger(&pDebugger)) 	    && pDebugger != NULL)    {	XDebuggerEventsObj::CreateInstance(&m_pDebuggerEventsObj);	m_pDebuggerEventsObj->AddRef();	m_pDebuggerEventsObj->Connect(pDebugger);	m_pDebuggerEventsObj->m_pCommands = this;    }}void CCommands::UnadviseFromEvents(){    ASSERT (m_pApplicationEventsObj != NULL);    m_pApplicationEventsObj->Disconnect(m_pApplication);    m_pApplicationEventsObj->Release();    m_pApplicationEventsObj = NULL;    if (m_pDebuggerEventsObj != NULL)    {	// Da wir die Verbindung zu den Debugger-Ereignissen herstellen konnten, 	//  sollte es auch m鰃lich sein, erneut auf das Debugger-Objekt zuzugreifen, 	//  um die Verbindung zu seinen Ereignissen zu trennen (daher das VERIFY_OK weiter unten -- siehe stdafx.h).	CComPtr<IDispatch> pDebugger;	VERIFY_OK(m_pApplication->get_Debugger(&pDebugger));	ASSERT (pDebugger != NULL);	m_pDebuggerEventsObj->Disconnect(pDebugger);	m_pDebuggerEventsObj->Release();	m_pDebuggerEventsObj = NULL;    }}/////////////////////////////////////////////////////////////////////////////// Ereignis-Handler// ZU ERLEDIGEN: F黮len Sie die Implementierung f黵 die Ereignisse aus, die Sie behandeln wollen//  Verwenden Sie m_pCommands->GetApplicationObject(), um auf das Objekt//  "Developer Studio Application" zuzugreifen//Application-EreignisseHRESULT CCommands::XApplicationEvents::BeforeBuildStart(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::BuildFinish(long nNumErrors, long nNumWarnings){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::BeforeApplicationShutDown(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::DocumentOpen(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    dontOpen = TRUE;    if ( !theDocument )	return S_OK;    CComQIPtr<ITextDocument, &IID_ITextDocument> pText(theDocument);    if ( pText ) {	CString file;	CString filepath;	CString filename;	CString fileext;	CComBSTR bszStr;	pText->get_FullName(&bszStr);	file = bszStr;    	m_pCommands->splitFileName( file, filepath, filename, fileext );	if ( fileext == "ui" ) {	    DsSaveStatus saved;	    pText->Close( CComVariant(dsSaveChangesNo), &saved );	    m_pCommands->runDesigner( filepath + file );	}    }    return S_OK;}HRESULT CCommands::XApplicationEvents::BeforeDocumentClose(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    dontOpen = TRUE;    return S_OK;}HRESULT CCommands::XApplicationEvents::DocumentSave(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::NewDocument(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::WindowActivate(IDispatch* theWindow){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    // only run designer if it was intended    if ( dontOpen ) {	dontOpen = FALSE;	return S_OK;    }        CComQIPtr<IGenericWindow, &IID_IGenericWindow> pGenericWindow(theWindow);    if ( !pGenericWindow )	return S_OK;    BSTR type;    pGenericWindow->get_Type( &type );    if ( CString(type) != "Text" )	return S_OK;    CComPtr<IDispatch> pDocument;    pGenericWindow->get_Parent(&pDocument);    CComQIPtr<ITextDocument, &IID_ITextDocument> pTextDocument(pDocument);    if ( pTextDocument ) {	CString file;	CString filepath;	CString filename;	CString fileext;	CComBSTR bszStr;	pTextDocument->get_FullName(&bszStr);	file = bszStr;	m_pCommands->splitFileName( file, filepath, filename, fileext );	if ( fileext == "ui" )	    m_pCommands->runDesigner( filepath + file );    }    return S_OK;}HRESULT CCommands::XApplicationEvents::WindowDeactivate(IDispatch* theWindow){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::WorkspaceOpen(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::WorkspaceClose(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::NewWorkspace(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}// Debugger-EreignisHRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch* pBreakpoint){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}/////////////////////////////////////////////////////////////////////////////// Little helpersCString CCommands::getActiveFileName(){    CString file;    CComPtr<IDispatch> pActiveDocument;    m_pApplication->get_ActiveDocument(&pActiveDocument);    if (pActiveDocument) {	CComQIPtr<ITextDocument, &IID_ITextDocument> pText(pActiveDocument);	if ( pText ) {	    CComBSTR bszStr;	    pText->get_FullName(&bszStr);	    file = bszStr;	}    }    return file;}void CCommands::splitFileName( CString &file, CString &filepath, CString &filetitle, CString &fileext ){    // cut file into filepath and file    int pathpos = file.ReverseFind( '\\' );    if ( pathpos != -1 ) {	filepath = file.Left( pathpos +1 );	file = file.Mid(pathpos + 1);    }    // cut file into filetitle and fileext (without dot)    int extpos = file.ReverseFind( '.' );    if ( extpos != -1 ) {	filetitle = file.Left( extpos );	fileext = file.Mid( extpos + 1 );	    }}int CCommands::getActiveProject(CComQIPtr<IBuildProject, &IID_IBuildProject>& project ){    CComPtr<IDispatch> pDispProject;    m_pApplication->get_ActiveProject(&pDispProject);    project = CComQIPtr<IBuildProject, &IID_IBuildProject>(pDispProject);    if ( !project ) {	m_pApplication->PrintToOutputWindow( CComBSTR("NO ACTIVE PROJECT FOUND") );	return S_FALSE;    }    return S_OK;}int CCommands::getConfigurations(CComQIPtr<IBuildProject, &IID_IBuildProject> project, CComQIPtr<IConfigurations, &IID_IConfigurations>& configs ){    project->get_Configurations( &configs );    if ( !configs ) {	m_pApplication->PrintToOutputWindow( CComBSTR("NO CONFIGURATIONS IN THIS PROJECT") );	return S_FALSE;    }    return S_OK;}bool CCommands::getGlobalSettings( CString &libname ){    CFileFind qtLib;    CString qtFile = "";    CString qtThread = "";    CString filever = "";    CString threadver = "";    CString libver;    BOOL bWorking = qtLib.FindFile( _T(getenv("QTDIR") + CString("\\lib\\qt*.lib" ) ) );    bool useThreads;    while ( bWorking ) {	bWorking = qtLib.FindNextFile();	if ( !bWorking ) 	    break;	if ( (LPCTSTR)qtLib.GetFileName().Left(5).Compare( "qt-mt" )==0 ) {	    qtThread = (LPCTSTR)qtLib.GetFileName();	    threadver = qtThread.Mid( 5, 3 );	} else if ( !(qtLib.GetFileName().Compare( "qtmain.lib" ) == 0) ) {	    qtFile = (LPCTSTR)qtLib.GetFileName();	    filever = qtFile.Mid( 2, 3 );	}		if ( threadver.Compare( filever ) > 0 && threadver.Compare( libver ) > 0 ) {	    libname = qtThread;	    libver = threadver;	    useThreads = TRUE;	} else if ( threadver.Compare( filever ) < 0 && filever.Compare( libver ) > 0 ) {	    libname = qtFile;	    libver = filever;	    useThreads = FALSE;	} else if ( threadver.Compare( filever ) == 0 && !(qtThread.Right(6).Compare("nc.lib")==0) && threadver.Compare( libver ) > 0 ) {	    libname = qtThread;	    libver = threadver;	    useThreads = TRUE;	} else if ( filever.Compare( libver ) > 0 ) {	    libname = qtFile;	    libver = filever;	    useThreads = FALSE;	} else if ( filever.Compare( libver ) == 0 && libname.Right(6).Compare("nc.lib")==0 ) {	    libname = qtFile;	    libver = filever;	    useThreads = FALSE;	}    }    return useThreads;}void CCommands::addSharedSettings( 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" );    const CComBSTR threadLibD("/MLd");    const CComBSTR threadLibR("/ML");    const CComBSTR correctLibD("/MDd");

⌨️ 快捷键说明

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