Launch the exe file and click on the cross in the upper right corner.

Participant

Member
Joined
Oct 26, 2022
Messages
6
Programming Experience
Beginner
Hello. How the code will look like.
The user clicks twice on the exe file, the console program starts, the console program starts the Skype program, the Skype program is displayed, the console program clicks the cross in the upper right corner of the Skype program, the console program closes.
 
There's no clicking. You will start the program by calling Process.Start. Depending on the application, you will likely be able to close it by calling CloseMainWindow on the Process object.
 
I don't need Skype to shut down. I want the console program to do exactly the click, i.e. make it look like the user clicks on the cross. If the console program does as you wrote, then as I understand it, Skype will close completely.
 
Calling CloseMainWindow on a Process is exactly equivalent to clicking the Close button on the title bar of that process's main window. They both invoke the same command as selecting the Close item on the window's system menu.
 
jmcilhinney, thank you, there is no way to check now, because I have to write code from scratch, and I'm just starting, so it will be a while before I can check your offer.
 
Clicking on the X on a window sends a WM_CLOSE message to that window. Here's the source code for CloseMainWindow() which also sends the WM_CLOSE message.

C#:
public bool CloseMainWindow() {
    IntPtr mainWindowHandle = MainWindowHandle;
    if (mainWindowHandle == (IntPtr)0) return false;
    int style = NativeMethods.GetWindowLong(new HandleRef(this, mainWindowHandle), NativeMethods.GWL_STYLE);
    if ((style & NativeMethods.WS_DISABLED) != 0) return false;
    NativeMethods.PostMessage(new HandleRef(this, mainWindowHandle), NativeMethods.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
    return true;
}
 
Back
Top Bottom