根据上面的思路写了一个PageControl组件,有点问题。请大侠看看!!
代码如下:
Unit RLpageControl;
Interface
Uses
SysUtils, Classes, Controls, ComCtrls, Windows, Messages, CommCtrl;
Type
TOnUpDownClickNextEvent = Procedure(Sender: TObject) Of Object; //关联的右键头按钮事件
TOnUpDownClickPriorEvent = Procedure(Sender: TObject) Of Object; //关联的左键头按钮事件
TRLpageControl = Class(TPageControl)
Private
UpDownWnd: HWND;
UpDownControl: TWinControl;
OldWndProc: TWndMethod;
FUpDownNextClick: TOnUpDownClickNextEvent;
FUpDownPriorClick: TOnUpDownClickPriorEvent;
Procedure OnUpDownNextClick(Sender: TObject);
Procedure OnUpDownPriorClick(Sender: TObject);
Protected
{ Protected declarations }
Public
Constructor Create(AOwner: TComponent); Override;
Procedure SetUpDownNextClick(UpDownOnNextClick: TOnUpDownClickNextEvent); Virtual; //用于设置右键头按钮事件指针
Procedure SetUpPriorPriorClick(UpDownOnPriorClick: TOnUpDownClickPriorEvent); Virtual; //用于设置左键头按钮事件指针
Published
Procedure NewWndProc(Var Message: TMessage);
End;
Procedure Register;
Implementation
Procedure Register;
Begin
RegisterComponents('GenCheng', [TRLpageControl]);
End;
{ TRLpageControl }
Constructor TRLpageControl.Create(AOwner: TComponent);
Begin
Inherited Create(AOwner);
If Not (csDesigning In ComponentState) Then //设计期不执行
Begin
OldWndProc := self.WindowProc;
self.WindowProc := NewWndProc;
End;
End;
Procedure TRLpageControl.NewWndProc(Var Message: TMessage);
Begin
Case Message.Msg Of
WM_NOTIFY:
With TWMNotify(Message) Do
If NMHdr^.code = UDN_DELTAPOS Then
Begin
PNMUpDown(NMHdr).iPos:=?????? //这一句该如何写
UpDownWnd := FindWindowEx(Handle, 0, 'msctls_updown32', Nil);
UpDownControl := FindControl(UpDownWnd);
LongBool(Result) := True; //不允许修改Position,这样的话点击箭头按钮就没反应了
End;
WM_HSCROLL:
Begin
If TWMHScroll(Message).ScrollCode = SB_THUMBPOSITION Then
If TWMHScroll(Message).Pos > ???? Then //这一句中的问号部分该如何写???
OnUpDownNextClick(UpDownControl)
Else
If TWMHScroll(Message).Pos < ???? Then //这一句中的问号部分该如何写???
OnUpDownPriorClick(UpDownControl);
End;
Else
OldWndProc(Message);
End;
End;
Procedure TRLpageControl.OnUpDownNextClick(Sender: TObject);
Begin
If Assigned(FUpDownNextClick) Then
FUpDownNextClick(Sender);
End;
Procedure TRLpageControl.OnUpDownPriorClick(Sender: TObject);
Begin
If Assigned(FUpDownPriorClick) Then
FUpDownPriorClick(Sender);
End;
Procedure TRLpageControl.SetUpDownNextClick(
UpDownOnNextClick: TOnUpDownClickNextEvent);
Begin
FUpDownNextClick := UpDownOnNextClick;
End;
Procedure TRLpageControl.SetUpPriorPriorClick(
UpDownOnPriorClick: TOnUpDownClickPriorEvent);
Begin
FUpDownPriorClick := UpDownOnPriorClick;
End;
End.