-
July 27th, 2009, 06:47 AM
#1
SendMessage to Excel
Hi, all
Is it possible to send 'CTRL+A' and 'CTRL+C' to MS Excel using SendMessage?
I have tried WM_KEYDOWN and WM_KEYUP Messages for 'CTRL+A' with following code but no success.
Code:
SendMessage(m_fEC2,WM_KEYDOWN, (WPARAM)VK_CONTROL,(LPARAM)1);
SendMessage(m_fEC2,WM_KEYDOWN, (WPARAM)65,(LPARAM)1);
SendMessage(m_fEC2,WM_KEYUP, (WPARAM)VK_CONTROL,(LPARAM)1);
SendMessage(m_fEC2,WM_KEYUP, (WPARAM)65,(LPARAM)1);
m_fEC2 is the handle to the Child window as detected in SPY++.
Difference from SPY++ is only the LPARAM Parameter. How to construct LPARAM parameter for the same? or is there any thing wrong or missing.
Thanx for any kind of help.
Regards,
Shail2k4
Regards,
-
July 27th, 2009, 06:51 AM
#2
Re: SendMessage to Excel
Victor Nijegorodov
-
July 27th, 2009, 06:58 AM
#3
Re: SendMessage to Excel
Originally Posted by VictorN
Try SendInput instead.
Thanx for the reply..
Will it be useful when the windows is not having focus?
In my case the window may not be having focus.
Regards,
Shail2k4
-
July 27th, 2009, 07:03 AM
#4
Re: SendMessage to Excel
Nope... SendInput inserts your commands into the keyboard chain, so it is the same as you pressing the keys yourself. I guess the only thing you can do is set the focus to excel before you send the keys, but I don't think that you want that
-
July 27th, 2009, 07:11 AM
#5
Re: SendMessage to Excel
Originally Posted by Skizmo
Nope... SendInput inserts your commands into the keyboard chain, so it is the same as you pressing the keys yourself. I guess the only thing you can do is set the focus to excel before you send the keys, but I don't think that you want that
Absolutely i cant do that..
What is wrong with the SendMessage?
Again i made a test with the notepad still no success...
Thanx for any kind of help..
Regards,
Shail2k4
-
July 27th, 2009, 03:24 PM
#6
Re: SendMessage to Excel
SendMessage isn't a good choice because it's synchronous so if the target app is hung, your app will hang. SendMessageTimeout would be a better choice.
Unfortunately, it still won't work in this case where you are doing a select all/copy to the clipboard.
If you want to do this, you'll need to set focus on the target application (SetForegroundWindow) and then use SendInput as Victor suggested.
An alternative to this is to use Excell's automation model to connect to the active Excell instance and access the work book from there.
If you can give more specifics on what you are actually trying to do, then we might be able to offer additional alternatives.
-
July 28th, 2009, 09:03 AM
#7
Re: SendMessage to Excel
Originally Posted by Arjay
SendMessage isn't a good choice because it's synchronous so if the target app is hung, your app will hang. SendMessageTimeout would be a better choice.
Unfortunately, it still won't work in this case where you are doing a select all/copy to the clipboard.
If you want to do this, you'll need to set focus on the target application (SetForegroundWindow) and then use SendInput as Victor suggested.
An alternative to this is to use Excell's automation model to connect to the active Excell instance and access the work book from there.
If you can give more specifics on what you are actually trying to do, then we might be able to offer additional alternatives.
Thanx for the reply
Here is the specification of the work that i want to do.
I am having an external application from which i need to capture the data.
There are two possible source of the data.
One is the window with TStringGrid and another is a window containing embedded excel object.
Thanx for any kind of help.
Regards,
Shail2k4
-
July 28th, 2009, 09:49 AM
#8
Re: SendMessage to Excel
SetForegroundWindow and SendInput will get the job done as long as setting focus on the application isn't a problem.
-
July 28th, 2009, 01:55 PM
#9
Re: SendMessage to Excel
SendMessage works perfectly by attaching the remote thread
-
July 28th, 2009, 02:22 PM
#10
Re: SendMessage to Excel
Originally Posted by carl666
SendMessage works perfectly by attaching the remote thread
Not recommended. If you use SendMessage to send a message to an application that is hung, you will hang your app. Try it - just create a simple dialog app, add a button and in the button handler, add a Sleep( 100000 ) command to simulate a hung app. Open the test app, press the button and then use SendMessage from another app to send it a message. The 'sending' app will hang.
-
July 29th, 2009, 01:14 AM
#11
Re: SendMessage to Excel
Originally Posted by Arjay
Not recommended. If you use SendMessage to send a message to an application that is hung, you will hang your app. Try it - just create a simple dialog app, add a button and in the button handler, add a Sleep( 100000 ) command to simulate a hung app. Open the test app, press the button and then use SendMessage from another app to send it a message. The 'sending' app will hang.
In this condition can i make use of PostMessage instead of SendMessage?
-
July 29th, 2009, 06:27 AM
#12
Re: SendMessage to Excel
Originally Posted by carl666
SendMessage works perfectly by attaching the remote thread
I have tried doing the same but no success.
Can u pls provide me some working example?
-
July 29th, 2009, 12:35 PM
#13
Re: SendMessage to Excel
Originally Posted by shail2k4
I have tried doing the same but no success.
Have you tried using SetForegroundWindow and SendInput?
-
July 30th, 2009, 03:13 AM
#14
Re: SendMessage to Excel
Originally Posted by Arjay
Have you tried using SetForegroundWindow and SendInput?
I have tried and its working fine but if the target window is minimized then it is not working.
-
July 30th, 2009, 10:43 AM
#15
Re: SendMessage to Excel
Originally Posted by shail2k4
I have tried and its working fine but if the target window is minimized then it is not working.
Would you expect to be able to type into an app that has focus but is minimized?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|