Naked » 02.12.2005 (Пт) 19:15
пишу как есть на самом деле (немножко изменил)
в VB создаю модуль класса, обзываю ClassXXX. В нем пишу
Option Explicit
Event Click()
Dim hwnd As Long
Dim hdc As Long
Dim ParentHwnd As Long
Dim mWndProcOrg As Long
Private Sub Hook(hwnd As Long)
mWndProcOrg = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf ProcXXX)
Call SetWindowLong(hwnd, GWL_USERDATA, ObjPtr(Me))
End Sub
Private Sub UnHook(hwnd As Long)
Call SetWindowLong(hwnd, GWL_WNDPROC, mWndProcOrg)
End Sub
Function Create(nLeft As Long, nTop as long, nWidth As Long, nHeight as long, nParent As Long) As Long
hwnd = CreateClass("xxx", "", COLOR_BTNFACE, CS_DBLCLKS + CS_PARENTDC, WS_CHILD Or WS_VISIBLE, 0, nLeft, nTop, nWidth, nHeight, nParent)
Call Hook(hwnd)
Create = hwnd
End Function
Private Sub Class_Terminate()
Call UnHook(hwnd)
Call DestroyWindow(hwnd)
End Sub
Friend Function WindowProc(ByVal hwnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case message
Case WM_LBUTTONDOWN
Call SetCapture(hwnd)
WindowProc = CallWindowProc(mWndProcOrg, hwnd, message, wParam, lParam)
Case WM_LBUTTONUP
Call ReleaseCapture
WindowProc = CallWindowProc(mWndProcOrg, hwnd, message, wParam, lParam)
Case WM_SETFOCUS
msgbox "SETFOCUS"
WindowProc = CallWindowProc(mWndProcOrg, hwnd, message, wParam, lParam)
Case WM_KILLFOCUS
msgbox "KILLFOCUS"
WindowProc = CallWindowProc(mWndProcOrg, hwnd, message, wParam, lParam)
Case Else
WindowProc = CallWindowProc(mWndProcOrg, hwnd, message, wParam, lParam)
End Select
End Function
Создаю модуль название не важно
Dim ctlXXX As ClassXXX
Dim ptrObject As Long
Function ProcXXX(ByVal hwnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
ptrObject = GetWindowLong(hwnd, GWL_USERDATA)
Call CopyMemory(ctlXXX, ptrObject, 4)
ProcXXX = ctlXXX.WindowProc(hwnd, message, wParam, lParam)
Call CopyMemory(ctlXXX, 0&, 4)
Set ctlXXX = Nothing
End Function
Function CreateClass(clsName As String, clsCaption As String, nBackgrd As Long, clsStyle As Long, nStyle As Long, nStyleEx As Long, nLeft As Long, nTop As Long, nWidth As Long, nHeight As Long, nParent As Long) As Long
Dim hwnd As Long
Dim wndcls As WNDCLASS
wndcls.style = clsStyle
wndcls.lpfnwndproc = GetWndProc(AddressOf WndProc)
wndcls.hInstance = App.hInstance
wndcls.hCursor = LoadCursor(0, IDC_ARROW)
wndcls.hbrBackground = nBackgrd
wndcls.lpszClassName = clsName
Call RegisterClass(wndcls)
hwnd = CreateWindowEx(nStyleEx, clsName, clsCaption, nStyle Or WS_CLIPSIBLINGS Or WS_CLIPCHILDREN, nLeft, nTop, nWidth, nHeight, nParent, 0, App.hInstance, ByVal 0&)
CreateClass = hwnd
Call UnregisterClass(clsName, App.hInstance)
End Function
Private Function WndProc(ByVal hwnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WndProc = DefWindowProc(hwnd, message, wParam, lParam)
End Function
Private Function GetWndProc(ByVal lWndProc As Long) As Long
GetWndProc = lWndProc
End Function
переходим к форме
Dim xxx As New ClassXXX
private sub form_load()
xxx.Create 0, 0, 100, 100, PalitraHwnd
end sub
ANDLL и ошибки вроде не выскакивают
ANDLL насчет 4 пункта, да, создается окно внутри другого
как только убираю WS_CHILD, все сообщения срабатывают, но при этом контрол не имеет родителя и болтается на рабочем столе