Я использую такой код:
- Код: Выделить всё
Public Declare Function RegisterClassEx Lib "user32" Alias "RegisterClassExA" (ByRef lpWndClass As WNDCLASSEX) As Long
Public Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpszModuleName As Long) As Long
Public Declare Function GetStockObject Lib "gdi32" (ByVal fnObject As Long) As Long
Public Const WS_POPUP = 80000000
Public Const WS_CHILD = 40000000
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" ( _
ByVal dwExStyle As Long, _
ByVal lpszClassName As String, _
ByVal lpszWindowName As String, _
ByVal dwStyle As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hWndParent As Long, _
ByVal hMenu As Long, _
ByVal hInstance As Long, _
ByVal lpParam As Long) As Long
Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hModule As Long, ByVal lpStr As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'------
Function WindowFunc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WindowFunc = DefWindowProc(hWnd, uMsg, wParam, lParam)
End Function
Private Sub LetLong(ByRef lpLong As Long, ByVal nValue As Long)
lpLong = nValue
End Sub
Public Sub Main()
Dim n(100) As Byte, wnd As Long
Dim wcl As WNDCLASSEX
n(0) = Asc("C")
n(1) = Asc("l")
n(2) = Asc("s")
n(3) = Asc("0")
n(4) = Asc("0")
n(5) = Asc("1")
n(6) = 0
wcl.cbSize = 48
wcl.hInstance = GetModuleHandle(0)
wcl.lpszClassName = VarPtr(n(0))
LetLong wcl.lpfnWndProc, AddressOf Module1.WindowFunc
wcl.style = CS_OWNDC Or CS_HREDRAW Or CS_VREDRAW
wcl.hIcon = 0
wcl.hCursor = LoadCursor(0, &H7F00) 'курсор IDC_ARROW
wcl.lpszMenuName = 0
wcl.cbClsExtra = 0
wcl.cbWndExtra = 0
wcl.hIconSm = 0
wcl.hbrBackground = GetStockObject(0) 'кисть WHITE_BRUSH
RegisterClassEx wcl
Load Form1
Form1.Show
Form1.Hide
wnd = CreateWindowEx(0, "Cls001", "Wnd0001", _
WS_POPUP + WS_CHILD, _
10, 10, 80, 40, _
Form1.myPictureBox.hWnd, 0, 0, 0)
Form1.Show vbModal
End Sub
Всё идёт нормально до вызова CreateWindowEx(). Во время вызова CreateWindowEx() ВБ вылетает с ошибкой! Что я здесь делаю неправильно?
При этом, если создавать окно НЕ дочернее, то есть так:
- Код: Выделить всё
...
wnd = CreateWindowEx(0, "Cls001", "Wnd0001", _
WS_POPUP, _
10, 10, 80, 40, _
0, 0, 0, 0)
...
то оно вроде создаётся нормально (несколько раз вызывается WindowProc)
Заранее спасибо!