Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public ms As String, cm As ComboBox
Public Sub chg2ComboBox(ByVal h As Long, ByVal m As Long, ByVal i As Long, ByVal t As Long)
Dim x As Long, k As String
Static f As Long, tmp As String, b As Boolean
x = FindWindow("#32770", ms)
If x Then
If b Then
k = cm
If tmp <> k Then SetWindowText f, k: tmp = k
Else
f = FindWindowEx(x, ByVal 0&, "Edit", vbNullString)
If f Then
Dim w As WINDOWPLACEMENT
w.Length = Len(w)
GetWindowPlacement f, w
SetParent cm.hwnd, x
SetWindowPlacement cm.hwnd, w
w.showCmd = 0
SetWindowPlacement f, w
b = True
End If
End If
Else
b = False: f = 0: tmp = ""
KillTimer h, i
End If
End Sub
'------------------------------------
'底下在表單,置放一個CommandButton
Const GW_CHILD = 5
Const GWL_STYLE = (-16)
Const NV_INPUTBOX As Long = &H5000&
Private Sub Command1_Click()
Dim i, s
Set cm = Controls.Add("VB.ComboBox", "Combo1")
With cm
.FontName = "微軟正黑體"
.FontItalic = True
.ForeColor = vbRed
.FontSize = 9
.Visible = True
s = Array("台北市", "新北市", "台北市", "台中市", "台南市", "高雄市")