?? misc.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;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -