我正在尝试创建一种机制,允许用户在工具栏上右键单击并拖动以移动窗口...
这证明非常困难:
我目前没有收到HTCAPTION活动,我已经看到了一个非常有用的帖子!
Not receiving WM_NCHitTest on title bar
这里的建议/替代方案是使用WMNCMouseMove并检查HitTest以查看它是否是标题。所以我天真地认为我可以扩展这个想法以使用WMNCMButtonDown(而不是)让我更近一步!
如果这样可行,那么我可以获得点击类型,即左,右,中,双或单!这将允许我以某种方式告诉窗口我希望将其识别为拖动事件。
问题是我从未收到过WM_NCMBUTTONDOW:
void __fastcall TForm1::Dispatch( void* message )
{
switch ( static_cast<TMessage*>( message )->Msg )
{
case WM_NCHITTEST:
{
TWMNCHitTest &Message = *static_cast<TWMNCHitTest*>( message );
WMNCHitTest( Message );
break;
}
case WM_NCMOUSEMOVE:
{
TWMNCMouseMove &Message = *static_cast<TWMNCMouseMove*>( message );
WMNCMouseMove( Message );
break;
}
case WM_NCMBUTTONDOWN:
{
TWMNCMButtonDown &Message = *static_cast<TWMNCMouseMove*>( message );
WMNCMButtonDown(Message);
break;
}
default:
{
TForm::Dispatch(message);
break;
}
}
}
是谁有任何想法?
值得注意的是,我确实收到了其他类型的消息(WM_NCHITTEST&amp;&amp; WM_NCMOUSEMOVE),因此机制正常工作。
请不要错过任何想法!!
谢谢,
乔
答案 0 :(得分:0)
我执行以下操作而不是覆盖任何方法。
在我的.h
BEGIN_MESSAGE_MAP
{
VCL_MESSAGE_HANDLER( WM_NCHITTEST, TWMNCHitTest, WMNCHitTest );
VCL_MESSAGE_HANDLER( WM_NCCALCSIZE, TWMNCCalcSize, WMNCCalcSize );
VCL_MESSAGE_HANDLER( WM_NCPAINT, TWMNCPaint, WMNCPaint );
VCL_MESSAGE_HANDLER( WM_ERASEBKGND, TWMEraseBkgnd, StopFlicker );
VCL_MESSAGE_HANDLER( WM_NCLBUTTONDOWN, TWMNCLButtonDown, WMNCLButtonDown );
}
END_MESSAGE_MAP( TCustomPanel ) // change TCustomPanel to your parent class name
void __fastcall WMNCHitTest( Messages::TWMNCHitTest& inoutMessage );
void __fastcall WMNCCalcSize( Messages::TWMNCCalcSize& inoutMessage );
void __fastcall WMNCPaint( Messages::TWMNCPaint& inoutMessage );
void __fastcall StopFlicker( Messages::TWMEraseBkgnd& inoutMessage );
void __fastcall WMNCLButtonDown( Messages::TWMNCLButtonDown& inoutMessage );
然后我在.cpp中实现代码,例如:
void __fastcall TResizePanel::WMNCLButtonDown( Messages::TWMNCLButtonDown &inoutMessage )
{
if ( inoutMessage.HitTest == HTCLOSE )
{
delete this;
inoutMessage.Result = 0;
}
else
{
Dispatch( &inoutMessage );
}
}