1.MESSAGE_HANDLER
public:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST,TWMNCHitTest ,OnNcHitTest)
END_MESSAGE_MAP(TForm)
void __fastcall OnNcHitTest(TWMNCHitTest&);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST,TWMNCHitTest ,OnNcHitTest)
END_MESSAGE_MAP(TForm)
void __fastcall OnNcHitTest(TWMNCHitTest&);
//---------------------------------------------------------------------------
void __fastcall TForm1::OnNcHitTest(TWMNCHitTest& Msg)
{
// 分解当前鼠标的坐标
int nPosX = Msg.XPos;
int nPosY = Msg.YPos;
if(nPosX >= Left + Width - 2 && nPosY >= Top + Height - 2)
{
// 鼠标位置在窗体的右下角附近
Msg.Result = HTBOTTOMRIGHT;
return;
}
else if(nPosX >= Left + Width -2)
{
// 鼠标位置在窗体右侧
Msg.Result = HTRIGHT;
return;
}
else if(nPosY >= Top + Height - 2)
{
// 鼠标位置在窗体下方
Msg.Result = HTBOTTOM;
return;
}
TForm::Dispatch(&Msg);
}
void __fastcall TForm1::OnNcHitTest(TWMNCHitTest& Msg)
{
// 分解当前鼠标的坐标
int nPosX = Msg.XPos;
int nPosY = Msg.YPos;
if(nPosX >= Left + Width - 2 && nPosY >= Top + Height - 2)
{
// 鼠标位置在窗体的右下角附近
Msg.Result = HTBOTTOMRIGHT;
return;
}
else if(nPosX >= Left + Width -2)
{
// 鼠标位置在窗体右侧
Msg.Result = HTRIGHT;
return;
}
else if(nPosY >= Top + Height - 2)
{
// 鼠标位置在窗体下方
Msg.Result = HTBOTTOM;
return;
}
TForm::Dispatch(&Msg);
}
2. 重写WndProc