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:===
Postmessage for keys stroke and mouse click in VBA

Question-1 how to do postmessage with simulation key stroke of Alt-s combined keys, and I tried the follows
it should work but it fail ?
PostMessage hdlg, WM_SYSKEYDOWN, &H73&, 0 'Alt-S Down
'PostMessage hdlg, WM_SYSTEMUP, &H73&, 0 'Alt-S Up
'Ascii of S in HEX shoule be 73.
Question-2, I read those post, sometimes, people are using sendmessage, sometime using postmessage
what is the major different, I tried sendmessage for sending alt-s but it not repsone .
Question-3, Should we do coding to a must for including WM_SYSKEYUP/WM_LBUTTONUP when doing WM_SYSKEYDOWN/WM_LBUTTONDOWN for simulating key-stroke and mouse-click that is similar our hand operation, press
key down and key up/( OR mouseclick down/up). I found sometimes the opertioan is also working even wihout
'PostMessage hdlg, WM_SYSTEMUP VBA statement , Why ?
Question-4, what is different we are between using sendmessage and sendlgitemmessage ?
Question-5, WHen we including API lib like Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
why using Alias ,?I know A is for ascill and W is for unicode, how to input the uncode for postmessage when using
Private Declare Function PostMessageW Lib "user32"
Please advise
Duncan
THanks for your reply
1)
Use keybd_event() or SendInput() instead.
http://msdn.microsoft.com/en-us/library/ms646304(v=VS.85).aspx
2 )
SendMessage() blocks the thread until the application processes the message.
PostMessage() sends the message and doesn't care about the return value of wheter the application processed the message, it doesn't block the thread.
3)
Refer to #1
4)
SendMessage() requires a handle to the control which in most cases requires you to walk the chain of controls until you find the one you need to automate.
SendDlgItemMessage() works differently, some windows mostly dialogs in windows have static control ID's associated with them that can be used. This eliminates the requirment of walking the chain of control since you can associate the control of interest with the control ID instead. It will find the particlar control by it's control ID and send the message to that control.
SendDlgItemMessage() is also the same as using SendMessage() and GetDlgItem()
5)
Yes some API use ANSI and WIDE versions particular when dealing with marshaling strings. It's best to use the WIDE versions when possible on Windows NT. The "Alias" is a way to reference the API name and use a different name in your code. For example there is no API function named PostMessage but rather they are exported as PostMessageA and PostMessageW. You can either declare it directly and ignore the "Alias" member OR you can declare it as PostMessage() but then you must use "Alias" so the call knows how to call the *real exported function since PostMessage doesn't exist.