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

📄 clock.dpr

📁 这一系列是我平时收集的pascal深入核心编程
💻 DPR
字号:
program Clock;

{$R Clock.res}

uses Windows, Messages;

const
  IDC_TIME  = 100; // Static控件ID
  IDD_CLOCK = 101; // 对话框模板ID
  IDI_CLOCK = 102; // 对话框图标ID

  // WM_INITDIALOG消息处理函数
function Clock_OnInitDialog(hWnd, hWndFocus: HWND; lParam: LPARAM): BOOL;
begin
  SetTimer(hWnd, 1, 1000, nil); // 安装定时器,间隔为1秒
  SendMessage(hWnd, WM_TIMER, 1, 0); // 先执行一次WM_TIMER处理过程
  SendMessage(hWnd, WM_SETICON, ICON_BIG, // 设置对话框图标
    LoadIcon(Hinstance, MakeIntResource(IDI_CLOCK)));
  Result := TRUE; // 允许Windows设置焦点给hWndFocus
end;

  // WM_TIMER消息处理过程
procedure Clock_OnTimer(hWnd: HWND; id: UINT);
var
  szTime: array[0..100] of Char;
begin
  GetTimeFormat(LOCALE_USER_DEFAULT, 0, nil, nil, szTime, SizeOf(szTime));
  SetDlgItemText(hWnd, IDC_TIME, szTime); // 设Static控件文字为当前时间
end;

  // WM_COMMAND消息处理过程
procedure Clock_OnCommand(hWnd: HWND; id: Integer; hWndCtl: HWND; codeNotify: UINT);
begin
  if (id = IDCANCEL) then EndDialog(hWnd, id); // 关闭对话框
end;

  // 对话框消息处理回调函数
function Clock_DlgProc(hWnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): BOOL; stdcall;
begin
  Result := TRUE; // 返回TRUE代表消息已被处理  
  case (uMsg) of
    WM_INITDIALOG:
      Result := BOOL(SetWindowLong(hWnd, DWL_MSGRESULT, Longint(Clock_OnInitDialog(hWnd, wParam, lParam))));
    WM_TIMER:
      Clock_OnTimer(hWnd, 1);
    WM_COMMAND:
      Clock_OnCommand(hWnd, LOWORD(wParam), lParam, HIWORD(wParam));
    else
      Result := FALSE; // 要求DefDlgProc()处理消息
  end;
end;

  // 程序'主线程'入口
begin
  DialogBox(HInstance, MakeIntResource(IDD_CLOCK), 0, @Clock_DlgProc);
end.

⌨️ 快捷键说明

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