RegisterHotKey - problem

0

Witam, mam kolejny problem związany z RegisterHotKey, poniżej zamieszczam źródło, mimo tego, że nie wywala błędów podczas kompilacji to nie działa. Proszę o pomoc

static public class winapi
        {
            public static IntPtr statusbar;

            public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);

            #region WinApi Constants, Enums and structs



            public const int WM_HOTKEY = 0x0312;

            public const int WM_CLOSE = 0x10;
            public const int WM_SYSCOMMAND = 0x0112;


            [Flags]
            public enum KeyModifiers : uint
            {
                None = 0,
                Alt = 1,
                Control = 2,
                Shift = 4,
                Windows = 8
            }

 

            #endregion

            #region WinApi functions


            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id);


            #endregion

        } 

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case winapi.WM_HOTKEY:
                    ProcessHotkey(m.WParam);
                    break;
            }
            base.WndProc(ref m);
        }

        private void ProcessHotkey(IntPtr wparam)
        {
            if (wparam.ToInt32() == 1730)
            {
                if (timer13.Enabled == false)
                {
                    timer13.Enabled = true;
                }
                else
                    timer13.Enabled = false;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            uint mod = 2;
            
            uint key = 65;

            if (mod > 0 && key > 0)
            {
                winapi.RegisterHotKey(this.Handle, 1730, mod, key);
            }
        } 
    
                           
    } 
0

nie wiem dlaczego nie działa, ale coś takiego

                if (timer13.Enabled == false)
                {
                    timer13.Enabled = true;
                }
                else
                    timer13.Enabled = false;

ładniej zapiszesz jako

                timer13.Enabled = !timer13.Enabled;
0

błąd jest w tym miejscu:

wparam.ToInt32()

nie chce mi się wgryzać w to czemu to nie działa - najprostszy workaround to:

Convert.ToInt32(wparam.ToString())

1 użytkowników online, w tym zalogowanych: 0, gości: 1