expndbox.pas
来自「这一系列是我平时收集的pascal深入核心变成」· PAS 代码 · 共 69 行
PAS
69 行
unit ExpndBox;
interface
uses Windows, Messages;
// 调整对话框(放大or缩小)
procedure ExpandBox(fExpand: BOOL; hWnd: HWND; nIDDefaultBox: Integer);
implementation
// 调整对话框(放大or缩小)
procedure ExpandBox(fExpand: BOOL; hWnd: HWND; nIDDefaultBox: Integer);
var
RcWnd, RcDefaultBox, RcChild, RcIntersection: TRect;
hWndChild, hWndDefaultBox: LongWord; // HWND
dwDims: DWORD;
begin
// 取'预设区'Static句柄和范围
hWndDefaultBox := GetDlgItem(hWnd, nIDDefaultBox);
GetWindowRect(hWndDefaultBox, RcDefaultBox);
// 启用or禁用'预设区'外的控件
// 第一个控件
hWndChild := GetTopWindow(hWnd);
while (hWndChild <> 0) do
begin
// 控件范围
GetWindowRect(hWndChild, RcChild);
// 是否相交
if (not IntersectRect(RcIntersection, RcChild, RcDefaultBox)) then
EnableWindow(hWndChild, fExpand);
// 下一个控件
hWndChild := GetWindow(hWndChild, GW_HWNDNEXT);
end;
if (not fExpand) then // 缩小
begin
GetWindowRect(hWnd, RcWnd);
// 第一次缩小
if (GetWindowLong(hWnd, GWL_USERDATA) = 0) then
begin
// 保存大尺寸
SetWindowLong(hWndDefaultBox, GWL_USERDATA,
MakeLong(RcWnd.Right - RcWnd.Left, RcWnd.Bottom - RcWnd.Top));
// 隐藏'预设区'
ShowWindow(hWndDefaultBox, SW_HIDE);
end;
// 缩小对话框
SetWindowPos(hWnd, 0, 0, 0,
RcDefaultBox.Right - RcWnd.Left, RcDefaultBox.Bottom - RcWnd.Top,
SWP_NOZORDER or SWP_NOMOVE);
end else
begin
// 设置hWnd为以前保存的大尺寸
dwDims := GetWindowLong(hWndDefaultBox, GWL_USERDATA);
SetWindowPos(hWnd, 0, 0, 0, LOWORD(dwDims), HIWORD(dwDims), SWP_NOZORDER or SWP_NOMOVE);
// 保证整个对话框在屏幕上可见
SendMessage(hwnd, DM_REPOSITION, 0, 0);
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?