Does anyone know how to send an ENTER key to an OK button on a window not owned by the vb application I'm running? I originally tried using SendInput for it but it does not seem to work. Is there an alternative method to using SendInput?
..the button has the focus, than you can
Elseif that button has not focus, you may try with a dirty (and
dangerous!) trick you can find in attachment
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Private Const BM_SETSTATE = &HF3
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Sub Command1_Click()
Dim hwnd As Long, hchildwnd As Long, t As Long, ret As Long
Dim FileName As String
Dim PlayTime As Long
'Change Try me bellow to the window title with the Ok button.
hwnd = FindWindow(vbNullString, "Try me")
hchildwnd = FindWindowEx(hwnd, ByVal 0&, vbNullString, "Ok")
If hchildwnd > 0 Then
'restore the last button state to normal
Call SendMessage(hchildwnd, BM_SETSTATE, 0, ByVal 0&)
Call SendMessage(hchildwnd, WM_LBUTTONDOWN, ByVal 1&, ByVal 11&)
Call SendMessage(hchildwnd, WM_LBUTTONDOWN, ByVal 1&, ByVal 0&)
Call SendMessage(hchildwnd, WM_LBUTTONUP, ByVal 0&, ByVal 0&)
Call SendMessage(hchildwnd, BM_SETSTATE, ByVal 1&, ByVal 0&)
DoEvents
Call SendMessage(hchildwnd, BM_SETSTATE, 0, ByVal 0&)
End If
End Sub
You lifesaver!!! Thanks for the excellent code. I suspected it could be solved using SendMessage but didn't know about the BM_ constants. Again Many Thanks and five stars.
Cesare,
Thanks for the code but I had already tried something similar. I don't know why it did not work but MKSa's code snippet has solved the problem. Many Thanks.
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
'**************************************
'Windows API/Global Declarations for :A
' Send Key - Send Input
'**************************************
Public Const WM_CHAR = &H102
Public Const VK_RETURN = &HD
Public Const WM_KEYDOWN = &H100
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
if i use the command shell "explorer c:\project1.vbp" the 'download file' window opens (that is, the dialog that has open, save, cancel, and more info. like when you d/l a file off the internet and u can either open or save it). i want it to go directly to the file. so my question is, can I:
a) invoke a keypress event for O or o (therefore 'clicking' the open button).
or,
b) is there a better way to open the file, or invoke the open button 'click' event?
i don't understand anything about the API so please help me if you can without using API.
with above, you're asking explorer to open the vbp file.
Instead, you should do a kind of:
shell "vb6.exe c:\project1.vbp" if you want to open it with vb6
or
shell "explorer c:\" if you want explorer to open on folder where
your vbp is....
Last edited by Cimperiali; May 13th, 2004 at 02:32 AM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Originally posted by Cimperiali
with above, you're asking explorer to open the vbp file.
Instead, you should do a kind of:
shell "vb6.exe c:\project1.vbp" if you want to open it with vb6
or
shell "explorer c:\" if you want explorer to open on folder where
your vbp is....
i've tried this and it doesn't work. have you got any ideas? here is my code:
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.