VB中如何使用PostMessage移动窗体?

zhujiujun 2006-10-30 02:58:27
先贴我的VC代码
void CPLAYERDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(MK_LBUTTON == nFlags && point.y <= 20)
{
HCURSOR hCursor = LoadCursor(NULL, IDC_SIZEALL);
SetCursor(hCursor);
::PostMessage(GetSafeHwnd(),WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
}

CDialog::OnMouseMove(nFlags, point);
}
上面的VC代码可以实现移动没有Title Bar的窗体
========================================================================
下面,是我VB中的代码(窗体BorderStyle = None)
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim nLParam As Long
Dim blReturn As Boolean

If Button = vbLeftButton Then
nLParam = CInt(Y) * &H10000 + CInt(X)
blReturn = PostMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, nLParam)
End If
End Sub

该段代码blReturn = True,但是窗体无法移动。
请高手指教,谢谢!
...全文
260 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujiujun 2006-10-30
  • 打赏
  • 举报
回复
ReleaseCapture
The ReleaseCapture function releases the mouse capture from a window in the current thread and restores normal mouse input processing. A window that has captured the mouse receives all mouse input, regardless of the position of the cursor, except when a mouse button is clicked while the cursor hot spot is in the window of another thread.

谢谢楼上两位。

不好意思没分了,顺便再问个问题:窗体BorderStyle = None的时候,如何拖动边框实现窗体的缩放?需要用那个消息?
谢谢!

yachong 2006-10-30
  • 打赏
  • 举报
回复
ReleaseCapture这个API函数一定要调用
yachong 2006-10-30
  • 打赏
  • 举报
回复
楼上正解,半句废话都没有
Hassle 2006-10-30
  • 打赏
  • 举报
回复
Option Explicit

Private Const WM_NCLBUTTONDOWN = &HA1

Private Const HTCAPTION = 2

Private Declare Sub ReleaseCapture Lib "User32" ()

Private Declare Function PostMessage Lib "User32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
ReleaseCapture
PostMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
End If
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧