-1

I've created an app with invisible form. (Opacity = 0 or Visible = false ShowInTaskbar = false) I've tried a lot of different ways of activating my form while having active other applications. By "activating" I mean giving focus to it without making it visible. For some reason, Activate() and Focus() methods are not working as supposed. According to MSDN (https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activate%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) Activate() method should cause focus of window if form is not minimized, but it is not working.

The only way I found to activate (focus) my window is minimize it and then return its state to Normal. It is working just perfect, but there is another problem: for Windows XP it causes constant effect of minimizing and maximizing of window, even though it is invisible. Is there a way to make this effect not visible just for my form?

Right now this effect is looking like this:

Effect

Sergey Dudkin
  • 169
  • 1
  • 10
  • What do you mean by "activating form"? If you mean make it visible again you should change the visibility to true and opacity to 100? If you trying to focus on your form try `Focus()` instead of `Activate()` – Ham3d May 02 '15 at 19:02
  • Thanks for your comments! By "activating" I mean giving focus to it without making it visible, and I've already tried Focus(). I am trying to make application, which, for example, can register KeyPress events for my form. I don't want to use Global hook. When I press some key with focus on my application, it will work, but the problem is I can not focus it, nor by activate(), not by focus(). The only way I found - minimizing and maximizing form again (even though it is invisible it works) but for Windows XP it causes effects of minimizing and maximizing which is not looking well. – Sergey Dudkin May 02 '15 at 19:27
  • This sounds like making use of a bug present in Windows XP. You know WXP is out-of-service right? I think a global hook will work better for what you're trying to do. But still, sniffing keystrokes isn't nice ;) – huysentruitw May 02 '15 at 19:34
  • It is not nice yes :) But I am trying to make a useful app (at least for me) which could simulate work of Win+X behaviour in Windows 8 (sounds crazy, especially when you see Windows XP in the same topic, isn't it ;) ) Right now it looks like this: https://img-fotki.yandex.ru/get/5805/110173670.1/0_c7d67_229c4acd_orig – Sergey Dudkin May 02 '15 at 19:44

2 Answers2

0

According to exact the complementary problem I had (I wanted to have those effects, but they didn't work), I think this could solve you problem:

What about changing your forms BorderStyle to none? Before minimiting call this:

this.FormBorderStyle = FormBorderStyle.None;

After maximizing that:

this.FormBorderStyle = FormBorderStyle.FixedSingle;

This resolves the winform to neither have a minimize nor maximize nor restore nor aerial effect.

Thus it might solve the wrong minimize/maximize effects.

cramopy
  • 3,459
  • 6
  • 28
  • 42
  • If something seems wrong to you, please add a comment or specify what doesn't fit you, please.. – cramopy May 02 '15 at 19:28
  • Thanks for your answer! Unfortunatelly, effects remained the same, even without changing form border style back from None state. I would plus your answer, but I can not change rep, because of my own one. – Sergey Dudkin May 02 '15 at 19:33
  • If you wait a second, I'll a virtual machine (of course WinXP) and have a look on it quickly. ^^ – cramopy May 02 '15 at 19:34
  • I have just done this, you can see result in my gif animation: https://img-fotki.yandex.ru/get/5805/110173670.1/0_c7d67_229c4acd_orig – Sergey Dudkin May 02 '15 at 19:45
0

Ok, I managed to find answer to my question, very similar question has already been on Stack Overflow, my fault: Is it possible to disable animation when minimizing / restoring window?

To be short, you just need to catch minimization system message in following way:

protected override void WndProc(ref Message m) {
        // Catch WM_SYSCOMMAND, SC_MINIMIZE
        if (m.Msg == 0x112 && m.WParam.ToInt32() == 0xf020) {
            this.Hide();
            this.WindowState = FormWindowState.Minimized;
            this.BeginInvoke(new Action(() => this.Show()));
            return;
        }
        base.WndProc(ref m);
    }
Community
  • 1
  • 1
Sergey Dudkin
  • 169
  • 1
  • 10