不可能呀!我的一个控件就是响应这两个消息的。
-------------------------------------------
下面是我的C++Builder代码:
void __fastcall WMSetFocus(TWMSetFocus& Message);
void __fastcall WMKillFocus(TWMKillFocus& Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_SETFOCUS,TWMSetFocus,WMSetFocus);
MESSAGE_HANDLER(WM_KILLFOCUS,TWMKillFocus,WMKillFocus);
END_MESSAGE_MAP(TPanel);
-------------------
//WMSetFocus
void __fastcall TExtPanel::WMSetFocus(TWMSetFocus& Message)
{
if(!TabStop)
{
PostMessage(this->Handle,WM_NEXTDLGCTL,0,(WPARAM)false);
return;
}
FGetFocus = true;
if(FOnSetFocus != NULL)
FOnSetFocus(this);
if(FDrawFocusRect)
Invalidate();
Message.Result = 1;
}
//---------------------------------------------------------------------------
//WMKillFocus
void __fastcall TExtPanel::WMKillFocus(TWMKillFocus& Message)
{
FGetFocus = false;
if(FOnKillFocus != NULL)
FOnKillFocus(this);
if(FDrawFocusRect)
Invalidate();
Message.Result = 1;
}
//---------------------------------------------------------------------------
void __fastcall TExtPanel:
aint()// Override
{
TPanel:
aint();
//............... Some code here
//画焦点
if(FDrawFocusRect && FGetFocus)
{
int Offset = 2;
this->Canvas->Brush->Color = clWhite;
Rect = TRect(0,0,this->Width,this->Height);
Rect.Left = Rect.Left + Offset;
Rect.Top = Rect.Top + Offset;
Rect.Right = Rect.Right-Offset;
Rect.Bottom = Rect.Bottom - Offset;
this->Canvas->DrawFocusRect(Rect);
}
}