Module1 Public Const SW_SHOWNORMAL = 1 Public Const CBS_DROPDOWNLIST = &H3& Public Const WS_CHILD = &H40000000Public Const CB_ADDSTRING = &H143 Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName 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, lpParam As Any) As Long Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic gCBhwnd As Long Public CBobj As Object Public Sub Main()gCBhwnd& = CreateWindowEx(0&, "COMBOBOX", "CB1", (WS_CHILD Or CBS_DROPDOWNLIST), 58, 90, 85, 25, Form1.hwnd&, 0&, App.hInstance, 0&)Call ShowWindow(Form1.hwnd, SW_SHOWNORMAL) Call ShowWindow(gCBhwnd, SW_SHOWNORMAL) SendMessage gCBhwnd, CB_ADDSTRING, 0&, "aaa" End Sub还有一个窗体Form1
参考这个代码:Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName 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, lpParam As Any) As Long Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long Private Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long Private Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long 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 ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Type WNDCLASS style As Long lpfnwndproc As Long cbClsextra As Long cbWndExtra2 As Long hInstance As Long hIcon As Long hCursor As Long hbrBackground As Long lpszMenuName As String lpszClassName As String End Type
'eine der WNDCLASS hbrBackground-Konstanten Private Const COLOR_BTNSHADOW = 16
'einige der Standard Combobox Stile Private Const CBS_DISABLENOSCROLL = &H800& Private Const CBS_DROPDOWNLIST = &H3& Private Const CBS_NOINTEGRALHEIGHT = &H400&
'eine der Combobox Nachrichten Private Const CB_ADDSTRING = &H143
Dim hWindow As Long Dim hCombo As Long Dim hProcWnd As Long Dim WndClosed As Boolean
'Ermittelt die Funktionsadresse einer übergeben Funktion mit der AdressOf Methode Private Function GetFuncAddress(ByVal Func As Long) As Long GetFuncAddress = Func End Function
'Erstellt ein Fenster und eine Combobox Public Sub Main() Dim Retval As Long, i As Integer Dim WClass As WNDCLASS, Styles As Long
'Classe für ein Fenster erstellen With WClass .hInstance = App.hInstance .lpfnwndproc = GetFuncAddress(AddressOf WndProc) .style = CS_HREDRAW Or CS_VREDRAW Or CS_OWNDC .lpszClassName = "LonelySuicide666_Fenster" .hbrBackground = COLOR_BTNSHADOW .hIcon = ExtractIcon(App.hInstance, "E:\WINDOWS\system32\SHELL32.dll", 2) End With Retval = RegisterClass(WClass) If Retval = 0 Then MsgBox "Die Fensterklasse konnte nicht Registriert werden" Exit Sub End If
'Fenster erstellen Styles = WS_OVERLAPPED Or WS_VISIBLE Or WS_SYSMENU Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX hWindow = CreateWindowEx(0&, "LonelySuicide666_Fenster", "Comobox Style Beispiel", Styles, 0, 0, 640, 480, 0&, 0&, App.hInstance, ByVal 0&) If hWindow = 0 Then MsgBox "Das Fenster konnte nicht erstellt werden" Exit Sub End If
'Combobox erstellen Styles = WS_VISIBLE Or WS_CHILD 'standard Fensterstile Styles = Styles Or CBS_DISABLENOSCROLL Or CBS_NOINTEGRALHEIGHT Or CBS_DROPDOWNLIST hCombo = CreateWindowEx(0&, "combobox", "Combo1", Styles, 140, 50, 300, 300, hWindow, 0&, App.hInstance, ByVal 0&) If hCombo = 0 Then MsgBox "Die Combobox konnte nicht erstellt werden" Else 'Combobox füllen For i = 0 To 10 SendMessage hCombo, CB_ADDSTRING, 0&, ByVal CStr("Eintrag: " & CStr(i)) Next i End If
'Schleife durchlaufen bis das Fenster geschlossen wird Do DoEvents Loop Until WndClosed = True
'Combobox wieder zerstören und Classe Unrigistrieren Call DestroyWindow(hCombo) Call DestroyIcon(WClass.hIcon) Call UnregisterClass("LonelySuicide666_Fenster", App.hInstance) End Sub 'Empfängt alle Ereignisse des Fensters (hWindow) Private Function WndProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Nachrichten auswerten Select Case wMsg Case WM_DESTROY 'Beim schließen die Variabel zum schleifen verlassen setzen WndClosed = True End Select
'Standardprozdur aller Fenster aufrufen damit wir nicht 'auf alle Ereiginisse Reagiernen müssen WndProc = DefWindowProc(hWnd, wMsg, wParam, lParam) End Function
Public Const SW_SHOWNORMAL = 1
Public Const CBS_DROPDOWNLIST = &H3&
Public Const WS_CHILD = &H40000000Public Const CB_ADDSTRING = &H143
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName 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, lpParam As Any) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic gCBhwnd As Long
Public CBobj As Object
Public Sub Main()gCBhwnd& = CreateWindowEx(0&, "COMBOBOX", "CB1", (WS_CHILD Or CBS_DROPDOWNLIST), 58, 90, 85, 25, Form1.hwnd&, 0&, App.hInstance, 0&)Call ShowWindow(Form1.hwnd, SW_SHOWNORMAL)
Call ShowWindow(gCBhwnd, SW_SHOWNORMAL)
SendMessage gCBhwnd, CB_ADDSTRING, 0&, "aaa"
End Sub还有一个窗体Form1
试试可以,真正用很麻烦,建议看 vc 得书
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName 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, lpParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
Private Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
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 ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Type WNDCLASS
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
'eine der WNDCLASS hbrBackground-Konstanten
Private Const COLOR_BTNSHADOW = 16
'einige der WNDCLASS style-Konstanten
Private Const CS_HREDRAW = &H2
Private Const CS_VREDRAW = &H1
Private Const CS_OWNDC = &H20
'eine der Get-/SetWindowLong nIndex-Konstanten
Private Const GWL_WNDPROC = (-4)
'eine der Standard Fensternachrichten
Private Const WM_DESTROY = &H2 'Das Fenster wird zerstört
'einige der Standard Fensterstile
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WS_OVERLAPPED = &H0&
Private Const WS_SYSMENU = &H80000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
'einige der Standard Combobox Stile
Private Const CBS_DISABLENOSCROLL = &H800&
Private Const CBS_DROPDOWNLIST = &H3&
Private Const CBS_NOINTEGRALHEIGHT = &H400&
'eine der Combobox Nachrichten
Private Const CB_ADDSTRING = &H143
Dim hWindow As Long
Dim hCombo As Long
Dim hProcWnd As Long
Dim WndClosed As Boolean
'Ermittelt die Funktionsadresse einer übergeben Funktion mit der AdressOf Methode
Private Function GetFuncAddress(ByVal Func As Long) As Long
GetFuncAddress = Func
End Function
'Erstellt ein Fenster und eine Combobox
Public Sub Main()
Dim Retval As Long, i As Integer
Dim WClass As WNDCLASS, Styles As Long
'Classe für ein Fenster erstellen
With WClass
.hInstance = App.hInstance
.lpfnwndproc = GetFuncAddress(AddressOf WndProc)
.style = CS_HREDRAW Or CS_VREDRAW Or CS_OWNDC
.lpszClassName = "LonelySuicide666_Fenster"
.hbrBackground = COLOR_BTNSHADOW
.hIcon = ExtractIcon(App.hInstance, "E:\WINDOWS\system32\SHELL32.dll", 2)
End With
Retval = RegisterClass(WClass)
If Retval = 0 Then
MsgBox "Die Fensterklasse konnte nicht Registriert werden"
Exit Sub
End If
'Fenster erstellen
Styles = WS_OVERLAPPED Or WS_VISIBLE Or WS_SYSMENU Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
hWindow = CreateWindowEx(0&, "LonelySuicide666_Fenster", "Comobox Style Beispiel", Styles, 0, 0, 640, 480, 0&, 0&, App.hInstance, ByVal 0&)
If hWindow = 0 Then
MsgBox "Das Fenster konnte nicht erstellt werden"
Exit Sub
End If
'Combobox erstellen
Styles = WS_VISIBLE Or WS_CHILD 'standard Fensterstile
Styles = Styles Or CBS_DISABLENOSCROLL Or CBS_NOINTEGRALHEIGHT Or CBS_DROPDOWNLIST
hCombo = CreateWindowEx(0&, "combobox", "Combo1", Styles, 140, 50, 300, 300, hWindow, 0&, App.hInstance, ByVal 0&)
If hCombo = 0 Then
MsgBox "Die Combobox konnte nicht erstellt werden"
Else
'Combobox füllen
For i = 0 To 10
SendMessage hCombo, CB_ADDSTRING, 0&, ByVal CStr("Eintrag: " & CStr(i))
Next i
End If
'Schleife durchlaufen bis das Fenster geschlossen wird
Do
DoEvents
Loop Until WndClosed = True
'Combobox wieder zerstören und Classe Unrigistrieren
Call DestroyWindow(hCombo)
Call DestroyIcon(WClass.hIcon)
Call UnregisterClass("LonelySuicide666_Fenster", App.hInstance)
End Sub
'Empfängt alle Ereignisse des Fensters (hWindow)
Private Function WndProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Nachrichten auswerten
Select Case wMsg
Case WM_DESTROY 'Beim schließen die Variabel zum schleifen verlassen setzen
WndClosed = True
End Select
'Standardprozdur aller Fenster aufrufen damit wir nicht
'auf alle Ereiginisse Reagiernen müssen
WndProc = DefWindowProc(hWnd, wMsg, wParam, lParam)
End Function
TechnoFantasy(冰儿马甲www.applevb.com) 兄,先谢谢了!第一发帖听说要给点数!怎么给啊在哪里点?