📄 commands.cpp
字号:
/************************************************************************
*
* Resource ID Organiser Add-In
*
* (c) Copyright 2000-2002 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
* All rights reserved.
*
************************************************************************
*
* Filename : Commands.cpp
*
* Description : CCommands - Add-In implementation class
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or later
*
* Target
* Environment : Windows 98/NT/2000/XP
*
* 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 Anna-Jayne 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.annasplace.me.uk/resorg 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: 14 $
* $Date: 22/10/05 17:04 $
* $Author: Anna $
*
* $History: Commands.cpp $
*
* ***************** Version 14 *****************
* User: Anna Date: 22/10/05 Time: 17:04
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Moved CVc6AutomationHelper from the ResOrgCore module to ResOrgAddIn.
*
* ***************** Version 13 *****************
* User: Anna Date: 25/11/02 Time: 16:52
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Changed website address in banner
*
* ***************** Version 12 *****************
* User: Anna Date: 22/10/02 Time: 13:34
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Changed name/mail address (at last!)
*
* ***************** Version 11 *****************
* User: Andy Date: 2/08/02 Time: 17:03
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Renamed CWorkspaceHelper to CVc6AutomationHelper, and moved it to the
* ResOrgCore module
*
* ***************** Version 10 *****************
* User: Andy Date: 12/06/02 Time: 14:56
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Set the module state for the About Box to that of the Add-In's DLL
* before invoking it. This ensures that the Add-In will be listed in the
* "Modules" control
*
* ***************** Version 9 *****************
* User: Andy Date: 1/25/02 Time: 2:53p
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Added some (deactivated) code to identify the document being saved in
* CCommands::XApplicationEvents::DocumentSave()
*
* ***************** Version 8 *****************
* User: Andy Date: 12/29/01 Time: 11:42p
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Got rid of compiler warnings
*
* ***************** 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 "Vc6AutomationHelper.h"
#include "Commands.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CVc6AutomationHelper hides away the grot of talking to the COM interfaces
// exposed by Visual Studio...
CVc6AutomationHelper 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);
/*
// How to find out which file is being saved...
IGenericDocument* pDocument = NULL;
// Yum. Dontcha just *love* COM code?
m_pCommands->GetApplicationObject()->get_ActiveDocument( (IDispatch **)&pDocument);
if (NULL != pDocument)
{
CString sFullName = Workspace.GetFullName(pDocument);
pDocument->Release();
TRACE(" File %s saved\n", sFullName);
}
*/
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());
// TO DO: Get the pathname of the workspace and read it
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);
}
#pragma warning(push, 3)
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE) );
#pragma warning(pop)
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);
#pragma warning(push, 3)
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE) );
#pragma warning(pop)
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.SetModuleState( ::AfxGetStaticModuleState() );
aboutDlg.DoModal();
#pragma warning(push, 3)
VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE) );
#pragma warning(pop)
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -