0

I have two windows form MainForm and MinimizedMainForm. I want to disable Windows+D for both the forms. Parent of both forms is a third form FormBase. I have used following code for disabling the Windows+D

private const in GWL_HWNDPARENT =-8

IntPtr hprog = NativeMethods.FindWindowEx(NativeMethods.FindWindowEx(NativeMethods.FindWindow("Progman", "Program Manager"),
                          IntPtr.Zero, "SHELLDLL_DefView", ""),
                          IntPtr.Zero, "SysListView32", "FolderView");
        NativeMethods.SetWindowLong(this.Handle, GWL_HWNDPARENT, hprog);

Problem I am facing is my MainForm is never getting minimized if I press Win+D. and for first launch of MinimizedForm if I i press Win+D it doesnt get minimized. But for second+ time Load of minimizedMainForm if I press Win+D , Form gets minimized. I have added above code on the FormLoad event of both the forms. MinimizedMainForm is opened when i click on panel on MainForm and vice versa. MainForm is the starting form of my project.

What should I do to stop the form from minimizing on 2nd+ loadForm events?

C.M.W.
  • 133
  • 1
  • 8
  • 18

2 Answers2

0

Maybe instead of preventing minimizing of window what can be minimized, you have to create window what can't be minimized instead: MinimizeBox = false ? (it can't be that simple I bet, but i can't write comments, so here comes a solution =D)

Sinatr
  • 20,892
  • 15
  • 90
  • 319
  • From user experience, you cannot really prevent minimizing. This only means that as soon as you interact with the desktop, the app will pop up again - in between it will be minimized though and show the desktop. – Andreas Reiff Feb 15 '13 at 16:05
0

Basically Win + D is not for minimizing the windows but for showing desktop. Win+D = Show desktop. So even if your window does not have minimize box, it will get minimized.

Further, when you press Win+D, it is not your application which handles it but it is the windows itself which is handling it so it will never reach to your application at all so it makes no sense if you handle it in your application.

Try finding out some hack where your application is up, you stop windows from processing Win+D key.

There is a key in registry

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

changing values of hotkeys here will disable the Win+D combination but it is not recommended as you will have to restore it back when you application leaves the focus.

And yes, if you are making a widget, follow the requirements of creating a widget. It will automatically provide you such functionality

Murtuza Kabul
  • 6,438
  • 6
  • 27
  • 34
  • but how the MainForm is not getting minimized then? Even the MinimizedForm is also not getting minimized on First load? How? – C.M.W. Feb 15 '13 at 14:46
  • I am not sure with it but I think you should build a release version of your application and run it on another pc rather then launching it from IDE, it might show consistent behavior. – Murtuza Kabul Feb 15 '13 at 14:52