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

📄 expndbox.pas

📁 这一系列是我平时收集的pascal深入核心变成
💻 PAS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -