2

Possible Duplicate:
How to disable the minimize 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?

Community
  • 1
  • 1
raicha101
  • 109
  • 1
  • 7
    Sounds evil... why would you do this? – jball Mar 02 '10 at 20:26
  • dupe: http://stackoverflow.com/questions/319124/how-to-disable-the-minimize-button-in-c (not an _exact_ dupe of the question, but the accepted answer will do what this user wants) – Michael Todd Mar 02 '10 at 20:26
  • 1
    Except if you have really good reason to do this, it's really annoying to don't allow users to manage as they want windows. Think twice before do it. – Boris Guéry Mar 02 '10 at 20:26
  • 2
    @jball: see his other question – Michael Todd Mar 02 '10 at 20:27
  • Sorry for my hasty comments (now deleted). I see that you may have a legitimate reason to want to do this. – Scott Cranfill Mar 02 '10 at 20:28
  • The Windows Toolbar functionality in your other question should automatically handle this. – overslacked Mar 02 '10 at 20:42
  • @Micheal, I can see the other question, but I don't see anything inherint in the idea of an application desktop toolbar that would require it to be un-minimizeable. – jball Mar 03 '10 at 01:10
  • @jball I think the idea is something akin to Windows Sidebar (at least, how it originally worked when released on Vista). Rather than minimizing, Sidebar is always there, and other applications exist "around" it. Not saying it's a great idea, but that's what the OP was shooting for. – Michael Todd Mar 03 '10 at 03:55

7 Answers7

4

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.

Community
  • 1
  • 1
LBushkin
  • 129,300
  • 32
  • 216
  • 265
0

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

LukeN
  • 5,590
  • 1
  • 25
  • 33
0

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".

0

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.

Joshua
  • 40,822
  • 8
  • 72
  • 132
0

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.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
0

Set your window parent of taskbar. Done!

Leo
  • 1,753
  • 3
  • 20
  • 23
-1

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.

dsimcha
  • 67,514
  • 53
  • 213
  • 334
  • Sorry but this is not helpful. I once wanted to make a program that popped up for a few seconds, displaying sentences in a language I was learning. Programs can also be for a personal usage. – glmxndr Mar 02 '10 at 20:47
  • DVDs that act like old VHS tapes are really annoying - you must watch these previews, the menu button is disabled, so you can only skip ahead preview by preview or fastforward the whole time... – jball Mar 02 '10 at 20:49
  • hehe, I know you are getting burned for thinking about the evil stuff, but there's reasons to do it, you can't think of every scenario. What if you just want to implement a feature to pin the window on top? – Richard Anthony Hein Mar 02 '10 at 20:57
  • 1
    @Richard: I actually run an "always on top" tool. If you manually click minimize, it still minimizes the window. It just doesn't allow other windows to hide it. – dsimcha Mar 02 '10 at 21:02
  • Punishable by death?! Excuse me, but **I** am the programmer, and therefore **I** will decide how the computer behaves when any user attempts to run **my** program. The user benefits from **my** work, and that is all. Sorry I had to chime in like this, but your answer is way off, and it appears that your way of thinking is abstracted beyond reality. If any given user *wanted* these kinds of rights, they would not expect an easy-to-use operating system when they buy a new computer, they would hope for a mobo beep instead. Sounds like a perfect world, right?! – Josh Stodola Mar 02 '10 at 21:23
  • @Josh I suppose you think user expectations and common interface and usability practices are silly too, since you're the one putting **your** hard work into **your** program? – jball Mar 02 '10 at 21:36
  • @jball There is no "best practice" regarding user interface and/or usability that can be globally applied. There are too many variants, too many oddball situations, too many different kinds of programs that serve too many different purposes. Closed-minded purists would beg to differ, but most of them are too caught up in ethics to focus on releasing production software. – Josh Stodola Mar 02 '10 at 22:14
  • @jball Oh, and by the way, every "expectation" that any user has today is the byproduct of a programming decision made some time ago. Don't forget it. – Josh Stodola Mar 02 '10 at 22:17
  • 2
    @Josh, and those programming decisions that survived were the ones that produced the most usable and consistent interfaces. I'm not going to presume to tell you what you should and shouldn't forget. – jball Mar 02 '10 at 23:32
  • @Josh: Your program is running on **my machine**. http://www.dailykos.com/story/2010/2/20/839011/-RELOAD:-DVD-Piracy-vs.-DVD-Paying-Customer-%28POLL%29 –  Mar 02 '10 at 23:45
  • @jball I'm glad we understand each other. So... are you saying that there is no possible way that an app could be usable without an option to "minimize"? You can't minize the desktop, does that deem it unusable and worthless? Absolutely not; it disappears when you choose to do something else. Look at the question he asked the other day. Not *everything* conceivable has to be subjected to these so-called programming proverbs. It's a legitimate question, and an answer like this is just (controversial) noise. – Josh Stodola Mar 03 '10 at 00:00
  • @Josh, *So... are you saying that there is no possible way that an app could be usable without an option to "minimize"?* - No, I am saying that it is less usable than it would be with the option. – jball Mar 03 '10 at 00:15
  • -1 Maybe this is for a kiosk where the user is only permitted to interact with this one application. – Jon B Mar 04 '10 at 20:08
  • Whoever voted this down needs remedail training in UI design. @Jon: in kiosk mode what you do is make sure that nothing else is launchable so if they minimize it all they get is a taskbar with one button on it, or perhaps the minimum size window if you reduce it to the point where there's not even a taskbar. – Joshua Mar 05 '10 at 05:20
  • @Joshua - my point is that there may be a valid reason to do this. LBushkin's answer is perfect. He tells the OP how to accomplish his goal, but also warns about the risks of doing so. – Jon B Mar 05 '10 at 12:45