开发者

Make program unminimizeable [duplicate]

开发者 https://www.devze.com 2022-12-21 21:59 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How to disable the min开发者_开发百科imize button in C#?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How to disable the min开发者_开发百科imize button in C#?

Is there a way to make a c sharp program impossible to minimize ? Is there a way to stop a program from being affected by the Show Desktop button?


You will need to use the Window Hook API.

This API includes methods that applications like computer-based training programs or Kiosk-based applications use to make themselves the only window that can interact with the user. There are many different methods to hook - but there's an article on MSDN that describes how to use the API from .NET that you may find useful.

There is a particular hook event: HCBT_MINMAX that you can intercept and cancel for your window.

If all you want to do is disable the minimize button in your app you can look at the following question's accepted answer How to disable the minimize button in C#?. However, this will not prevent the app from being hidden if the user clicks Show Desktop, or some other window wants to appear over your application.

One word of caution: You should be very careful about the instances where you choose to write an application that takes over control of a machine in this manner. This is the antithesis of user-friendly design. It's only appropriate in narrow situations, like computer-based training, kiosks, or ATM machine software where you really DO want to completely control the machine.


How about catching the minimize event (or other means of checking wheter the window is currently minimized), and just un-minimize it again?


well, the only way i can think of is to catch the event of minimizing and write a code for that.

I would suggest against it because ultimately, its the user who should decide what he wants to do.

Another approach could be to force the form as a Dialog and topmost with no minimize button. However in this case, the user would be able to minimize it using "Show Desktop".


You can prevent yourself from being minimized but I think the ShowDesktop button does some composting that makes that not preventable w/o setting topmost.


I do not think you should be forcing that on the end-user, after all, they paid for their computer, their windows license, so they should be pretty much be able to do something themselves instead of constraining the end-user to be forced to look at a window that cannot be minimized. That is against the standard guideline that a window has a minimize/maximize/close and a system menu, along with a title...it may sound extremely harsh in saying it...it's akin to asking the end-user having to drive a car without an engine and forcing them to drive by pushing the car forward....

Nonetheless, if you still insist, you can override the WndProc and process the SC_COMMAND for the SC_MINIMIZE message, that will override the default handler for minimize...

        private const int SC_CLOSE = 0xF060;
        private const int SC_MAXIMIZE = 0xF030;
        private const int SC_MINIMIZE = 0xF020;
        private const int SC_MOVE = 0xF010;
        private const int SC_SIZE = 0xF000;
        private const int SC_RESTORE = 0xF120;
        private const int SC_NEXTWINDOW = 0xF040;
        private const int SC_PREVWINDOW = 0xF050;
        private const int WM_MENUSELECT = 0x11F;
        private const int MF_SYSMENU = 0x2000;
        private const int MF_DISABLED = 0x2;
        private const int MF_GRAYED = 0x1;
        private const int MF_HILITE = 0x80;

        static int HiWord(int Number) {
            return (Number >> 16) & 0xffff;
        }

        static int LoWord(int Number) {
            return Number & 0xffff;
        }

        [System.Security.Permissions.SecurityPermission(
            System.Security.Permissions.SecurityAction.LinkDemand,
            Flags = System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
        protected override void WndProc(ref System.Windows.Forms.Message m) {
            int nHiWord = HiWord(m.WParam.ToInt32());
            int nLoWord = LoWord(m.WParam.ToInt32());
            switch (nLoWord) {
                case SC_RESTORE:
                    break;
                case SC_MINIMIZE:
                    // Handle the minimize!
                    break;
                case SC_MAXIMIZE:
                    break;
                case SC_SIZE:
                    break;
                case SC_CLOSE:
                    break;
                case SC_MOVE:
                    break;
                case SC_NEXTWINDOW:
                    break;
           }
            base.WndProc(ref m);
        }

Hope this helps, Best regards, Tom.


Set your window parent of taskbar. Done!


Don't. I wish an API didn't even exist for this. If a user wants to minimize your program, he/she has every right to. Messing with what the user has the right to do w/ his/her own system (think preventing using the back button, preventing minimization, preventing fast forwarding of certain sections of DVDs) should be punishable by death.

0

精彩评论

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

关注公众号