Страница: 1 |
|
Вопрос: Перемещение контролла
|
Добавлено: 08.10.10 18:36
|
|
Автор вопроса: Игорь | ICQ: 457394129
|
В общем нарыл функции, пытаюсь таскать контролл по форме:
Call ReleaseCapture
Call SendMessage(Component(Index).hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
Контролл та таскается, тока вот его координаты не обновляются, то бишь что Left что Top остаются первоначальными, что посоветуете?
Ответить
|
Номер ответа: 2 Автор ответа: Just
Вопросов: 4 Ответов: 330
|
Профиль | | #2
|
Добавлено: 08.10.10 22:41
|
вот модуль который я делал для своих нужд (все лишнее я убрал, вызывать просто: "MoveObject хэндл_объекта"
'форма
-
- Private Sub Picture1_Click()
- MoveObject Picture1.hwnd
- End Sub
'модуль
-
- Option Explicit
-
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
- Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function ReleaseCapture Lib "user32" () As Long
- Private Const WM_NCLBUTTONDOWN = &HA1&
- Private Const HTCAPTION = 2&
-
- Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
- Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
- Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
-
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
-
- Private Type POINTAPI
- X As Long
- y As Long
- End Type
-
- Private CurPos As POINTAPI
- Private rcWnd As RECT
-
-
- Public Function MoveObject(lHwnd As Long) As Boolean
- BringWindowToTop lHwnd
- ReleaseCapture
- SendMessage lHwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
- MoveObject = PlaneObject(lHwnd)
- End Function
-
-
- Private Function PlaneObject(lHwnd As Long) As Boolean
- Dim lRet As Long, lParentHeight As Long
- Dim lObjectTop As Long, lObjectLeft As Long, lObjectRight As Long, lObjectBottom As Long, lObjectHeight As Long, lObjectWidth As Long
-
- lRet = GetWindowRect(lHwnd, rcWnd)
- If lRet = 0 Then PlaneObject = False: Exit Function
- CurPos.X = rcWnd.Left
- CurPos.y = rcWnd.Top
- lRet = ScreenToClient(GetParent(lHwnd), CurPos)
- If lRet = 0 Then PlaneObject = False: Exit Function
- lObjectLeft = CurPos.X
- lObjectTop = CurPos.y
- CurPos.X = rcWnd.Right
- CurPos.y = rcWnd.Bottom
- lRet = ScreenToClient(GetParent(lHwnd), CurPos)
- If lRet = 0 Then PlaneObject = False: Exit Function
- lObjectRight = CurPos.X
- lObjectBottom = CurPos.y
- lObjectWidth = lObjectRight - lObjectLeft
- lObjectHeight = lObjectBottom - lObjectTop
-
- lRet = GetWindowRect(GetParent(lHwnd), rcWnd)
- If lRet = 0 Then PlaneObject = False: Exit Function
- CurPos.X = rcWnd.Top
- CurPos.y = rcWnd.Bottom
- lRet = ScreenToClient(GetParent(lHwnd), CurPos)
- If lRet = 0 Then PlaneObject = False: Exit Function
- lParentHeight = CurPos.y
-
- If lObjectTop < 0 Then
- lObjectTop = 0
- ElseIf (lObjectTop + lObjectHeight) > lParentHeight Then
- lObjectTop = (lParentHeight - lObjectHeight)
-
- End If
-
- lRet = MoveWindow(lHwnd, lObjectLeft, lObjectTop, lObjectWidth, lObjectHeight, 1)
-
- If lRet <> 0 Then
- PlaneObject = True
- Else
- PlaneObject = False
- End If
- End Function
Ответить
|
Страница: 1 |
Поиск по форуму