ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 3 2

7 ѹҤ ..2549
87 Users On-Line.
Visitors - Page views
 8 9 7 3 8 7 5
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ҹ ComboBox Method ͹غ Ѻ Win32 API ѹǡҡѹ

Category »  VB 6/VB.Net
: Webmaster 22/3/2550 1:59:00
(ҹ : 19800) 
ٴ֧ͧͧ Win32 API (Application Programming Interface) ҷ ¤᷺˹ǤѺ ... ͧ سͧҹ͹Ѻ ҤسҨ¹Ҫͺѹ (ҧ͹) ǹ鹰ҹ ´ͧ API ѹü͡Ƕ֧Сѹ 纷Һ͡ ѧҡҹ سШԹҡ͹ѹԴªҧФѺ ... ͧ
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6

Design Time
Design Time

Execute
Execute



' ==========================================================
' ÷ͺºº (Add Item)  ComboBox 
' 1. ¡ Method AddItem 
' 2. ¡ Win32 API (Application Programming Interface)
' URL: http://www.g2gnet.com
' eMail: [email protected]  [email protected]
' ==========================================================

Option Explicit
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
			
' ͸Ժ¨ҡ SendMessage
' hWnd  ѵ (Object)  Control ҵͧõԴ͡Ѻѹ 㹷 ComboBox
' wMsg  觷仺͡ѵҨѹ 㹷͡ ¡á˹Ҥ 143 ҹ 16
' wParam  Param   ˹ҷ  ᵡҧѹ Message ЪԴ
' ͧǹҡҹ ͧ˹ 0  ǹ㹡óչ
' wParam = 0 ¤ ҹ
' lParam  ҷѺ ComboBox 㹷 Ҩҡ strItemText


' ˹Ҥк繡 ¡˹Ҥ 143 Ţҹ 16
Private Const CB_ADDSTRING = &H143

'  ˹ź͡
Private Const CB_DELETESTRING = &H144

'  ˹ҧ͡
Private Const CB_RESETCONTENT = &H14B

' ================================================================
' ˵: ҡس¤Ҥҹ Module (ʡ .BAS)
' سͧ¹ҡ Private  Public ءöͧ繴 ... ͧ
' ǹŴҨդҤ (Constant) Ѻ SendMessage Ҵ¤Ѻ
' ٵѡõ˹Ѻ Control еǴ 
' CB ¶֧ ComboxBox 
' LB ¶֧ ListBox 
' TB ¶֧ TextBox 繵ҧ 繵 () ... 55555 ... ع
' ================================================================


' ͺ¡ Win32 API
Private Sub cmdComboAPI_Click()
    Dim strItemText As String
    Dim CountIndex As Integer
    Dim StartTimer As Double
    
    cmbTest.Clear
    ' Ѻ
    StartTimer = Timer
    ' Ըա¡ҹ Win32 API
    ' ¡âѡ 5000 ¡ 繡ѹѴҢͧùѹҡѹ
    For CountIndex = 1 To 5000
        strItemText = "ӴѺ: " & CStr(CountIndex)
        '  Message 仺͡
        ' ComboxBox ( cmbTest), Ըա (˹ 143 Ţҹ 16), 0 = , к繤 (ByVal) ͧ strItemText
        SendMessage cmbTest.hWnd, CB_ADDSTRING, 0, ByVal strItemText
    Next
    
    ' StartTimer  ҷҡ˹ҡ͹ 觡ФѺ
    ' Timer  һѨغѹ  й 觡ҷشͧ÷ӧҹ
    MsgBox ": " & Format(Timer - StartTimer, "0.000") & " Թҷ", vbOKOnly + vbInformation, " Win32 API"
    
    ' ҡسҡͧ蹡Ѻѹ¡ Clear  ComboBox
    ' 㹡 Clear 觴ѧ ... cmbTest.Clear
    ' Ѻ Win32 API
    ' SendMessage cmbTest.hWnd, CB_RESETCONTENT, 0, 0
    ' 0 Ѻ 0 繤 ҹ wParam, lParam ҵͧкؤ 0 աҹѺ
    
    ' ҡͧź Index ͡ ѧ
    '   Method 㹡 Remove 觴ѧ ... cmbTest.RemoveItem 2
    ' ¤ҵͧź Index = 2 ͡ (鹹Ѻ Index  ComboBox ҡ 0 ФѺ)
    ' Ѻ Win32 API
    ' » API ҧ ҡբͼԴҴԴ  س Index ҡ 0 - 9 سź Index  10
    ' ҡͧ仵Ǩͺͧ ѹ͡س͡ ...  ѹ¡
    ' õǨͺẺ Error  ¡÷ͺҷ Return Ѻ
    ' Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (
    '           .................
    '            ) As Long ҵǹ繤ҷͧ Return Ѻ
    
    ' Dim Result As Long
    ' Result = SendMessage(cmbTest.hWnd, CB_DELETESTRING, 2, 0)
    ' MsgBox Result
    ' óչ Result = 4999
    ' Result = SendMessage(cmbTest.hWnd, CB_DELETESTRING, 20000, 0)
    ' MsgBox Result
    ' óչ Result = -1 蹤 ԴԴҴҹФѺ ... ͧ ... ҷѧ  á
    
    ' ͧ蹴ФѺͧ ... Learning By Doing ѹ ¹  ͧͧԴ+Թҡõ仴
End Sub

' ͺ Method AddItem 
Private Sub cmdComboVB_Click()
    Dim strItemText     As String
    Dim CountIndex        As Integer
    Dim StartTimer        As Double
    
    cmbTest.Clear
    StartTimer = Timer
    ' Ըա ComboBox ¡ҹ Method AddItem 
    ' ¡âѡ 5000 ¡
    For CountIndex = 1 To 5000
        strItemText = "ӴѺ: " & CStr(CountIndex)
        cmbTest.AddItem strItemText
    Next
    MsgBox ": " & Format(Timer - StartTimer, "0.000") & " Թҷ", vbOKOnly + vbInformation, " Method AddItem "
End Sub

Private Sub Form_Load()
    cmbTest.Clear
End Sub

Conclusion:
ѹ¤ҡ API д͡ФѺ ѹҡҡԸաûԫա API ѡɳй֧СѺҳŷ ComboBox 繨ӹǹҡ ͡㹡ùѹ͹ҧй (ԧ) Ӥѭչ ش ѹӤѭ֡ ͧ蹡Ѻ API Ẻ鹰ҹ SendMessage Шҧ (ա) ҡ鹡仾ѲҹѺ Object ʶҹСó Ҩǧҡ͹ öǷҧ֡ҹͻСͺ㹡õѴԹա˹ҤѺ

ѡѧҹͧѡ֡ǵҷᨡ CD ҧ 件֧ǡѺҧਤѡ֡ ѧ͡ ҡԹѺͧѡ֡ (¨) ҹ ... ҧҾĵԡͧҹ 㹨ѧѴ͹Ѻѹ ҧѧդҨ˹ ... ѹ Դ٤Ѻͧ ˹ҡѡ
mov AX, The Dog Ҥ Ŵը AX عѢ Ѻҹ ... 55555

Ǩ仡ѹ˭ 觵͡Ң (ɹФѺ Ӫ) ҡਵҷ չ֡Ҵ ҡҡѲҵͧҡ ͧµͧ仫ԤѺ Ҽͧӷҧѡͧǡѹ


Ẻ Ҥس䢡ͧѺŤꡨҡǷͧâ سͧ¹ (֡Էط) ComboBox Ҫ ʴ㹵˹ Cell ͧԹ Թ ... ᷹ (ҹ ҧԴ ͧСͺ仴¤Ѻ ... ͧ ͧ仡͹ͺ˹Ҽ) 觡óչҳԹѹҨ繨ӹǹҡ ѧ鹵ͧ Win32 API ҪФѺ ԴʴŢŷǴ ... ФѺ ... ػͧ.

 


͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560