|
-
Jun 7th, 2006, 04:49 AM
#1
[RESOLVED] Shelling around
I know how to use the shell command to start a program from within my own. But I'd like do something more complicated:
1. Start another app.
2. Select a menu option: open a specific file.
3. Then use another menu to make a change (edit a textbox)
4. And finally select the save command in the file menu and give the file a new name.
5. Exit from the app.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 7th, 2006, 05:04 AM
#2
Re: Shelling around
Most of it can be done using SendMessage / PostMessage API
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 7th, 2006, 05:07 AM
#3
Re: Shelling around
And if you can open the File by supplying a commandline parameter then that would cut down a lot of stuff you'd have to do
-
Jun 7th, 2006, 05:52 AM
#4
Re: Shelling around
 Originally Posted by Shuja Ali
Thank you, but I'm afraid I don't quite understand what the (last 2) parameters exactly mean in the function calls.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 7th, 2006, 05:56 AM
#5
Re: Shelling around
the last two parameters (wParam & lParam) are dependent on which message you are sending / posting.
Search for the message at http://www.msdn.com to find out what values they should be
-
Jun 7th, 2006, 06:02 AM
#6
Re: Shelling around
The last two parameters are actually the additional input that you need to send to the application. If you search MSDN you will get more information regarding these API's.
Also there will be lot of samples here on VBF, just do a search.
Edit--
I have become slow again.
Last edited by Shuja Ali; Jun 7th, 2006 at 06:05 AM.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 7th, 2006, 06:53 AM
#7
Re: Shelling around
 Originally Posted by bushmobile
the last two parameters (wParam & lParam) are dependent on which message you are sending / posting.
Search for the message at http://www.msdn.com to find out what values they should be
I'll stop by MSDN as soon as I can. Thanx.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 7th, 2006, 06:54 AM
#8
Re: Shelling around
 Originally Posted by Shuja Ali
The last two parameters are actually the additional input that you need to send to the application. If you search MSDN you will get more information regarding these API's.
Also there will be lot of samples here on VBF, just do a search.
Edit--
I have become slow again. 
All right, I will do a search.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 8th, 2006, 12:19 PM
#9
Re: Shelling around
After all I've found I can possibly do it by shelling the other app and using sendkeys. Is there any reason why I shouldn't go this way or is there any trouble that can be anticipated?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 8th, 2006, 02:38 PM
#10
Re: Shelling around
SendKeys is notoriously unreliable - it only sends key-presses to the active window and you have no idea what might steal focus on your users computers. You might be able to get away one or two key-presses but the more you use then the more likely you are to run into trouble.
-
Jun 8th, 2006, 03:33 PM
#11
Re: Shelling around
The thing is I haven't been able to find any decent explanation for this special intended use of SendMessage. Is there any place where all the possible messages and parameters are catalogued?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 8th, 2006, 03:59 PM
#12
Re: Shelling around
you can send any windows message using SendMessage and PostMessage - the list must run into thousands. You'll find them all at www.msdn.com but you have to have a rough idea at what your looking for as they are catalogued in groups (like messages for the ListBox etc.)
Try searching for examples of what you want to do on the forum - you'll then find the messages that are used and you can look them up for more information.
-
Jun 8th, 2006, 04:09 PM
#13
Re: Shelling around
 Originally Posted by bushmobile
you can send any windows message using SendMessage and PostMessage - the list must run into thousands. You'll find them all at www.msdn.com but you have to have a rough idea at what your looking for as they are catalogued in groups (like messages for the ListBox etc.)
Try searching for examples of what you want to do on the forum - you'll then find the messages that are used and you can look them up for more information.
As you say, it's not easy to find your way to the correct place in msdn. I tried already to search the forums with poor luck so far... but I haven't surrendered yet.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 8th, 2006, 04:11 PM
#14
Re: Shelling around
well if your trying to change the text in a textbox you'll want the WM_SETTEXT message; To close an app - WM_CLOSE; press a button - BM_CLICK
you want to try and make this as simple as possible
-
Jun 8th, 2006, 04:26 PM
#15
Re: Shelling around
 Originally Posted by bushmobile
well if your trying to change the text in a textbox you'll want the WM_SETTEXT message; To close an app - WM_CLOSE; press a button - BM_CLICK
you want to try and make this as simple as possible
Well, to begin with, how do I get a handle to the external application?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 8th, 2006, 04:28 PM
#16
Re: Shelling around
 Originally Posted by krtxmrtz
Well, to begin with, how do I get a handle to the external application?
...and how do I specify which textbox or button I need to type to / click on?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 8th, 2006, 05:00 PM
#17
Re: Shelling around
To find the top-level window - you'll have to use FindWindow API,
to find the handles of the child windows (buttons / textboxes etc.) use FindWindowEx
if you do a search for those (forum/google/msdn - look at AllApi.net too) you'll find lots of information.
-
Jun 9th, 2006, 03:29 AM
#18
Re: Shelling around
 Originally Posted by bushmobile
well if your trying to change the text in a textbox you'll want the WM_SETTEXT message; To close an app - WM_CLOSE; press a button - BM_CLICK
Btw, how about clicking on a menu? Or perhaps I should rather send Alt/whatever to the form?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 9th, 2006, 04:15 AM
#19
Re: Shelling around
Check out WM_COMMAND. The GetMenu & GetSubMenu & GetMenuItemInfo APIs may also be of use to you.
-
Jun 9th, 2006, 05:36 AM
#20
Re: Shelling around
 Originally Posted by bushmobile
Check out WM_COMMAND. The GetMenu & GetSubMenu & GetMenuItemInfo APIs may also be of use to you.
All right, but before I get into the various menu related API calls, isn't it possible to use SendMessage to send text directly to the window, similarly to SendKeys? Looks easier to me sending e.g. "Alt/p" to activate "open file". What's the message in this case? (second parameter for SendMessage)
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 9th, 2006, 05:41 AM
#21
Re: Shelling around
if you find the ID of the menu you want to press then the SendMessage will just be a single line:
VB Code:
SendMessage thehWnd, WM_COMMAND, theID, 0&
If you want to send an Alt+P i guess you'll have to use WM_KEYDOWN and then WM_KEYUP - check out the virtual key constants of the keys too. Alt will be VK_ALT or something like that.
-
Jun 9th, 2006, 05:55 AM
#22
Re: Shelling around
 Originally Posted by bushmobile
if you find the ID of the menu you want to press then the SendMessage will just be a single line:
VB Code:
SendMessage thehWnd, WM_COMMAND, theID, 0&
If you want to send an Alt+P i guess you'll have to use WM_KEYDOWN and then WM_KEYUP - check out the virtual key constants of the keys too. Alt will be VK_ALT or something like that.
I've tried this to get the menu id with no success (nothing happens):
VB Code:
'...after shelling MyApp:
hWnd= FindWindow(vbNullString, "MyAppName")
hmnu = GetMenu(hWnd)
hsbmnu = GetSubMenu(hMenu, 0)
SendMessage hWnd, WM_COMMAND, hsbmnu, 0&
... I am sort of groping in the API...
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 9th, 2006, 06:03 AM
#23
Re: Shelling around
that code will get the handle of the first menu (presumably 'File').
You then need to get the MenuID (not handle) of the Open item on that menu. This can be done with GetMenuItemID
You then pass the ID with the WM_COMMAND message, not the handle
-
Jun 9th, 2006, 06:14 AM
#24
Re: Shelling around
 Originally Posted by bushmobile
that code will get the handle of the first menu (presumably 'File').
You then need to get the MenuID (not handle) of the Open item on that menu. This can be done with GetMenuItemID
You then pass the ID with the WM_COMMAND message, not the handle
It finally worked!
Thanks a lot for patiently teaching me this on-the-fly SendMessage course.
But stay tuned, I may be soon asking for more, I'm hungry!!!
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 9th, 2006, 06:16 AM
#25
Re: [RESOLVED] Shelling around
Bushmobile, I tried to rate you up but it seems I must spread reputation elsewhere first. Sorry, some other time...
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 9th, 2006, 06:18 AM
#26
Re: [RESOLVED] Shelling around
no worries
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
|