1,184
社区成员
发帖
与我相关
我的任务
分享unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
dtp1: TDateTimePicker;
procedure dtp1DropDown(Sender: TObject);
procedure dtp1CloseUp(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses CommCtrl;
{$R *.dfm}
var
g_hHook: HHOOK;
function CallWndProc(code: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT stdcall;
function IsYearEdit(h: hwnd): Boolean;
var
b: array[0..255] of Char;
begin
Result := False;
GetClassName(h, b, 256);
if b <> 'Edit' then Exit;
Result := GetParent(h) = DateTime_GetMonthCal(Form1.dtp1.Handle);
end;
begin
if code = HC_ACTION then
begin
Result := 0;
if PCWPStruct(lParam)^.message = WM_SETFOCUS then
begin
if IsYearEdit(PCWPStruct(lParam)^.hwnd) then
begin
Form1.Text := '获得焦点'
end
end
else if PCWPStruct(lParam)^.message = WM_KILLFOCUS then
if IsYearEdit(PCWPStruct(lParam)^.hwnd) then
begin
Form1.Text := '失去焦点'
end
end else
Result := CallNextHookEx(g_hHook, code, wParam, lParam)
end;
procedure TForm1.dtp1DropDown(Sender: TObject);
begin//dtp1的OnDropDown事件
g_hHook := SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, hInstance, GetCurrentThreadId)
end;
procedure TForm1.dtp1CloseUp(Sender: TObject);
begin//dtp1的OnCloseUp事件
UnhookWindowsHookEx(g_hHook)
end;
end.