⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 donutconfirmoption.h

📁 一个使用wtl写的完整的多窗口浏览器
💻 H
字号:

#pragma once

#define DONUT_CONFIRM_EXIT				0x00000001L
#define DONUT_CONFIRM_CLOSEALL			0x00000002L
#define DONUT_CONFIRM_CLOSEALLEXCEPT	0x00000004L

class CDonutConfirmOption
{
public:
	static DWORD s_dwFlags;

	static void GetProfile()
	{
		CIniSection pr;
		pr.Open(_szIniFileName, _T("Confirmation"));
		pr.QueryValue(s_dwFlags, _T("Confirmation_Flags"));
		pr.Close();
	}

	static void WriteProfile()
	{
		CIniSection pr;
		pr.Open(_szIniFileName, _T("Confirmation"));
		pr.SetValue(s_dwFlags, _T("Confirmation_Flags"));
		pr.Close();
	}

	static bool OnDonutExit(HWND hWnd = NULL)
	{
		if (_SearchDownloadingDialog()) {
			if (IDYES == ::MessageBox(hWnd, _T("Files are found downloading, will you exit Donut?"),
				_T("Agreement Dialog"), MB_YESNO|MB_ICONQUESTION))
				return true;
			else
				return false;
		}

		if (!_check_flag(DONUT_CONFIRM_EXIT, s_dwFlags))
			return true;

		// Note. On debug mode, If DONUT_CONFIRM_EXIT set, the process would be killed
		//       before Module::Run returns. What can I do?
		if (IDYES == ::MessageBox(hWnd, _T("Will you exit Donut?"),
			_T("Agreement Dialog"), MB_YESNO|MB_ICONQUESTION)) {
			return true;
		}

		return false;
	}

	static bool OnCloseAll(HWND hWnd = NULL)
	{
		if (!_check_flag(DONUT_CONFIRM_CLOSEALL, s_dwFlags))
			return true;

		if (IDYES == ::MessageBox(hWnd, _T("Will you close all the window?"),
			_T("Agreement Dialg"), MB_YESNO|MB_ICONQUESTION))
			return true;

		return false;
	}

	static bool OnCloseAllExcept(HWND hWnd = NULL)
	{
		if (!_check_flag(DONUT_CONFIRM_CLOSEALLEXCEPT, s_dwFlags))
			return true;

		if (IDYES == ::MessageBox(hWnd, _T("Will you close all the windows except this?"),
			_T("Agreement Dialg"), MB_YESNO|MB_ICONQUESTION))
			return true;

		return false;
	}

	static bool _SearchDownloadingDialog()
	{
		_Function_Searcher f;

		f = MtlForEachTopLevelWindow(_T("#32770"), NULL, f);

		return f._bFound;
	}

	struct _Function_Searcher
	{
		bool _bFound;
		_Function_Searcher() : _bFound(false) {	}

		bool operator()(HWND hWnd)
		{
			if (MtlIsWindowCurrentProcess(hWnd)) {
				CString strCaption = MtlGetWindowText(hWnd);
				if ( (strCaption.Find(_T('%')) != -1 && strCaption.Find(_T("Complete")) != -1) ||
					  strCaption.Find(_T("Download")) != -1 ) {
					_bFound = true;
					return false;
				}
			}

			return true;// continue finding
		}
	};
};

__declspec(selectany) DWORD CDonutConfirmOption::s_dwFlags = 0;

class CDonutConfirmPropertyPage : public CPropertyPageImpl<CDonutConfirmPropertyPage>,
	public CWinDataExchange<CDonutConfirmPropertyPage>
{
public:
// Constants
	enum { IDD = IDD_PROPPAGE_CONFIRMDLG };

// Data members
	int m_nExit, m_nCloseAll, m_nCloseAllExcept;

// DDX map
	BEGIN_DDX_MAP(CDonutConfirmPropertyPage)
		DDX_CHECK(IDC_CHECK_CFD_EXIT, m_nExit)
		DDX_CHECK(IDC_CHECK_CFD_CLOSEALL, m_nCloseAll)
		DDX_CHECK(IDC_CHECK_CFD_CLOSEEXCEPT, m_nCloseAllExcept)
	END_DDX_MAP()

// Constructor
	CDonutConfirmPropertyPage()
	{
		_SetData();
	}

// Overrides
	BOOL OnSetActive()
	{
		SetModified(TRUE);
		return DoDataExchange(FALSE);
	}

	BOOL OnKillActive()
	{
		return DoDataExchange(TRUE);
	}

	BOOL OnApply()
	{
		if (DoDataExchange(TRUE)) {
			_GetData();
			return TRUE;
		}
		else 
			return FALSE;
	}

// Implementation
protected:
	void _GetData()
	{
		DWORD dwFlags = 0;
		if (m_nExit == 1)
			dwFlags |= DONUT_CONFIRM_EXIT;
		if (m_nCloseAll == 1)
			dwFlags |= DONUT_CONFIRM_CLOSEALL;
		if (m_nCloseAllExcept == 1)
			dwFlags |= DONUT_CONFIRM_CLOSEALLEXCEPT;

		CDonutConfirmOption::s_dwFlags = dwFlags;
	}

	void _SetData()
	{
		DWORD dwFlags = CDonutConfirmOption::s_dwFlags;
		m_nExit = _check_flag(DONUT_CONFIRM_EXIT, dwFlags) ? 1 : 0;
		m_nCloseAll = _check_flag(DONUT_CONFIRM_CLOSEALL, dwFlags) ? 1 : 0;
		m_nCloseAllExcept = _check_flag(DONUT_CONFIRM_CLOSEALLEXCEPT, dwFlags) ? 1 : 0;
	}
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -