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

📄 misc.cpp

📁 量免费资源任你下! 网站1:http://www.ahaoz.com 请这样记住本站:★A(爱)★hao(好)★Z(者).CoM 网站2:http://www.itlove.net
💻 CPP
字号:
/**
 * Misc.cpp		Copyright _ 2001 Li Zhaoming. All rights reserved.
 * Contains all miscellaneous functions "global" to the application.
 */

#include "stdafx.h"

/**
 * Center one window over another.
 *
 * PARAMETERS:
 *		hwndChild - The handle of the window to be centered.
 *		hwndParent- The handle of the window to center on.
 *
 * RETURN VALUE:
 *		true - Success
 *		false - Failure
 *
 * COMMENTS:
 *		Dialog boxes take on the screen position that they were designed
 *		at, which is not always appropriate. Centering the dialog over a
 *		particular window usually results in a better position.
 */

BOOL centerWindow(HWND hwndChild, HWND hwndParent)
{
	RECT rcChild, rcParent;
	int	cxChild, cyChild, cxParent, cyParent;
	int	cxScreen, cyScreen, xNew, yNew;
	HDC	hdc;

	// Get the Height and Width of the child window
	GetWindowRect(hwndChild, &rcChild);
	cxChild = rcChild.right - rcChild.left;
	cyChild = rcChild.bottom - rcChild.top;

	// Get the Height and Width of the parent window
	GetWindowRect(hwndParent, &rcParent);
	cxParent = rcParent.right - rcParent.left;
	cyParent = rcParent.bottom - rcParent.top;

	// Get the display limits
	hdc = GetDC(hwndChild);
	cxScreen = GetDeviceCaps(hdc, HORZRES);
	cyScreen = GetDeviceCaps(hdc, VERTRES);
	ReleaseDC(hwndChild, hdc);

	// Calculate new X position, then adjust for screen
	xNew = rcParent.left + ((cxParent - cxChild) / 2);
	if (xNew < 0)
	{
		xNew = 0;
	}
	else if ((xNew + cxChild) > cxScreen)
	{
		xNew = cxScreen - cxChild;
	}

	// Calculate new Y position, then adjust for screen
	yNew = rcParent.top + ((cyParent - cyChild) / 2);
	if (yNew < 0)
	{
		yNew = 0;
	}
	else if ((yNew + cyChild) > cyScreen)
	{
		yNew = cyScreen - cyChild;
	}

	// Set it, and return
	return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}

/**
 * Callback function for common open (save) file dialog.
 * PARAMETERS:
 *	hdlg - handle to child dialog box
 *	uMessage - message identifier
 *	wparam - message parameter
 *	lparam - message parameter
 */

UINT CALLBACK ofnHookProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
	if (uMessage == WM_INITDIALOG) // if NOT OFN_EXPLORER
	{
		HWND hwnd = GetParent(hdlg);
		centerWindow(hdlg, hwnd);
	}
	else if (uMessage == WM_NOTIFY) // if OFN_EXPLORER
	{
		LPNMHDR lpnmhdr = (LPNMHDR)lparam;
		if (lpnmhdr->code == CDN_INITDONE)
		{
			HWND hwnd = GetParent(hdlg);
			centerWindow(hwnd, GetParent(hwnd));
		}
	}
	return 0;
}

⌨️ 快捷键说明

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