-1

I have overridden wndproc() to use Hotkeys. but the form won't close anymore. and onclosing form the program stuck in an infinite loop in wndproc().

 protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        if (m.Msg == 0x0312)
        {


            Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);                  

            int id = m.WParam.ToInt32();                                        


            MessageBox.Show("Hotkey has been pressed!");
            // do something
        }

    }

i have set the e.cancel to true and added following codes in the OnFoemClosing method `

 e.Cancel = false;
 base.OnFormClosing(e);

But nothing happens.

Mamo Ghandi
  • 67
  • 2
  • 10

1 Answers1

-1
[DllImport("user32.dll")]
static extern bool DestroyWindow(IntPtr hWnd);

//Closes the form
btnCloseWindow_Click(object sender, EventArgs e)
{
     DestroyWindow(this.Handle);
}`[DllImport("user32.dll")]
static extern bool DestroyWindow(IntPtr hWnd);

//Closes the form
btnCloseWindow_Click(object sender, EventArgs e)
{
     DestroyWindow(this.Handle);
}`
Amira Bedhiafi
  • 6,070
  • 6
  • 17
  • 48
sudeep
  • 1