📄 pruninstaller.cpp
字号:
/* * * ppinstaller.cpp * * Copyright (C) 2006 Michael H. Overlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact at poster_printer@yahoo.com */#include "pruninstaller.h"#include "resource.h"#include "..\lib\prinstallroutines.h"#include "..\lib\printResizerCommon.h"#include "..\lib\prutils.h"#include "..\lib\workerthread.h"#include <windows.h>#include <shlobj.h>// *********************************************************************************************// ** MODULE PRIVATE TYPES ******************************************************************// *********************************************************************************************class UnInstallWorkerThread : public WorkerThread {public: UnInstallWorkerThread(ProgressDialogWindow *pdw) { m_pdw = pdw; } virtual ~UnInstallWorkerThread() { this->PeekMessagesUntilTerminate(); }protected: virtual void DoWork(void) { // NOT SURE IF IM USING COM, TO BE SAFE ... ::CoInitialize(0); ::InstallStatusString iss; ::SetWorkInProgress(TEXT("In progress."), m_pdw, &iss); ::DoAllUnInstall(m_pdw, &iss); ::SetWorkInProgress(TEXT("."), m_pdw, &iss); if (m_pdw != NULL) { m_pdw->SetStatusAllDone(); m_pdw->SetStatusString(iss.GetStatusString()); } ::CoUninitialize(); }private: ProgressDialogWindow* m_pdw;};// *********************************************************************************************// ** class InstallerDialogWindow ************************************************************// *********************************************************************************************UnInstallerDialogWindow::UnInstallerDialogWindow(IN HINSTANCE hinst) : DialogWindow(hinst, IDD_DIALOG_UNINSTALL){ m_bUninstallInProgress = FALSE;}UnInstallerDialogWindow::~UnInstallerDialogWindow() { // NOTHING TO DELETE}BOOL UnInstallerDialogWindow::InitMsg(WPARAM wParam, LPARAM lParam) { DialogWindow::InitMsg(wParam, lParam); // DOCS: DON'T HAVE TO WORRY ABOUT DELETING ICON HICON hIcon = ::LoadIcon(this->hinst(), MAKEINTRESOURCE(IDI_ICON_UNINSTALL)); this->SendMessage(WM_SETICON, ICON_BIG, (LPARAM) hIcon); this->SendMessage(WM_SETICON, ICON_SMALL, (LPARAM) hIcon); this->CenterWindowAboveParent(); tstring tstrTitle; ::ComposeDialogTitle(::PrintResizerComponents::eUnInstaller, tstrTitle, TEXT("Confirm")); this->SetWindowText(tstrTitle.c_str()); return TRUE;}BOOL UnInstallerDialogWindow::CommandMsg(WPARAM wParam, LPARAM lParam) { WORD wID = LOWORD(wParam); switch(wID) { case IDC_BUTTON_UNINSTALL: { if (! m_bUninstallInProgress) { m_bUninstallInProgress = TRUE; { tstring tstrMessage = TEXT("Please close any applications that are using "); tstrMessage += PRINTRESIZER_PACKAGE_NAME; tstrMessage += TEXT(" printers, and any of its utilities and folders."); tstrMessage += TEXT("\n\nThey cannot be uninstalled while they are in use."); ::NotificationMessage(PrintResizerComponents::eUnInstaller, this->hdlg(), tstrMessage.c_str()); }#if 1 HWND hwndUnInstall = this->GetDlgItem(IDC_BUTTON_UNINSTALL); HWND hwndCancel = this->GetDlgItem(IDC_BUTTON_CANCEL); HWND hwndStatic = this->GetDlgItem(IDC_STATIC_TEXT); ::DestroyWindow(hwndUnInstall); ::DestroyWindow(hwndCancel); DWORD dwStyle = this->GetWindowStyle(); dwStyle = (dwStyle & (~ (DWORD) WS_SYSMENU)) | WS_DLGFRAME; this->SetWindowStyleAndRedraw(dwStyle); ::SetWindowText(hwndStatic, TEXT("Uninstall in progress ... ")); ::CenterWindowAboveParent(hwndStatic); // THIS HAS THE EFFECT OF ALLOWING THE DIALOG WINDOW, WHICH NOW HAS JUST THE MESSAGE // "Uninstall in progress ...", // TO REPAINT ITSELF WHILE THE UNINSTALL PROGRESSES. // StartNewDoWorkThread RETURNS IMMEDIATELY. // AT THE END OF THES FOLLOWING BLOCK, THE DESTRUCTOR IS INVOKED. // THE DESTRUCTOR WAITS ON THE THREAD HANDLE UNTIL THE THREAD HAS TERMINATED // WHILE IT WAITS, IT EXECUTES A MESSAGE-PUMP LOOP { UnInstallWorkerThread *pWorker = new UnInstallWorkerThread(NULL); if (! pWorker->StartNewDoWorkThread()) { ::ErrorMessage(PrintResizerComponents::eUnInstaller, this->hdlg(), TEXT("Uninstall initialization failed.")); } delete pWorker; } tstring tstrMessage = PRINTRESIZER_PACKAGE_NAME; tstrMessage += TEXT(" has been uninstalled from your system."); ::NotificationMessage(PrintResizerComponents::eUnInstaller, this->hdlg(), tstrMessage.c_str());#else tstring tstrProgressDialogTitle; ::ComposeDialogTitle(PrintResizerComponents::eUnInstaller, tstrProgressDialogTitle, TEXT("Working")); ::InstallProgressDialog progDW(this->hinst(), tstrProgressDialogTitle, TEXT("Uninstalling ..."), TRUE); ::UnInstallWorkerThread *pWorker = new UnInstallWorkerThread( &progDW ); if (pWorker->StartNewDoWorkThread()) { progDW.SetInstallThread(pWorker); progDW.DoModalDialog(this->hdlg()); } else { ::ErrorExit(PrintResizerComponents::eUnInstaller, this->hdlg(), TEXT("Error initializing uninstall process.")); } delete pWorker;#endif this->DestroyWindow(); } } break; case IDC_BUTTON_CANCEL: if (! m_bUninstallInProgress) { this->DestroyWindow(); } break; default: break; } return TRUE;}BOOL UnInstallerDialogWindow::NotificationMsg(UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: // ONCE UNINSTALL IS IN PROGRESS, THIS HAS NO EFFECT this->PostMessage(WM_COMMAND, (WPARAM) IDC_BUTTON_CANCEL, 0); break; case WM_NCDESTROY: ::PostQuitMessage(0); break; default: break; } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -