【问题标题】:C++ Draggable Borderless FormC++ 可拖动无边框表单
【发布时间】:2011-10-25 01:50:13
【问题描述】:

好的,我正在 Microsoft Visual Studio C++ 2010 中用 C++ 制作一个简单的便签应用程序(Winodws 表单)。 我正在尝试制作一个可拖动的无边框表单。 我现在的代码是:

private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
this->dragging = false;
}

private: System::Void Form1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
this->dragging = true;
this->offset = Point(e->X, e->Y);

}


private: System::Void Form1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if (this->dragging)
{
Point currentScreenPos = PointToScreen(e->Location);
Location = Point(currentScreenPos.X - this->offset.X, currentScreenPos.Y - this->offset.Y);
}

}

private: System::Void Form1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
this->dragging = false;
}

这对我不起作用。任何人都可以帮忙吗?

【问题讨论】:

  • 你没有在 MouseMove 事件中使用e

标签: c++ winforms visual-studio-2010


【解决方案1】:

与其手动跟踪鼠标,不如让操作系统为您完成。拦截WM_NCHITTEST 并返回HTCAPTION。或者,仅使用 MouseDown 事件,向窗口发送一个特殊的WM_SYSCOMMAND/SC_DRAGmessage。 MSDN 上有很多关于拖动无边框和/或无标题窗口的信息。

【讨论】:

  • 我才 13 岁。我不知道该怎么做。
  • 在 MSDN 上查找 WM_NCHITTEST。您可以让您的 winform 覆盖它的虚拟 WndProc() 方法来捕获消息。至于SC_DRAG,官方并没有记载,不过是SC_MOVE + 2SC_MOVEWM_SYSCOMMAND 消息的可用参数,您可以使用SendMessage() 函数将其发送到您的winform。
猜你喜欢
  • 1970-01-01
  • 2016-07-03
  • 2011-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
  • 2014-05-23
  • 2011-11-15
相关资源
最近更新 更多