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

📄 commands.cpp

📁 Qt/Embedded是一个多平台的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;}void CCommands::addSharedSettings( CComPtr<IConfiguration> pConfig ){    const CComBSTR compiler("cl.exe");    const CComBSTR linker("link.exe");    const CComBSTR dllDefine("/D QT_DLL");    const CComBSTR qtInclude("/I \"$(QTDIR)\\include\"");    const CComBSTR staticLib("$(QTDIR)\\lib\\qt.lib");    const CComBSTR sharedLib("$(QTDIR)\\lib\\qt222.lib $(QTDIR)\\lib\\qtmain.lib");    VERIFY_OK(pConfig->AddToolSettings( compiler, dllDefine, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->AddToolSettings( compiler, qtInclude, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->RemoveToolSettings( linker, staticLib, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->AddToolSettings( linker, sharedLib, CComVariant(VARIANT_FALSE) ));    m_pApplication->PrintToOutputWindow( CComBSTR("\t\tadded Qt shared library") );}void CCommands::addStaticSettings( CComPtr<IConfiguration> pConfig ){    const CComBSTR compiler("cl.exe");    const CComBSTR linker("link.exe");    const CComBSTR dllDefine("/D QT_DLL");    const CComBSTR qtInclude("/I \"$(QTDIR)\\include\"");    const CComBSTR staticLib("$(QTDIR)\\lib\\qt.lib");    const CComBSTR sharedLib("$(QTDIR)\\lib\\qt222.lib $(QTDIR)\\lib\\qtmain.lib");    VERIFY_OK(pConfig->RemoveToolSettings( compiler, dllDefine, CComVariant(VARIANT_FALSE) ));    VERIFY_OK(pConfig->AddToolSettings( compiler, qtInclude, 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 );

⌨️ 快捷键说明

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