احتملا Rec در پیام WMPAINT باید Global یا Static تعیین شود. تست نشده ولی روال بدین شکل است .
Private Pressed As Boolean
Private FocusLost As Boolean
Private TRect As RECT
Border3D_Y, Border_Thickness, Btn_Width,Button_Width, Button_Height
(GetWindowDC(FrmMainForm.Handle
(Border3D_Y=GetSystemMetrics(SM_CYEDGE
(Border_Thickness=GetSystemMetrics(SM_CYSIZEFRAME
(Button_Width=GetSystemMetrics(SM_CXSIZE
(Button_Height=GetSystemMetrics(SM_CYSIZE
Btn_Width=Border3D_Y+Border_Thickness+Button_Height-(2 * Border3D_Y) - 1
*Rec.Left=FrmMainForm.Width-(3
(Button_Width+Btn_Width
+Rec.Right=FrmMainForm.Width - (3 * Button_Width
(03
Rec.Top=Border3D_Y+Border_Thickness -1
*Rec.Bottom=Rec.Top+Button_Height - (2
(Border3D_Y
FillRect
(MyCanvas.Handle,Rec,HBRUSH(COLOR_BTNFACE+1
If not Pressed or Focuslost Then
DrawEdge MyCanvas.Handle, Rec, EDGE_RAISED,BF_SOFT or BF_RECT
Else If Pressed and Not Focuslost Then
DrawEdge MyCanvas.Handle, Rec, EDGE_SUNKEN, BF_SOFT or BF_RECT
DrawIconEX MyCanvas.Handle,Rec.Left+4,Rec.Top+3,Application.Icon.Handle,8, 8, 0, 0, DI_NORMAL
WMNCACTIVATE
(InvalidateRect FrmMainForm.Handle, Rec, True
WMNCPAINT
InvalidateRect FrmMainForm.Handle, Rec, True
WMNCMOUSEDOWN
PT1.X=Loword(LParam)- FrmMainForm.Left
PT1.Y=Hiword(LParam)- FrmMainForm.Top
if PTInRect(Rec,PT1.x,PT1.y) Then
Pressed=True
FocusLost=False
InvalidateRect FrmMainForm.Handle, Rec,True
SetCapture TWinControl(FrmMainForm).Handle
End If
WMLBUTTONUP
Tmp Boolean
ReleaseCapture
Tmp=Pressed
Pressed=False
if Tmp and PTInRect(Rec, PT1.x,PT1.y) Then
InvalidateRect FrmMainForm.Handle, Rec,True
WMNCHITTEST
Tmp : Boolean
if Pressed then
Tmp=FocusLost
End if
PT1.X=Loword(LParam)- FrmMainForm.Left
PT1.Y=Hiword(LParam)- FrmMainForm.Top
if PTInRect(Rec, PT1.x,PT1.y) then
FocusLost=False
else
FocusLost=True
End if
if FocusLost =Tmp then
InvalidateRect FrmMainForm.Handle, Rec,True
End If
SM_CXSCREEN = 0
SM_CYSCREEN = 1
SM_CXSIZE = 30
SM_CYSIZE = 31
SM_CXFRAME = 32
SM_CYFRAME = 33
SM_CYCAPTION = 4
SM_CXBORDER = 5
SM_CYBORDER = 6
SM_CXICON = 11
SM_CYICON = 12
SM_CYSIZEFRAME = SM_CYFRAME
SM_CXSIZEFRAME = SM_CXFRAME
SM_CXFRAME = 32
SM_CYFRAME = 33
SM_CXEDGE = 45
SM_CYEDGE = 46