- 最後登錄
- 2024-9-17
- 在線時間
- 37 小時
- 註冊時間
- 2009-9-18
- 閱讀權限
- 20
- 精華
- 0
- UID
- 7034376
- 帖子
- 73
- 積分
- 22 點
- 潛水值
- 8184 米
| 本帖最後由 Waroger 於 2018-6-29 02:59 PM 編輯
將VB6 的InputBox元件改成下拉式選單,除了讓使用者方便輸入並能限制使用者輸入固定的數值。- '底下在模組
- Private Type POINTAPI
- x As Long
- Y As Long
- End Type
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Private Type WINDOWPLACEMENT
- Length As Long
- flags As Long
- showCmd As Long
- ptMinPosition As POINTAPI
- ptMaxPosition As POINTAPI
- rcNormalPosition As RECT
- End Type
- 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("台北市", "新北市", "台北市", "台中市", "台南市", "高雄市")
- For Each i In s
- cm.AddItem i
- Next
- DestroyWindow GetWindow(.hwnd, GW_CHILD)
- SetWindowLong .hwnd, GWL_STYLE, GetWindowLong(.hwnd, GWL_STYLE) + 1
- End With
- ms = "選擇城市"
- SetTimer hwnd, NV_INPUTBOX, 10, AddressOf chg2ComboBox
- s = InputBox("請選擇所在城市", ms)
- Controls.Remove cm
- If StrPtr(s) Then MsgBox s
- End Sub
複製代碼 ... |
|