开发者

How can I override the close button on a third-party application so that it minimizes instead? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
开发者_如何转开发

Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist

Closed 9 years ago.

Improve this question

I would like to override the close button on a third-party application so that it causes the application to be minimized instead. I do not have source code for the target application.

  • Can I write such thing in C#? Or do I need to use C++?
  • How do I write this kind of hook? Do I need a process running or would a driver/dll/service suffice?

As far as I got researching I think I have to do something like this but I don't know how exactly:

A WH_GETMESSAGE hook to override WM_CLOSE to set the Windows status to WS_MINIMIZE.


You can do it in both C++ and C#. To do this, you would have to hook into the applications message loop and override the WM_CLOSE message to WM_MINIMIZE. To hook into any process that's running you can use:

  1. Microsoft Detours (Commercial and not free if I remember correctly) (http://research.microsoft.com/en-us/projects/detours/)

  2. EasyHook (Open source under LGPL) (http://easyhook.codeplex.com/)

I've used EasyHook and I was very satisfied with the results. It gives you really nice features like starting up a process with the hooks attached OR attaching hooks to already running processes. Also, it provides you with both managed(C#) and native hooking libraries. I'd recommend you take a look at it...


For C# this can be done in a very simple manner:

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (!realClose)
        {
            e.Cancel = true;
            this.WindowState = FormWindowState.Minimized;
        }
    }

Where realClose is a boolean you set to true when you DO want the application to close (e.g. not when the user presses the close button, rather when he uses file -> exit or some such)


Don't do that. Disable the close button. Provide a minimize button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜