I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

August Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi COM / ActiveX / DCOM Topic   Print This     

How do I access menu commands in one program from

How do I access menu commands in one program from in Delphi COM / ActiveX / DCOM topic (part of our Pascal and Delphi Coding group).

Quick Search: commands   program   How do   How do access   menu commands   one program  
Neophyte185
 (Inactive)
Annapolis, MD, USA
I am a neophyte programmer. I have figured out how to generate a simple Delphi 7 form with a button in it which will run an executable.

procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Form1.Handle, 'open', 'c:\E3238s\bin\E3238s.exe',
nil, nil, SW_SHOWNORMAL);
end;
end.

My problem is I need to know how to access the menus that are a part of this executable. For example how would I access the FILE menu in order to select EXIT.
 Posted 15 years ago (Thread Starter)
Comment Quote
About Neophyte185 -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #11171, 5 replies
Thread Started 7/13/2005 12:47:00 PM
View Counter=5851
Last Reply Posted 7/17/2009 2:29:38 PM)
Location=Annapolis, MD, USA  
Joined=15 years ago   MB Posts=2  
William Pantoja
Woodinville, WA, USA

The best way to safely close an application is send a WM_CLOSE message to its main window.  If you have the process id (which you can get if you use CreateProcess), you can enumerate all the top level windows and call GetWindowThreadProcessId on each one until you find the window whose process id matches the process id returned by CreateProcess.  Once that is found, you can post a WM_CLOSE message to that window using SendMessage and it will close the window as if you clicked "Exit".

 

For other commands, you can iterate child windows and post message to the appropriate window.  Using the WM_MENUCOMMAND message you can simulate a menu selection.

 

It can get quite complicated depending on what you want to do but the APIs involved are pretty basic.

---
William Pantoja

Consultant/Software Engineer
ForceOne Technologies, Inc.

 Posted 13 years ago
Comment Quote
About William Pantoja -Collapse +Expand
Visit Profile
Approved member.
Member does not subscribe to this thread.

Post ID #11826 (Level 1.1)  Reply to 11171
Thread Started 6/12/2007 3:18:50 AM
View Counter=2
Location=Woodinville, WA, USA  
Joined=19 years ago   MB Posts=163   KB Posts=1  
Wes Peterson
Prestwood IT
Prestwood IT office in Citrus Heights, CA

I'm very sorry about this tardy reply and, hope, that by now, you've found a solution.

It is one thing to get Windows to launch a program, quite another to get into that other program's internals.

When developers want to provide access to their program's internals, they generally provide an API (Com/Active-X server).  Microsoft has done this for many of their popular programs, and Delphi provides mechanisms for "importing" the interfaces.

If, however, the program you're launching provides no such interface, you're pretty much out of luck - as far as getting at the program's menus.

All is not lost, though.  Just as you can get Windows to launch a program, you can make Windows "kill" a program.  It's a dangerous business, though, because your application has no way of knowing when the other program can be killed without causing data damage.


Wes

Wes Peterson
Senior Software Engineer
Prestwood IT Solutions
http://www.prestwood.com

 Posted 13 years ago
Comment Quote
About Wes Peterson -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Wes Peterson

Wes Peterson is a Senior Programmer Analyst with Prestwood IT Solutions where he develops custom Windows software and custom websites using .Net and Delphi. When Wes is not coding for clients, he participates in this online community. Prior to his 10-year love-affair with Delphi, he worked with several other tools and databases. Currently he specializes in VS.Net using C# and VB.Net. To Wes, the .NET revolution is as exciting as the birth of Delphi.


Post ID #11746 (Level 1.2)  Reply to 11171
Reply Posted 6/4/2007 2:05:02 PM
Location=Prestwood IT office in Citrus Heights, CA 
Joined=16 years ago   MB Posts=158   KB Posts=163   KB Comments=34   BLOG, Topics=20  
Wes Peterson
Prestwood IT
Prestwood IT office in Citrus Heights, CA

>For other commands, you can iterate child windows and post message to the appropriate window.  Using the WM_MENUCOMMAND message you can simulate a menu selection.

 

>It can get quite complicated depending on what you want to do but the APIs involved are pretty basic.

You are absolutely correct, both about the WM_MENUCOMMAND and the potential complexity.

The reason I didn't mention this route - and I pursue it only with great reluctance - is that, without an API (for the other program), it can be very difficult to know the state of the other program and, thus, whether or not it is wise to issue a menu command.

Wes Peterson
Senior Software Engineer
Prestwood IT Solutions
http://www.prestwood.com

 Posted 13 years ago
Comment Quote
About Wes Peterson -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Wes Peterson

Wes Peterson is a Senior Programmer Analyst with Prestwood IT Solutions where he develops custom Windows software and custom websites using .Net and Delphi. When Wes is not coding for clients, he participates in this online community. Prior to his 10-year love-affair with Delphi, he worked with several other tools and databases. Currently he specializes in VS.Net using C# and VB.Net. To Wes, the .NET revolution is as exciting as the birth of Delphi.


Post ID #11830 (Level 1.3)  Reply to 11171
Reply Posted 6/14/2007 9:11:23 PM
Location=Prestwood IT office in Citrus Heights, CA 
Joined=16 years ago   MB Posts=158   KB Posts=163   KB Comments=34   BLOG, Topics=20  
Mark B

Also, consider the very nature of the "Shell" command itself, where you are spawning a new operating system shell for the executable to run within, until it terminates (properly) and the shell dies (hopefully).

 Posted 12 years ago
Comment Quote
About Mark B -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #13021 (Level 1.4)  Reply to 11171
Reply Posted 9/4/2008 8:29:47 PM
Location= 
Joined=12 years ago   MB Posts=1   KB Comments=1  
Most Recent Post
Daniel Kram
-- UNK

If you created the process, then it is quite easy to close it. Here is how I accomplished this task.

uses
  Windows;
...
private
  ProcInfo: TProcessInformation;

function TfrmMyForm.StartProcesses: boolean;
var
  StartInfo:             TStartupInfo;
begin
   FillChar(StartInfo,SizeOf(TStartupInfo),#0);
   FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
   StartInfo.cb := SizeOf(TStartupInfo);
  CreateProcess(nil, PChar('SomeApplicationToStart.exe'), nil, nil,False,
                CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
                nil, nil, StartInfo, ProcInfo);
  Result := True;
end;

now, to close it:

function TfrmMyForm.EndProcess: boolean;
begin
  TerminateProcess(ProcInfo.hProcess,0);
  CloseHandle(ProcInfo.hProcess);
  CloseHandle(ProcInfo.hThread );
  Result := True;
end;

When calling the starting or ending functions, you may want to put the call in a try..except block.

Enjoy.

 Posted 11 years ago
Comment Quote
About Daniel Kram -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #13609 (Level 1.5)  Reply to 11171
Reply Posted 7/17/2009 2:22:11 PM
Location=-- UNK 
Joined=12 years ago   MB Posts=25   KB Posts=4   KB Comments=11  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P154A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #11171 Counter
5851
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech