Ask Question Forum:
C
O
M
P
U
T
E
R
2
8
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Y-position of the mouse cursor
Attachment:===
how to send Alt-S in VBA to other window

it doesn't work, I also try WM_SYSKEYDOWN for Alt but it also not response. THe purpise is using for save botton
of Alt-S in download diaglog and (I don't want to use sendigitemmessage hwnd, &H1,BM_CLIC,0 because the function
will hang up if the file is existed until you reply overwrite or not )
PostMessage hdlg, WM_KEYDOWN, &H1F&, 0 'Alt-S
PostMessage hdlg, WM_KEYUP, &H1F&, 0
Please help to point out my mistake for postmessage VBA code
Duncan
<< (I don't want to use sendigitemmessage hwnd, &H1,BM_CLIC,0 because the function will hang up if the file is existed until you reply overwrite or not ) >>
Use the custom implementation to avoid this behavior. The example is below... If the overwrite dialog appears you can automate that also under Windows XP the control ID for "Yes" and "No" are as follows.
Yes = 6
No = 7
'// Usage
Where (hDlg) is the handle to dialog only (The main dialog window handle) you don't need to search deeper since the association of the control is obtained using the control ID. (XP only)
ClickMethod hDlg, 6 '//click yes
ClickMethod hDlg, 7 '//click no
Option Explicit'egl1044Private Const SMTO_NORMAL As Long = &H0&Private Const BM_CLICK As Long = &HF5&Private Declare Function SendMessageTimeoutW Lib "user32.dll" ( _ ByVal hWnd As Long, _ ByVal Msg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long, _ ByVal fuFlags As Long, _ ByVal uTimeout As Long, _ ByRef lpdwResult As Long) As LongPrivate Declare Function GetDlgItem Lib "user32.dll" ( _ ByVal hDlg As Long, _ ByVal nIDDlgItem As Long) As LongPublic Function SendDlgItemMessageTimeout( _ ByVal hWnd As Long, _ ByVal Msg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long ' Custom implementation of SendDlgItemMessage that doesn't ' block the current thread. This is useful for example when ' dialog opens a modal dialog. Dim Success As Long Dim lpResult As Long Success = SendMessageTimeoutW( _ hWnd, _ Msg, _ wParam, _ lParam, _ SMTO_NORMAL, _ 1000, _ lpResult) SendDlgItemMessageTimeout = lpResultEnd FunctionPublic Sub ClickMethod( _ ByVal hDlg As Long, _ ByVal dwId As Long) Dim ctlhWnd As Long ctlhWnd = GetDlgItem(hDlg, dwId) Debug.Print SendDlgItemMessageTimeout(ctlhWnd, BM_CLICK, 0, 0)End Sub
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:
<< (I don't want to use sendigitemmessage hwnd, &H1,BM_CLIC,0 because the function will hang up if the file is existed until you reply overwrite or not ) >>
Use the custom implementation to avoid this behavior. The example is below... If the overwrite dialog appears you can automate that also under Windows XP the control ID for "Yes" and "No" are as follows.
Yes = 6
No = 7
'// Usage
Where (hDlg) is the handle to dialog only (The main dialog window handle) you don't need to search deeper since the association of the control is obtained using the control ID. (XP only)
ClickMethod hDlg, 6 '//click yes
ClickMethod hDlg, 7 '//click no
Option Explicit'egl1044Private Const SMTO_NORMAL As Long = &H0&Private Const BM_CLICK As Long = &HF5&Private Declare Function SendMessageTimeoutW Lib "user32.dll" ( _ ByVal hWnd As Long, _ ByVal Msg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long, _ ByVal fuFlags As Long, _ ByVal uTimeout As Long, _ ByRef lpdwResult As Long) As LongPrivate Declare Function GetDlgItem Lib "user32.dll" ( _ ByVal hDlg As Long, _ ByVal nIDDlgItem As Long) As LongPublic Function SendDlgItemMessageTimeout( _ ByVal hWnd As Long, _ ByVal Msg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long ' Custom implementation of SendDlgItemMessage that doesn't ' block the current thread. This is useful for example when ' dialog opens a modal dialog. Dim Success As Long Dim lpResult As Long Success = SendMessageTimeoutW( _ hWnd, _ Msg, _ wParam, _ lParam, _ SMTO_NORMAL, _ 1000, _ lpResult) SendDlgItemMessageTimeout = lpResultEnd FunctionPublic Sub ClickMethod( _ ByVal hDlg As Long, _ ByVal dwId As Long) Dim ctlhWnd As Long ctlhWnd = GetDlgItem(hDlg, dwId) Debug.Print SendDlgItemMessageTimeout(ctlhWnd, BM_CLICK, 0, 0)End Sub
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55: