Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close application window?

Status
Not open for further replies.

Sidro

MIS
Sep 28, 2002
197
0
0
US
hi,
Heres the scenerio.
I have an exe program that uses shellexecute to execute another exe program like notepad for instance.
There would be a notepad window with text and everything.
My question is, how do I close the the notepad window?
I would like to simulate a use closing a window by clicking on the "X" icon box on the top left corner of the window. Can someone give an example? Thanks in advance.
 
Use CreateProcess instead of ShellExecute because the first one returns (as an out parameter) a pointer to a PROCESS_INFORMATION structure whom's members can help you close the child application (by sending messages using SendMessage for example).
You can find child's process window by using EnumWindows and GetWindowThreadProcessId (process' thread ID can be found in the PROCESS_INFORMATION structure that I've mentioned above). After finding the right window, you can use SendMessage to send a WM_CLOSE to that window.

Examples:
1) I know it's VB but it is quite readable: 2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top