-2

我发现这段代码可以在面板中移动表单,但我想在 c++ 中使用这段代码,因为我在 vb 中为空,我需要帮助才能在 Visual c++ 中转换以下代码。

'Constants   
Const HTCAPTION = &H2
Const WM_NCLBUTTONDOWN = &HA1

'API functions   
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function ReleaseCapture() As Boolean
End Function
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr


'You could Dock a Panel to the top of your form and use:   


Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown

    'This code can be used in the MouseDown event of any control(s) you want to be able to move your form with   
    ReleaseCapture()
    SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0&)

End Sub
4

1 回答 1

1

在您的 WndProc 中:

case WM_LBUTTONDOWN:
    ReleaseCapture ();
    SendMessage (hWnd, WM_NCLBUTTONBUTON, HTCAPTION, 0);
    break;
于 2012-11-02T09:29:57.257 回答