📄 previewdialog_helpmenu.cpp
字号:
/* * * previewdialog_helpmenu.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 "previewdialog.h"#include "previewdialog_switches.h"#include "prpreviewutils.h"#include "resource.h"#include "..\lib\dialogwindow.h"#include "..\lib\myfilemap.h"#include "..\lib\printResizerCommon.h"#include "..\lib\prreadgpldialog.h"#include "..\lib\prutils.h"#include "..\lib\subclasswindow.h"#include <shellapi.h>// *****************************************************************************************// ** MODULE PRIVATE TYPES **************************************************************// *****************************************************************************************class AboutDialog : public DialogWindow {public: AboutDialog(PreviewDialog& pd, HINSTANCE hinst, const tstring& tstrTitle); virtual ~AboutDialog();protected: virtual BOOL InitMsg(WPARAM wParam, LPARAM lParam); virtual BOOL CommandMsg(WPARAM wParam, LPARAM lParam); virtual BOOL CommonControlColorNotifyMsg(UINT msg, WPARAM wParam, LPARAM lParam); virtual BOOL NotificationMsg(UINT msg, WPARAM wParam, LPARAM lParam) ;private: PreviewDialog& m_pd; tstring m_tstrTitle;};class DocumentationDialog : public DialogWindow {public: DocumentationDialog(PreviewDialog& pd, HINSTANCE hinst, const tstring& tstrTitle); virtual ~DocumentationDialog();protected: virtual BOOL InitMsg(WPARAM wParam, LPARAM lParam); virtual BOOL CommandMsg(WPARAM wParam, LPARAM lParam); virtual BOOL CommonControlColorNotifyMsg(UINT msg, WPARAM wParam, LPARAM lParam); virtual BOOL NotificationMsg(UINT msg, WPARAM wParam, LPARAM lParam) ;private: PreviewDialog& m_pd; tstring m_tstrTitle;};class HTMLLinkSubClass : public SubClassWindow {public: HTMLLinkSubClass(PreviewDialog& pd, HWND hwndUI, HINSTANCE hinst, HWND hwndTarget); virtual ~HTMLLinkSubClass() ;protected: virtual void CursorMsg(Window::MSGRESULT& mr, UINT msg, WPARAM wParam, LPARAM lParam) ; virtual void MouseMsg(Window::MSGRESULT& mr, UINT msg, WPARAM wParam, LPARAM lParam) ;private: PreviewDialog& m_pd; HCURSOR m_hcursHand; HWND m_hwndUI;};// *****************************************************************************************// ** class PreviewDialog ****************************************************************// *****************************************************************************************void PreviewDialog::OnHelpAbout(void) { tstring tstrTitle; this->ComposeDialogTitle(tstrTitle, TEXT("About")); AboutDialog *pad = new AboutDialog(*this, this->hinst(), tstrTitle); pad->DoModalDialog(this->hdlg());}void PreviewDialog::OnHelpDocumentation(void) { tstring tstrTitle; this->ComposeDialogTitle(tstrTitle, TEXT("Documentation")); ::DocumentationDialog *pdd = new ::DocumentationDialog(*this, this->hinst(), tstrTitle); pdd->DoModalDialog(this->hdlg());}// *****************************************************************************************// ** MODULE PRIVATE: class AboutDialog *************************************************// *****************************************************************************************AboutDialog::AboutDialog(PreviewDialog& pd, HINSTANCE hinst, const tstring& tstrTitle) : DialogWindow(hinst, IDD_DIALOG_ABOUT), m_pd(pd){ m_tstrTitle = tstrTitle;}AboutDialog::~AboutDialog() { // NOTHING TO DELETE}// ****// **** protected // ****BOOL AboutDialog::InitMsg(WPARAM wParam, LPARAM lParam) { DialogWindow::InitMsg(wParam, lParam); this->CenterWindowAboveParent(); this->SetWindowText(m_tstrTitle.c_str()); this->SetDlgItemText(IDC_STATIC_VERSION, PRINTRESIZER_VERSION_USER_SEES); this->SetDlgItemText(IDC_STATIC_AUTHOR, PRINTRESIZER_AUTHOR); this->SetDlgItemText(IDC_STATIC_CONTACT, PRINTRESIZER_CONTACT); this->SetDlgItemText(IDC_STATIC_WEBSITE, PRINTRESIZER_URL); this->SetDlgItemText(IDC_STATIC_BUGREPORT, PRINTRESIZER_BUGREPORT); this->SetDlgItemText(IDC_STATIC_SOURCE_CODE, PRINTRESIZER_SOURCE); this->SetDlgItemText(IDC_STATIC_OTHERCREDITS, PRINTRESIZER_OTHERCREDITS); this->SetDlgItemText(IDC_STATIC_OSFOR, PRINTRESIZER_OSFOR); this->SetDlgItemText(IDC_STATIC_PUBLISHDATE, PRINTRESIZER_PUBLISHDATE); HWND hwndWeb = this->GetDlgItem(IDC_STATIC_WEBSITE); new ::HTMLLinkSubClass(m_pd, this->hdlg(), this->hinst(), hwndWeb); HWND hwndBug = this->GetDlgItem(IDC_STATIC_BUGREPORT); new ::HTMLLinkSubClass(m_pd, this->hdlg(), this->hinst(), hwndBug); HWND hwndSource = this->GetDlgItem(IDC_STATIC_SOURCE_CODE); new ::HTMLLinkSubClass(m_pd, this->hdlg(), this->hinst(), hwndSource); HWND hwndContact = this->GetDlgItem(IDC_STATIC_CONTACT); new ::HTMLLinkSubClass(m_pd, this->hdlg(), this->hinst(), hwndContact); return TRUE;}BOOL AboutDialog::CommandMsg(WPARAM wParam, LPARAM lParam) { BOOL bRetValue = TRUE; WORD wID = LOWORD(wParam); switch(wID) { case IDC_BUTTON_LICENSE: { BOOL bDialogShown = FALSE; LPTSTR lptstrFileNameGPLRTFText = ::GetInstalledGPLRTFTextFileName(); if (lptstrFileNameGPLRTFText != NULL) { LPTSTR lptstrGPL_RTF = NULL; try { ::MyFileMap mfm; if (mfm.Open(lptstrFileNameGPLRTFText)) { DWORD dwCb = mfm.GetSize(); lptstrGPL_RTF = (LPTSTR) malloc(dwCb); if (lptstrGPL_RTF != NULL) { ::CopyMemory(lptstrGPL_RTF, mfm.GetBasePtr(), dwCb); } mfm.Close(); } } catch ( ... ) { } if (lptstrGPL_RTF != NULL) { ::ReadGPLDialog *prgpld = new ::ReadGPLDialog(this->hinst(), lptstrGPL_RTF, FALSE); prgpld->DoModalDialog(this->hdlg()); bDialogShown = TRUE; free(lptstrGPL_RTF); } free(lptstrFileNameGPLRTFText); } if (!bDialogShown) { m_pd.ErrorMessage(TEXT("Error loading GPL license text")); } } break; case IDC_BUTTON_OK: this->EndDialog(0); break; default: bRetValue = FALSE; break; } return bRetValue;}BOOL AboutDialog::CommonControlColorNotifyMsg(UINT msg, WPARAM wParam, LPARAM lParam) { // NOT STRICTLY CORRECT TO USE A STATIC VARIABLE FOR THIS ; IF THERE WERE EVER MULTIPLE // ABOUT DIALOGS UP AT ONCE, THE STATE WOULD BE INCORRECTLY SHARED AMONGST THEM ALL static BOOL bSkipRecursion = FALSE; BOOL bRetValue = FALSE; // I WANT TO CALL THE DEFDLGPROC TO GET THE BACKGROUND BRUSH // BUT I WANT TO SET THE TEXT COLOR switch(msg) { case WM_CTLCOLORSTATIC: if (!bSkipRecursion) { HWND hwndControl = (HWND) lParam; int iCtrlID = ::GetDlgCtrlID(hwndControl); if (iCtrlID == IDC_STATIC_BUGREPORT || iCtrlID == IDC_STATIC_CONTACT || iCtrlID == IDC_STATIC_SOURCE_CODE || iCtrlID == IDC_STATIC_WEBSITE ) { HDC hdc = (HDC) wParam; bSkipRecursion = TRUE; LRESULT lres = ::CallWindowProc(::DefDlgProc, this->hdlg(), WM_CTLCOLORSTATIC, wParam, lParam); bSkipRecursion = FALSE; bRetValue = (BOOL) lres; // BLUE COLOR FOR URL ::SetTextColor(hdc, RGB(0, 0, 0xff)); } } break; default: break; } return bRetValue;}BOOL AboutDialog::NotificationMsg(UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: this->PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_OK, 0), 0); break; default: break; } return FALSE;}// *****************************************************************************************// ** MODULE PRIVATE: class DocumentationDialog *****************************************// *****************************************************************************************DocumentationDialog::DocumentationDialog(PreviewDialog& pd, HINSTANCE hinst, const tstring& tstrTitle) : DialogWindow(hinst, IDD_DIALOG_DOCUMENTATION), m_pd(pd){ m_tstrTitle = tstrTitle;}DocumentationDialog::~DocumentationDialog() { // NOTHING TO DELETE}// ****// **** protected // ****BOOL DocumentationDialog::InitMsg(WPARAM wParam, LPARAM lParam) { DialogWindow::InitMsg(wParam, lParam); this->CenterWindowAboveParent(); this->SetWindowText(m_tstrTitle.c_str()); this->SetDlgItemText(IDC_STATIC_DIRECTORYURL, PRINTRESIZER_URL); HWND hwndURL = this->GetDlgItem(IDC_STATIC_DIRECTORYURL); new ::HTMLLinkSubClass(m_pd, this->hdlg(), this->hinst(), hwndURL); return TRUE;}BOOL DocumentationDialog::CommandMsg(WPARAM wParam, LPARAM lParam) { BOOL bRetValue = TRUE; WORD wID = LOWORD(wParam); switch(wID) { case IDC_BUTTON_OK: this->EndDialog(0); break; default: bRetValue = FALSE; break; } return bRetValue;}BOOL DocumentationDialog::CommonControlColorNotifyMsg(UINT msg, WPARAM wParam, LPARAM lParam) { // NOT STRICTLY CORRECT TO USE A STATIC VARIABLE FOR THIS ; IF THERE WERE EVER MULTIPLE // ABOUT DIALOGS UP AT ONCE, THE STATE WOULD BE INCORRECTLY SHARED AMONGST THEM ALL static BOOL bSkipRecursion = FALSE; BOOL bRetValue = FALSE; // I WANT TO CALL THE DEFDLGPROC TO GET THE BACKGROUND BRUSH // BUT I WANT TO SET THE TEXT COLOR switch(msg) { case WM_CTLCOLORSTATIC: if (!bSkipRecursion) { HWND hwndControl = (HWND) lParam; int iCtrlID = ::GetDlgCtrlID(hwndControl); if (iCtrlID == IDC_STATIC_DIRECTORYURL) { HDC hdc = (HDC) wParam; bSkipRecursion = TRUE; LRESULT lres = ::CallWindowProc(::DefDlgProc, this->hdlg(), WM_CTLCOLORSTATIC, wParam, lParam); bSkipRecursion = FALSE; bRetValue = (BOOL) lres; // BLUE COLOR FOR URL ::SetTextColor(hdc, RGB(0, 0, 0xff)); } } break; default: break; } return bRetValue;}BOOL DocumentationDialog::NotificationMsg(UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: this->PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_OK, 0), 0); break; default: break; } return FALSE;}// *****************************************************************************************// ** MODULE PRIVATE: class HTMLLinkSubClass ********************************************// *****************************************************************************************HTMLLinkSubClass::HTMLLinkSubClass(PreviewDialog& pd, HWND hwndUI, HINSTANCE hinst, HWND hwndTarget) : SubClassWindow(hinst, hwndTarget), m_pd(pd){ m_hwndUI = hwndUI; m_hcursHand = LoadCursor(NULL, IDC_HAND);}HTMLLinkSubClass::~HTMLLinkSubClass() { // NOTHING TO DELETE}void HTMLLinkSubClass::CursorMsg(Window::MSGRESULT& mr, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_SETCURSOR: if (m_hcursHand != NULL) { ::SetCursor(m_hcursHand); mr.bProcessed = TRUE; mr.lRetValue = 0; } break; default: break; }}void HTMLLinkSubClass::MouseMsg(Window::MSGRESULT& mr, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_LBUTTONDOWN: { LPTSTR lptstrLink = this->GetWindowText(); if (lptstrLink != NULL) { int iRetCode = (int) ::ShellExecute(m_hwndUI, TEXT("open"), lptstrLink, NULL, NULL, SW_SHOW); if (iRetCode <= 32) { tstring tstrMessage = TEXT("There was an error opening a web browser to display "); tstrMessage += lptstrLink; m_pd.ErrorMessage(tstrMessage.c_str()); } free(lptstrLink); } else { m_pd.ErrorMessage(TEXT("Unexpected error")); } mr.bProcessed = TRUE; mr.lRetValue = 0; } break; default: break; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -