Public Declare Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" _
(ByVal hInstance As Long, ByVal lpTemplate As Long, ByVal hWndParent As Long, _
ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Long
Public Declare Function EndDialog Lib "user32" _
(ByVal hDlg As Long, ByVal nResult As Long) As Long
Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
(ByVal lpLibFileName As String) As Long
Public Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetDlgItem Lib "user32" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Public Declare Function GetDlgItemText Lib "user32" Alias "GetDlgItemTextA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" _
(ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Const MB_OK = &H0&
Public Const MB_ICONINFORMATION = &H40&
Public Const CB_ADDSTRING = &H143
Public Const WM_INITDIALOG = &H110
Public Const WM_COMMAND = &H111
Public Const IDOK = 1
Public Const IDCANCEL = 2
Public Const BN_CLICKED = 0
Public Const ID_RUN_DIALOG = 1003
Public Const ID_RUN_DIALOG_COMBO = 12298
Public Const ID_RUN_DIALOG_BROWSE_BUTTON = 12288
Private SelectedValue As String
Private OkButtonClicked As Boolean
Private Function TrimZero(str As String) As String
Dim lngPos As Long
lngPos = InStr(str, Chr$(0))
If lngPos > 0 Then
TrimZero = Mid$(str, 1, lngPos - 1)
Else
TrimZero = str
End If
End Function
Public Function DialogBoxProc(ByVal hwndDlg As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim NotidyCode As Long
Dim ItemID As Long
Dim Index As Integer
Dim Str1 As String
Dim hCombo As Long
Dim TempStr As String * 255
If uMsg = WM_COMMAND Then
NotidyCode = wParam \ 65536
ItemID = wParam And 65535
If (ItemID = IDOK Or ItemID = IDCANCEL) And NotidyCode = BN_CLICKED Then
EndDialog hwndDlg, 0
DialogBoxProc = 1
If ItemID = IDOK Then
GetDlgItemText hwndDlg, ID_RUN_DIALOG_COMBO, TempStr, 255
SelectedValue = TrimZero(TempStr)
OkButtonClicked = True
Else
OkButtonClicked = False
SelectedValue = ""
End If
Exit Function
End If
If ItemID = ID_RUN_DIALOG_BROWSE_BUTTON And NotidyCode = BN_CLICKED Then
MessageBox hwndDlg, "You clicked the browse button !", "Browse Button", MB_OK Or MB_ICONINFORMATION
DialogBoxProc = 1
Exit Function
End If
End If
If uMsg = WM_INITDIALOG Then
hCombo = GetDlgItem(hwndDlg, ID_RUN_DIALOG_COMBO)
For Index = 1 To 10
Str1 = "Item Number " & Index
SendMessage hCombo, CB_ADDSTRING, 0, ByVal Str1
Next
End If
DialogBoxProc = 0
End Function
Public Function ShowDialog(hParent As Long, SelValue As String) As Boolean
Dim hShell32 As Long
hShell32 = LoadLibrary("shell32.dll")
If hShell32 <> 0 Then
DialogBoxParam hShell32, ID_RUN_DIALOG, hParent, AddressOf DialogBoxProc, 0
FreeLibrary hShell32
SelValue = SelectedValue
ShowDialog = OkButtonClicked
End If
End Function
|