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

📄 windowex.hpp

📁 一个完整的桌面日历程序
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																					-
// - File:			windowex.hpp.																														-
// -																																					-
// - Contents: 		Interfaces and implementation of window related funtionality.																		-
// -																																					-
// - Purpose:  		-																																	-
// -																																					-
// - Remarks:    	-																																	-
// -																																					-
// - Originator: 	Michael Mogensen, MM-IT Consult 2003.																								-
// -																																					-
// - Compiler:		MS Visual C++ ver6.0.																											    -
// -																																					-
// - Period:		00.00.00 - 00.00.00.																											    -
// -																																					-
// - Version:		1.00. 																																-
// -																																					-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Header(s).																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "geometryex.hpp"
#include "shadow_dc.h"

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Global(s), predecleration(s).																														-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
enum EDirection 
{
	eDir_Unknown, 
	eDir_Left2Right, 
	eDir_Top2Bottom, 
	eDir_Right2Left, 
	eDir_Bottom2Top 
};

enum ETBLocWindow
{
	eTBLoc_Unknown,
	eTBLoc_Left, 
	eTBLoc_Top, 
	eTBLoc_Right, 
	eTBLoc_Bottom
};

inline const CRectEx 
GetClientRectEx(CWnd*, const bool bInRelativeCoord = false);

inline const CRectEx 
GetScreenRect();

inline const CRectEx 
GetTaskbarRect();

inline const ETBLocWindow 
GetTaskbarLocation();

inline const CRectEx 
GetTaskbarRect();

inline const HWND 
GetWindowFromPt(const CPointEx&);

inline const CRectEx 
GetWindowRectEx(CWnd*, const bool bInRelativeCoord = false);

inline const bool 
IsPtInWindow(CWnd*, const CPointEx &ipMouseEx = CPointEx(0, 0));

inline const bool 
SetTrayIcon(
	CWnd*, 
	CONST DWORD, 
	CONST DWORD, 
	CONST UINT, 
	LPCTSTR lpszTTTEx = _T(""), 
	CONST UINT uId_CallbackEx = 0);

inline const void 
SlideWindow(
	CWnd*, 
	const enum EDirection, 
	const long, 
	const long, 
	CShadowDC*, 
	CShadowDC*, 
	const bool, 
	CRectEx const *pirWindow_EndEx = NULL);

inline const void 
Wait(const long);

inline const bool 
WndCenter(const HWND&);

inline const bool 
WndCenter(const HWND&, const float, const float);

inline const bool 
WndCenter(const HWND&, const int, const int);

inline const bool 
WndPlace(const HWND&, const double, const double);

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Global(s).																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
inline const CRectEx GetClientRectEx(CWnd *pWnd, const bool bInRelativeCoord)
// Return client rect.
{
	CRectEx irClient;
	if(pWnd)
		pWnd->GetClientRect((LPRECT)&irClient);
	if(bInRelativeCoord)
		irClient.MoveTo(0, 0);
	return irClient;
}

inline const CRectEx GetScreenRect()
// Return screen rect.
{
	const CRectEx irScreen(0,
						   0,
						   ::GetSystemMetrics(SM_CXSCREEN),
						   ::GetSystemMetrics(SM_CYSCREEN));
	return irScreen;
}

inline const ETBLocWindow GetTaskbarLocation()
{
	HWND hWndDesktop = ::GetDesktopWindow();
	if(!hWndDesktop || !::IsWindow(hWndDesktop))
		return eTBLoc_Unknown;
	HWND hWndTB = ::FindWindow(_T("Shell_TrayWnd"), NULL);
	if(!hWndTB || !::IsWindow(hWndTB))
		return eTBLoc_Unknown;
	// Check location.
	enum ETBLocWindow iWindow = eTBLoc_Unknown;
	CRectEx irWndDesktop;
	CRectEx irWndTB;
	::GetWindowRect(hWndDesktop, (LPRECT)&irWndDesktop);
	::GetWindowRect(hWndTB, (LPRECT)&irWndTB);
	irWndTB.RestrictTo(irWndDesktop);
	// Along top edge?
	if(irWndDesktop.top == irWndTB.top &&
	   irWndDesktop.right == irWndTB.right &&
	   irWndDesktop.bottom != irWndTB.bottom &&
	   irWndDesktop.left == irWndTB.left)
		iWindow = eTBLoc_Top;
	else
		// Along right edge?
		if(irWndDesktop.top == irWndTB.top &&
		   irWndDesktop.right == irWndTB.right &&
		   irWndDesktop.bottom == irWndTB.bottom &&
		   irWndDesktop.left != irWndTB.left)
			iWindow = eTBLoc_Right;
		else
			// Along bottom edge?
			if(irWndDesktop.top != irWndTB.top &&
			   irWndDesktop.right == irWndTB.right &&
			   irWndDesktop.bottom == irWndTB.bottom &&
			   irWndDesktop.left == irWndTB.left)
				iWindow = eTBLoc_Bottom;
			else
				// Along left edge?
				if(irWndDesktop.top == irWndTB.top &&
				   irWndDesktop.right != irWndTB.right &&
				   irWndDesktop.bottom == irWndTB.bottom &&
				   irWndDesktop.left == irWndTB.left)
					iWindow = eTBLoc_Left;
	return iWindow;
}

inline const CRectEx GetTaskbarRect()
// Return tastbar wnd. rect.
{
	CRectEx irWndTB;
	HWND hWndTB = ::FindWindow(_T("Shell_TrayWnd"), NULL);
	::GetWindowRect(hWndTB, (LPRECT)&irWndTB);
	return irWndTB;
}

inline const HWND GetWindowFromPt(const CPointEx &ipMouse)
// Return handle of wnd. under mouse of this pt.
{
	CPointEx ipMouseEx;
	if(ipMouse.Exist())
		ipMouseEx = ipMouse;
	else
	{
		DWORD dwMessagePos = ::GetMessagePos();
		ipMouseEx.Set(LOWORD(dwMessagePos), HIWORD(dwMessagePos));
	}
	return(::ChildWindowFromPointEx(::GetDesktopWindow(), ipMouseEx, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED | CWP_SKIPTRANSPARENT));
}

inline const CRectEx GetWindowRectEx(CWnd *pWnd, const bool bInRelativeCoord)
// Return window rect.
{
	CRectEx irWindow;
	if(pWnd)
		pWnd->GetWindowRect((LPRECT)&irWindow);
	if(bInRelativeCoord)
		irWindow.MoveTo(0, 0);
	return irWindow;
}

inline const bool IsPtInWindow(CWnd *pWnd, const CPointEx &ipMouse)
// Return T in case this point is found within this window and F if not.
{
	if(!pWnd)
		return false;
	CPointEx ipMouseEx;
	if(ipMouse.Exist())
		ipMouseEx = ipMouse;
	else
	{
		DWORD dwMessagePos = ::GetMessagePos();
		ipMouseEx.Set(LOWORD(dwMessagePos), HIWORD(dwMessagePos));
	}
	const HWND hWndFromPt = ::GetWindowFromPt(ipMouseEx);
	const HWND hWndFromPtr = pWnd->GetSafeHwnd();
	return(::IsWindow(hWndFromPt) &&
		   ::IsWindow(hWndFromPtr) &&
		   (hWndFromPt == hWndFromPtr));
}

inline const bool SetTrayIcon(
	CWnd *pWnd, 
	CONST DWORD dwMessage, 
	CONST DWORD dwMessage_NIM,
	CONST UINT uId_Icon,
	LPCTSTR lpszTTT,
	CONST UINT uId_Callback)
// In the tray, show specific icon. Return T on succes and F if not.
// 
// To add the icon use:			NIM_ADD for NIM msg.
// To change the icon use:		NIM_MODIFY for NIM msg.
// To remove the icon use:		NIM_ADD for NIM msg.
// 
{
	NOTIFYICONDATA nid;
	nid.cbSize = sizeof(NOTIFYICONDATA);
	nid.hWnd = pWnd->GetSafeHwnd();
	nid.uID = uId_Callback;
	nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
	nid.uCallbackMessage = dwMessage;
	nid.hIcon = (HICON)::AfxGetApp()->LoadIcon(uId_Icon);
	::lstrcpyn(nid.szTip, lpszTTT, sizeof(nid.szTip));
	bool bResult = (::Shell_NotifyIcon(dwMessage_NIM, &nid) != 0);
	if(nid.hIcon)
		::DestroyIcon(nid.hIcon);
	return bResult;
}

inline const void SlideWindow(CWnd *pWnd, 
							  const enum EDirection iDirection, 
							  const long lDelay, 
							  const long lDelayAcc, 
							  CShadowDC *pdc_shadow_client, 
							  CShadowDC *pdc_shadow_non_client, 
							  const bool bSendNCPaintMsg, 
							  CRectEx const *pirWindow_End)
// Slowly slides window into position until fully visible/invisible.
{
	if(!pWnd || !::IsWindow(pWnd->GetSafeHwnd()))
		// On error.
		return;
	try
	{
		const UINT uFlags = SWP_SHOWWINDOW | SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOACTIVATE;
		long lDelayCurrent = lDelay;
		int iHeight = 0, 
			iWidth = 0;
		CRectEx irWindow_Begin;
		CRectEx irWindow_End(*pirWindow_End);
		CRectEx 
			irClient, 
			irClient_Final;
		CDC *pdc_client = pWnd->GetDC();
		CDC *pdc_non_client = pWnd->GetWindowDC();
		if(pdc_shadow_client)
			irClient_Final = pdc_shadow_client->GetDrawRect();
		switch(iDirection)
		{
			case eDir_Unknown:
				// On error.
				return;
			case eDir_Left2Right: 
			{
				if(pWnd->IsWindowVisible())
				{
					// Slide to invisible.
					irWindow_Begin = ::GetWindowRectEx(pWnd);
					iHeight = irWindow_Begin.Height();
					while(irWindow_Begin != irWindow_End)
					{
						++irWindow_Begin.left;
						pWnd->SetWindowPos(&pWnd->wndTop, 
										   irWindow_Begin.left, 
										   irWindow_Begin.top, 
										   irWindow_Begin.right - irWindow_Begin.left, 
										   iHeight, 
										   uFlags);
						if(pdc_shadow_client)
						{
							pdc_client->BitBlt(
								0, 
								0, 
								irClient_Final.right, 
								irClient_Final.bottom, 
								pdc_shadow_client, 
								0, 
								0, 
								SRCCOPY);
						}
						else
							pWnd->SendMessage(WM_PAINT);
						if(pdc_shadow_non_client)
						{
							// No impl.
						}
						if(bSendNCPaintMsg)
							pWnd->SendMessage(WM_NCPAINT);
						if(lDelayCurrent > 0L)
						{
							Wait(lDelayCurrent);
							lDelayCurrent = max(0L, (lDelayCurrent + lDelayAcc));
						}
					};
					pWnd->ShowWindow(SW_HIDE);
				}
				else
				{
					// Slide to visible.
					iHeight = irWindow_End.Height();
					irWindow_Begin.Set(
						irWindow_End.left, 
						irWindow_End.top,
						irWindow_End.left, // At 0 width to begin with.
						irWindow_End.bottom);
					pWnd->ShowWindow(SW_SHOW);
					while(irWindow_Begin != irWindow_End)
					{
						++irWindow_Begin.right;
						iWidth = irWindow_Begin.right - irWindow_Begin.left;
						pWnd->SetWindowPos(&pWnd->wndTop, 
										   irWindow_Begin.left, 
										   irWindow_Begin.top, 
										   iWidth, 
										   iHeight, 
										   uFlags);
						if(pdc_shadow_client)
						{
							pdc_client->BitBlt(
								0, 
								0, 
								irClient_Final.right, 
								irClient_Final.bottom, 
								pdc_shadow_client, 
								irClient_Final.right - iWidth, 
								0, 
								SRCCOPY);
						}
						else
							pWnd->SendMessage(WM_PAINT);
						if(pdc_shadow_non_client)
						{
							// No impl.

⌨️ 快捷键说明

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