找回密碼 或 安全提問
 註冊
|註冊|登錄

伊莉討論區

搜索
尊貴會員無限下載附件伊莉需要你的贊助和支持儲值後自動升級用戶組
office航海王偷拍julia新竹中文高中
続秘湯め北海道藏夏刹那にかisekai a決勝時刻ssis 529

休閒聊天興趣交流學術文化旅遊交流飲食交流家庭事務PC GAMETV GAME
熱門線上其他線上感情感性寵物交流家族門派動漫交流貼圖分享BL/GL
音樂世界影視娛樂女性頻道潮流資訊BT下載區GB下載區下載分享短片
電腦資訊數碼產品手機交流交易廣場網站事務長篇小說體育運動時事經濟
上班一族博彩娛樂

[繁]香格里拉・開拓異

老媽沒收兒子的手機

[繁]我獨自升級08-

中國爛尾樓現狀的小短

泰國 女學生踢球空檔

[DVD簡/日配]劇場版
C & C++ 語言C# 語言Visual Basic 語言PHP 語言JAVA 語言
查看: 3454|回復: 0

[原創] VB6 InputBox改成ComboBox輸入[複製鏈接]

帖子
73
積分
22 點
潛水值
8164 米
發表於 2018-6-29 02:55 PM|顯示全部樓層
若新密碼無法使用,可能是數據未更新。請使用舊密碼看看。
本帖最後由 Waroger 於 2018-6-29 02:59 PM 編輯

將VB6 的InputBox元件改成下拉式選單,除了讓使用者方便輸入並能限制使用者輸入固定的數值。
  1. '底下在模組

  2. Private Type POINTAPI
  3.         x As Long
  4.         Y As Long
  5. End Type

  6. Private Type RECT
  7.         Left As Long
  8.         Top As Long
  9.         Right As Long
  10.         Bottom As Long
  11. End Type
  12. Private Type WINDOWPLACEMENT
  13.         Length As Long
  14.         flags As Long
  15.         showCmd As Long
  16.         ptMinPosition As POINTAPI
  17.         ptMaxPosition As POINTAPI
  18.         rcNormalPosition As RECT
  19. End Type

  20. Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  21. 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
  22. Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
  23. Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
  24. Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
  25. Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  26. Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
  27. Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
  28. Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  29. Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  30. Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  31. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

  32. Public ms As String, cm As ComboBox

  33. Public Sub chg2ComboBox(ByVal h As Long, ByVal m As Long, ByVal i As Long, ByVal t As Long)
  34.     Dim x As Long, k As String
  35.     Static f As Long, tmp As String, b As Boolean
  36.    
  37.     x = FindWindow("#32770", ms)
  38.     If x Then
  39.        If b Then
  40.           k = cm
  41.           If tmp <> k Then SetWindowText f, k: tmp = k
  42.        Else
  43.           f = FindWindowEx(x, ByVal 0&, "Edit", vbNullString)
  44.           If f Then
  45.              Dim w As WINDOWPLACEMENT
  46.             
  47.              w.Length = Len(w)
  48.              GetWindowPlacement f, w
  49.              SetParent cm.hwnd, x
  50.              SetWindowPlacement cm.hwnd, w
  51.              w.showCmd = 0
  52.              SetWindowPlacement f, w
  53.              b = True
  54.           End If
  55.          
  56.        End If
  57.     Else
  58.        b = False: f = 0: tmp = ""
  59.        KillTimer h, i
  60.     End If
  61. End Sub

  62. '------------------------------------
  63. '底下在表單,置放一個CommandButton

  64. Const GW_CHILD = 5
  65. Const GWL_STYLE = (-16)
  66. Const NV_INPUTBOX As Long = &H5000&

  67. Private Sub Command1_Click()
  68.     Dim i, s
  69.    
  70.     Set cm = Controls.Add("VB.ComboBox", "Combo1")
  71.     With cm
  72.          .FontName = "微軟正黑體"
  73.          .FontItalic = True
  74.          .ForeColor = vbRed
  75.          .FontSize = 9
  76.          .Visible = True
  77.          s = Array("台北市", "新北市", "台北市", "台中市", "台南市", "高雄市")
  78.          For Each i In s
  79.              cm.AddItem i
  80.          Next
  81.          DestroyWindow GetWindow(.hwnd, GW_CHILD)
  82.          SetWindowLong .hwnd, GWL_STYLE, GetWindowLong(.hwnd, GWL_STYLE) + 1
  83.     End With
  84.     ms = "選擇城市"
  85.     SetTimer hwnd, NV_INPUTBOX, 10, AddressOf chg2ComboBox
  86.     s = InputBox("請選擇所在城市", ms)
  87.     Controls.Remove cm
  88.     If StrPtr(s) Then MsgBox s
  89. End Sub
複製代碼
...
瀏覽完整內容,請先 註冊登入會員

使用道具檢舉

您需要登錄後才可以回帖 登錄 | 註冊

Powered by Discuz!

© Comsenz Inc.

重要聲明:本討論區是以即時上載留言的方式運作,對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿上傳和撰寫 侵犯版權(未經授權)、粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。
回頂部