Tuesday, February 21, 2006

to automatically select the file (work around to set the file name in html programatically) call the below function after calling the click event of the file field.



Option Explicit
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 GetDesktopWindow Lib "user32" () As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Public Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Public Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Public Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hWnd As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_SETFOCUS = &H7
Public Const WM_KEYDOWN = &H100
Public Const WM_CHAR = &H102
Public Const WM_KEYUP = &H101
Public strPathToSet As String
Public openHwnd As Long
Const BM_CLICK = &HF5
'in a form
Public Sub getHandleOfBrowse(strPath As String)
strPathToSet = ""
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Form1.AutoRedraw = True
Dim browseWindow As Long
While browseWindow = 0
browseWindow = FindWindow(vbNullString, "Choose file")
DoEvents
Sleep (100)
Wend

strPathToSet = strPath
EnumChildWindows browseWindow, AddressOf EnumChildProc, ByVal 0&
If openHwnd <> 0 Then
Call SendMessage(openHwnd, BM_CLICK, 0, 0)
End If

End Sub


Public Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength(hWnd) + 1)
'get the window text
GetWindowText hWnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then
Form1.Print "Window name--->" & sSave
If sSave = "&Open" Then
openHwnd = hWnd
End If
Else
Dim lpClassName As String
lpClassName = Space(256)
'retrieve the class name
Dim retVal As Integer
retVal = GetClassName(hWnd, lpClassName, 256)
lpClassName = Left(lpClassName, retVal)
Form1.Print "Window Class --->" & lpClassName
If lpClassName = "Edit" Then
Call MySendKeys(strPathToSet, hWnd)
strPathToSet = ""
End If
End If
'continue enumeration
EnumChildProc = 1
End Function




Public Function MySendKeys(Msg As String, Handle As Long)
Const WM_CHAR As Long = &H102
Dim i As Integer, Key As Long, CharCode As String
For i = 1 To Len(Msg)
CharCode = Asc(Mid(Msg, i, 1))
SendMessage Handle, WM_CHAR, CharCode, MapVirtualKey(Key, 0)
Next i
End Function


Web Hosting Cheap PHP Plans Also at For free flags of the world