Option Explicit
Const CB_GETCURSEL = &H147
Const CB_GETLBTEXT = &H148
#If VBA7 Then
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare PtrSafe Function GetDlgItem Lib "user32" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long) As LongPtr
Dim hParent As LongPtr, hChild As LongPtr, hCombo As LongPtr, index As LongPtr, size As LongPtr
#Else
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetDlgItem Lib "user32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Dim hParent As Long, hChild As LongPtr, hCombo As Long, index As Long, size As Long
#End If
Sub bangma_Unikey()
Dim bufor As String, text As String, length As Long
hParent = FindWindowEx(0, 0, "#32770", vbNullString)
Do While hParent <> 0
bufor = String(256, Chr(0))
length = GetWindowText(hParent, bufor, 256)
text = Left(bufor, length)
text = Left(text, 6)
If text = "UniKey" Then Exit Do
hParent = FindWindowEx(0, hParent, "#32770", vbNullString)
Loop
If text = "UniKey" Then
hCombo = GetDlgItem(hParent, 1002)
If hCombo <> 0 Then
index = SendMessage(hCombo, CB_GETCURSEL, 0, 0)
If index >= 0 Then
bufor = String(256, Chr(0))
size = SendMessage(hCombo, CB_GETLBTEXT, index, ByVal bufor)
text = Left(bufor, size)
MsgBox "Bang ma dang chon la " & text
End If
End If
End If
End Sub