how do i prevent "show desktop" or "windows key+m" from minimizing my program?

hi,

i don't want my program to be on "TopMost" but i also don't want it to minimize. Never.

even if i disable the minimize feature, the program can still be minimized by clicking on the "show desktop" icon or pressing Windows Key+M. I'd like to prevent that. Can someone tell me a possible way to do it

btw, the "show desktop" button doesn't trigger the 'resize' or 'changesize' event in the form.

Thanks,


Answer this question

how do i prevent "show desktop" or "windows key+m" from minimizing my program?

  • hugh2005

    i found this code on the web. but it's for delphi...can you help me make into c#

    Set Form1 Properties in the object inspector to
    Border Icons  biMinimize = False
    formstyle  =  stay on top

    procedure TForm1.FormShow(Sender: TObject);
    begin
      setwindowlong(getwindow(self.Handle,GW_OWNER),GWL_STYLE,0);
      setwindowlong(getwindow(self.Handle,GW_OWNER),GWL_EXSTYLE,0);
      self.OnShow:=nil;
    end;

  • Jose Ferreira

    Greetings.

    This is compromising the experience of Windows, you know.

    You could do this by implementing < XML:NAMESPACE PREFIX = MSHelp NS = "http://msdn.microsoft.com/mshelp" />IMessageFilter.PreFilterMessage:
    look for WM_MINIMIZE, restore your window when it is minimized. After a timeout, send it to front. It might work, but is a bad solution. For instance, the user might believe the keyboard input goes to another window, but suddenly you steal the focus.

    You might have experienced that Internet Explorer suddenly takes focus after it has loaded a page. This is very annoying to me. I would not implement that kind of functionality myself.

    As mentioned by Vijaye Raji, handling minimize is insufficient since the z-order of the desktop will be changed so that the desktop is in front of your window.
    If this was not the case, the Delphi source would look promissing.

    I am pretty sure the only way to do this properly is to write a (most likely system-wide) keyboard hook.
    These are generally bad, since they are changes to how the OS works and requires some nasty priveleges (at least they should).
    Also, it is not in the domain of .NET programming. If you really want to do it, ask in eg. newsgroup microsoft.public.win32.programmer.kernel.

    If you go for it...
    You must write a little dll [in C/WINAPI, please] which exports a function you hook into the keyboard chain. This function could filter out the m-key when the windows-key is pressed. If you do this the wrong way, you can for instance loose the m-key (not only for your program) or the entire keyboard.

    Hope this is to any help
    Gorm Braarvig.

  • John Carter

    could you please elaborate a little what do you mean by subclassing the form and how do I catch SW_MINIMIZE wndproc

    thanks,

  • Matt Neerincx

    yes, i know what you mean. but i'm designing this program for myself.

    the purpose of the program is to be a semi-transparent textbox always sitting on my desktop. it will be the place where i can type notes and things to do and have them always in front of me.

  • PadamPadam

    I don't think that code is going to help you get the behavior you're looking for.  But if you're interested, the Delphi code translates to:

            uint GW_OWNER = 4;
            int GWL_STYLE = -16;
            int GWL_EXSTYLE = -20;

            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern long SetWindowLong(IntPtr hWnd, int index, long longValue);

            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern IntPtr GetWindow(IntPtr hWnd, uint cmd);


            private void Form1_Shown(object sender, EventArgs e)
            {
                this.MinimizeBox = false;
                SetWindowLong(GetWindow(this.Handle, GW_OWNER), GWL_STYLE, 0);
                SetWindowLong(GetWindow(this.Handle, GW_OWNER), GWL_EXSTYLE, 0);           
            }


  • MartinSGill

    For the heck of it...I tried to to do this with Desawares subclassing ocx. (the best I know of)

    You can stop the minimize event with this....but WinKey m...will always minimize it.

    Looks like the only way is the way Gorm posted....trap the m key.

  • Wail_gsm

    This is going to be tricky.  ShowDesktop, after it minimizes all "minimizable" windows, changes the z-order of the desktop window to make it come up.  So, you probably won't get any notification that you can listen to and act on.  So, I'm not sure if this is even possible.
  • Lekinho

    thank you for the help and information. it's very beneficial.

    there is a program called DeskLook. that program also needs to be on the desktop all the time, the way it got around this problem is by actually drawing itself on the wallpaper. weird solution.

    i appreciate your advice on the newsgroups and the other comments.

    thanks.

    msafi

  • Srinivas Lingineni

    you're right. it didn't produce the behavior i want.
  • di96rtpn

    You can't.  And it's probably not a good idea to do so either - imagine if some other program did that when you really wanted to see the desktop!
  • sbrickey

    Look into subclassing your form. Trap the SW_MINIMIZE message.

  • how do i prevent "show desktop" or "windows key+m" from minimizing my program?