/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ /* * Description: Put MSO in a state where it can be closed using * automation or kill it completely */ #include "stdafx.h" #include void KillOffice(); BOOL KillAppFromWindow(HWND hWnd, char *appName); BOOL CloseActiveDialogs(); void printUsage(); //Callbacks used in closing BOOL CALLBACK CloseOfficeDlgProc(HWND hwndChild, LPARAM lParam); BOOL CALLBACK CountOfficeDlgProc(HWND hwndChild, LPARAM lParam); //Global counters for number of windows found int gWDDlgCount = 0; int gXLDlgCount = 0; int gPPDlgCount = 0; //Dialog window class names for excel, powerpoint and word //These are "Best guess" dialog names const char *pWordDlg2k = "bosa_sdm_Microsoft Word 9.0"; const char *pWordDlg2k3 = "bosa_sdm_Microsoft Office Word"; const char *pXLDlg2k = "bosa_sdm_XL9"; const char *pPPDlg2k = "#32770"; const char *pXLDlg2k3 = "bosa_sdm_XL9"; const char *pPPDlg2k3 = "#32770"; const char *pGenMSODlg = "bosa_sdm_Mso96"; //consider adding - bosa_sdm_Mso96 //Command Line Argument constants const char *ARG_HELP = "--help"; const char *ARG_KILL = "--kill"; const char *ARG_CLOSE = "--close"; //Window class names for MSO apps - if we need to look at other office instances //then this list would need to be expanded #define NUM_WINDOWCLASSNAMES 4 char *wndClassName[NUM_WINDOWCLASSNAMES] = {"OpusApp", "XLMAIN", "PP9FrameClass", "PP10FrameClass"}; int main(int argc, char* argv[]) { if (argc < 2) { printUsage(); return 0; } if (strcmpi(argv[1], ARG_HELP) == 0) { printUsage(); return 0; } if (strcmpi(argv[1], ARG_KILL) == 0) { KillOffice(); return 0; } if (strcmpi(argv[1], ARG_CLOSE) == 0) { CloseActiveDialogs(); return 0; } return 0; } /*-------------------------------------------------------------- Find the MSO window if it is available and explictly kill it MSO apps in this case are Excel, Word and PP Use FindWindow Win32 API to detect if they are available -------------------------------------------------------------*/ void KillOffice() { HWND hWnd; for (int i=0;i