我制作了一个UserControl
包含几个常规 Button 控件的库。
我想在拖动时调整它的大小。dragdetction 是通过 Windows 消息完成的,它可以完美地工作。
我什至设法设置了一个正确的光标并..重新打开WM_MOUSELEAVE
。
virtual void WndProc( Message %m ) override
{
// Listen for operating system messages
switch ( m.Msg )
{
// more code
// .
// ..
// ...
case WM_MOUSEMOVE:
if(m.WParam.ToInt32() == MK_CONTROL)
{
Debug::WriteLine("MK_CONTROL");
return;
}
else if(m.WParam.ToInt32() == MK_LBUTTON)
{
Debug::WriteLine("MK_LBUTTON");
if(isMouseDown)
{
Debug::WriteLine("drag Detected");
Debug::WriteLine("isMouseDown: " + isMouseDown.ToString());
int tempX = (short)(m.LParam.ToInt32() & 0x0000FFFF);
this->Size.Width = (this->Location.X - tempX); // <--- does not work!
return;
}
return;
}
else if(m.WParam.ToInt32() == MK_MBUTTON)
{
Debug::WriteLine("MK_MBUTTON");
return;
}
else if(m.WParam.ToInt32() == MK_RBUTTON)
{
Debug::WriteLine("MK_RBUTTON");
return;
}
else if(m.WParam.ToInt32() == MK_SHIFT)
{
Debug::WriteLine("MK_SHIFT");
return;
}
else if(m.WParam.ToInt32() == MK_XBUTTON1)
{
Debug::WriteLine("MK_XBUTTON1");
return;
}
else if(m.WParam.ToInt32() == MK_XBUTTON2)
{
Debug::WriteLine("MK_XBUTTON2");
return;
}
return;
// more code
// .
// ..
// ...
return;
}
System::Windows::Forms::UserControl::WndProc( m );
}
然而this->Size.Width = (this->Location.X - e->Location.X);
// <--- 不起作用!
this->Size.Width
将保持其先前由属性窗口设置的默认值 400。
我知道可以通过 Windows 消息设置大小,但我不明白如何。取自 C# 示例: 一旦窗口的嵌套层次结构超过一定深度,控件将不会调整大小
// this doesn't seam the right synthax for C++
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);
[DllImport("User32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter,
int x, int y, int cx, int cy, int flags);
UserControl
没有调用的属性/方法SetWindowPos
如何进行?