📄 commands.cpp
字号:
/************************************************************************
*
* Resource ID Organiser Add-In
*
* (c) Copyright 2000 by Andy Metcalfe (andy.metcalfe@lineone.net)
* All rights reserved.
*
************************************************************************
*
* Filename : Commands.cpp
*
* Description : CCommands - Add-In implementation class
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or 4
*
* Target
* Environment : Windows 98/NT
*
* NOTE:
*
* This software is provided "as is" free for personal use. All
* title and copyrights in and to the software, including but not
* limited to any images, text, etc. incorporated into it, are
* owned by Andy Metcalfe, except where acknowledged otherwise.
*
* Your may freely to use this code in your own products, PROVIDED
* this notice is not removed or modified.
*
*
* Visit http://www.resorg.co.uk for latest updates
*
************************************************************************
*
* MODIFICATION HISTORY:
*
* This is a controlled document. See project configuration
* control tool for latest version and full version history.
*
* $Archive: /Projects/AddIns/ResOrg/ResOrgAddIn/Commands.cpp $
* $Revision: 7 $
* $Date: 8/07/01 17:06 $
* $Author: Andy $
*
* $History: Commands.cpp $
*
* ***************** Version 7 *****************
* User: Andy Date: 8/07/01 Time: 17:06
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* The "Options" dialog and "About" Box are now parented by DevStudio's
* main window rather than ResOrg's (this fixes a pretty nasty bug)
*
* ***************** Version 6 *****************
* User: Andy Date: 26/05/01 Time: 21:00
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Make Visual Studio the Active Window after executing ResOrg commands
* (prevents odd behaviour when the ResOrg toolbar in DevStudio is
* floated)
*
* ***************** Version 5 *****************
* User: Andy Date: 24/04/01 Time: 0:19
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Modified startup to prevent the wrong window being identified as the
* DevStudio window if another window was active.
*
* The active window is now checked when a command on the toolbar is
* activated instead
*
* ***************** Version 4 *****************
* User: Andy Date: 21/04/01 Time: 7:36
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Added version expiry check
*
* ***************** Version 3 *****************
* User: Andy Date: 29/11/00 Time: 18:37
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* 1. Moved Office2KDlg code to its own DLL
* 2. Added file banners
*
* $Nokeywords: $
*
************************************************************************/
// Commands.cpp : implementation file
//
#include "StdAfx.h"
#include "ResOrgAddIn.h"
#include "MainFrame.h"
#include "ResOrgProjectsDoc.h"
#include "ResOrgAddInApp.h"
#include "WorkspaceHelper.h"
#include "Commands.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CWorkspaceHelper hides away the grot of talking to the COM interfaces
// exposed by Visual Studio...
CWorkspaceHelper Workspace;
/////////////////////////////////////////////////////////////////////////////
// CCommands
CCommands::CCommands(void)
{
m_pApplication = NULL;
m_pApplicationEventsObj = NULL;
m_pDebuggerEventsObj = NULL;
}
CCommands::~CCommands(void)
{
Workspace.SetApplication(NULL);
ASSERT (m_pApplication != NULL);
m_pApplication->Release();
}
void CCommands::SetApplicationObject(IApplication* pApplication)
{
// This function assumes pApplication has already been AddRef'd
// for us, which CDSAddIn did in its QueryInterface call
// just before it called us.
m_pApplication = pApplication;
Workspace.SetApplication(m_pApplication);
// Create Application event handlers
XApplicationEventsObj::CreateInstance(&m_pApplicationEventsObj);
m_pApplicationEventsObj->AddRef();
m_pApplicationEventsObj->Connect(m_pApplication);
m_pApplicationEventsObj->m_pCommands = this;
// Create Debugger event handler
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(void)
{
ASSERT (m_pApplicationEventsObj != NULL);
m_pApplicationEventsObj->Disconnect(m_pApplication);
m_pApplicationEventsObj->Release();
m_pApplicationEventsObj = NULL;
if (m_pDebuggerEventsObj != NULL)
{
// Since we were able to connect to the Debugger events, we
// should be able to access the Debugger object again to
// unadvise from its events (thus the VERIFY_OK below--see 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;
}
}
HWND CCommands::GetDevStudioWindow(void) const
{
HWND hWndDevStudio = NULL;
HWND hWndDesktop = ::GetDesktopWindow();
HWND hWnd = ::GetActiveWindow();
while ( (NULL != hWnd) && (hWnd != hWndDesktop) )
{
hWndDevStudio = hWnd;
hWnd = ::GetParent(hWnd);
}
return hWndDevStudio;
}
/////////////////////////////////////////////////////////////////////////////
// Event handlers
// TODO: Fill out the implementation for those events you wish handle
// Use m_pCommands->GetApplicationObject() to access the Developer
// Studio Application object
// Application events
HRESULT CCommands::XApplicationEvents::BeforeBuildStart(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT CCommands::XApplicationEvents::BuildFinish(long nNumErrors, long nNumWarnings)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(nNumErrors);
UNREFERENCED_PARAMETER(nNumWarnings);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::BeforeApplicationShutDown(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TO DO: Shut down main window
return S_OK;
}
HRESULT CCommands::XApplicationEvents::DocumentOpen(IDispatch* theDocument)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(theDocument);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::BeforeDocumentClose(IDispatch* theDocument)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(theDocument);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::DocumentSave(IDispatch* theDocument)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(theDocument);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::NewDocument(IDispatch* theDocument)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(theDocument);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::WindowActivate(IDispatch* theWindow)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(theWindow);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::WindowDeactivate(IDispatch* theWindow)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(theWindow);
return S_OK;
}
HRESULT CCommands::XApplicationEvents::WorkspaceOpen(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT CCommands::XApplicationEvents::WorkspaceClose(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT CCommands::XApplicationEvents::NewWorkspace(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
// Debugger event
HRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch* pBreakpoint)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
UNREFERENCED_PARAMETER(pBreakpoint);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// CCommands methods
STDMETHODIMP CCommands::ResOrgShowMethod(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE) );
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
if (pMainFrame != NULL)
{
ASSERT_VALID(pMainFrame);
#ifdef _RESORG_EXPIRY_DATE
::DoVersionExpiryCheck();
#endif
pMainFrame->DoModal( GetDevStudioWindow() );
}
else
{
AfxMessageBox( IDP_WND_CREATION_FAILURE,
MB_OK | MB_ICONSTOP);
}
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE) );
return S_OK;
}
STDMETHODIMP CCommands::ResOrgOptionsMethod(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE) );
// Because this add-in is implemented as a Regular DLL with a
// mainframe window the usual trick of calling EnableModeless()
// isn't enough to ensure that modal dialogs behave correctly -
// we also have to ensure that any dialogs are parented by
// DevStudio's main window rather than our own...
HWND hWndDevStudio = GetDevStudioWindow();
CWnd* pWnd = CWnd::FromHandle(hWndDevStudio);
Options.Configure(pWnd);
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE) );
return S_OK;
}
STDMETHODIMP CCommands::ResOrgAboutMethod(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE) );
// Because this add-in is implemented as a Regular DLL with a
// mainframe window the usual trick of calling EnableModeless()
// isn't enough to ensure that modal dialogs behave correctly -
// we also have to ensure that any dialogs are parented by
// DevStudio's main window rather than our own...
HWND hWndDevStudio = GetDevStudioWindow();
CWnd* pWnd = CWnd::FromHandle(hWndDevStudio);
CResOrgAboutBox aboutDlg(pWnd);
aboutDlg.DoModal();
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE) );
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -