【问题标题】:Visual c++, resize a control on mousedownVisual c++,在 mousedown 上调整控件的大小
【发布时间】:2013-03-26 23:30:25
【问题描述】:

我创建了一个 UserControllibrary,其中包含几个常规 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 但是this-&gt;Size.Width = (this-&gt;Location.X - e-&gt;Location.X); // this->Size.Width 将保持其先前由属性窗口设置的默认值 400。

我知道可以通过 Windows 消息设置大小,但我不明白如何。 取自 C# 示例: Controls won't get resized once the nesting hierarchy of windows exceeds a certain depth

    // 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 的属性/方法

如何进行?

【问题讨论】:

    标签: winforms winapi visual-c++ winforms-interop


    【解决方案1】:

    Size 属性返回一个结构,它是值类型。所以你得到一个副本,你修改它,但原来的保持不变。要更改表单的大小,您可以设置:

    this->Size = new Size(100, 100);

    或者更好,使用宽度和高度属性:

    this->宽度 += 100;

    【讨论】:

    • 你是对的this-&gt;Width,发生了一些事情......虽然,我不知道......到底是什么......在它上面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    相关资源
    最近更新 更多