private const int Space = 0x3572; //热键ID protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_HOTKEY: //窗口消息-热键ID switch (m.WParam.ToInt32()) { case Space: //热键ID timer.Enabled = !timer.Enabled; Text = $"连点器 - F2 - {timer.Enabled}"; break; default: break; } break; case WM_CREATE: //窗口消息-创建 AppHotKey.RegKey(Handle, Space, 0, Keys.F2); break; case WM_DESTROY: //窗口消息-销毁 AppHotKey.UnRegKey(Handle, Space); //销毁热键 break; default: break; } }
private const int hotKey_id = 13682; // 0x3572; //热键ID protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_HOTKEY: //窗口消息-热键ID switch (m.WParam.ToInt32()) { case hotKey_id: //热键ID msg(m.HWnd + "--" + m.LParam + "--" + m.Msg + "--" + m.Result); MessageBox.Show("【全局】我按了Control +Shift +Alt +S"); break; default: break; } break; case WM_CREATE: //窗口消息-创建 AppHotKey.RegKey(Handle, hotKey_id, AppHotKey.KeyModifiers.Ctrl | AppHotKey.KeyModifiers.Shift | AppHotKey.KeyModifiers.Alt, Keys.S); break; case WM_DESTROY: //窗口消息-销毁 AppHotKey.UnRegKey(Handle, hotKey_id); //销毁热键 break; default: break; } }
private const int Space = 0x3572; //热键ID protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_HOTKEY: //窗口消息-热键ID switch (m.WParam.ToInt32()) { case Space: //热键ID this.Visible = true; this.WindowState = FormWindowState.Normal; //正常大小 this.Activate(); //激活窗体 //MessageBox.Show("我按了Control +Shift +Alt +S");//设置按下热键后的动作 break; default: break; } break; case WM_CREATE: //窗口消息-创建 AppHotKey.RegKey(Handle, Space, AppHotKey.KeyModifiers.Ctrl, Keys.Space); //热键为Ctrl+空格 break; case WM_DESTROY: //窗口消息-销毁 AppHotKey.UnRegKey(Handle, Space); //销毁热键 break; default: break; } }
//托盘退出事件 private void Exit_ToolStripMenuItem_Click(object sender, EventArgs e) { //退出程序 AppHotKey.UnRegKey(Handle, Constant.HOTKeyID); //销毁热键 this.notifyIcon.Dispose(); this.Dispose(); Environment.Exit(0); }
protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_HOTKEY: //窗口消息-热键ID switch (m.WParam.ToInt32()) { case AppShow: //热键ID if (!isShow) { if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Maximized; } this.Show(); isShow = true; } else { this.Hide(); isShow = false; } break; case AppSwith: MessageBox.Show("测试"); break; default: break; } break; case WM_CREATE: //窗口消息-创建 AppHotKey.RegKey(Handle, AppShow, AppHotKey.KeyModifiers.Ctrl | AppHotKey.KeyModifiers.Alt, Keys.S); break; case WM_DESTROY: //窗口消息-销毁 AppHotKey.UnRegKey(Handle, AppShow); //销毁热键 break; default: break; } }
private const int Space = 0x3572; //热键ID protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_HOTKEY: //窗口消息-热键ID ForseStopFeed = true; break; case WM_CREATE: //窗口消息-创建 AppHotKey.RegKey(Handle, Space, AppHotKey.KeyModifiers.Ctrl | AppHotKey.KeyModifiers.Shift | AppHotKey.KeyModifiers.Alt, Keys.P); break; case WM_DESTROY: //窗口消息-销毁 AppHotKey.UnRegKey(Handle, Space); //销毁热键 break; default: break; } }
//重写窗体的WndProc函数,在窗口创建的时候注册热键,窗口销毁时销毁热键 protected override void WndProc(ref Message m) { switch (m.Msg) { case Constant.WM_QUERYENDSESSION: Exit_ToolStripMenuItem_Click(null, null); m.Result = (IntPtr)0; break; case Constant.WM_HOTKEY: //窗口消息-热键ID switch (m.WParam.ToInt32()) { case Constant.HOTKeyID: //热键ID if (isShow) { FormStatus(false); } else { FormStatus(true); } break; default: break; } break; case Constant.WM_CREATE: //窗口消息-创建 if (!AppHotKey.RegKey(Handle, Constant.HOTKeyID, AppHotKey.KeyModifiers.Alt, Keys.Q)) { Application.Exit(); } break; case Constant.WM_DESTROY: //窗口消息-销毁 AppHotKey.UnRegKey(Handle, Constant.HOTKeyID); //销毁热键 break; default: break; } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { convert = false; int sizeX = 0; int sizeY = 0; int sizeWidth = 0; int sizeHeight = 0; if (DraggableObjects.Count > 0) { convert = true; sizeX = DraggableObjects[control_Num].Region.Left; sizeY = DraggableObjects[control_Num].Region.Top; sizeWidth = DraggableObjects[control_Num].Region.Width; sizeHeight = DraggableObjects[control_Num].Region.Height; } base.WndProc(ref m); switch (m.Msg) { case WM_NCPAINT: if (m_aeroEnabled) { var v = 2; DwmSetWindowAttribute(this.Handle, 2, ref v, 4); MARGINS margins = new MARGINS() { bottomHeight = 1, leftWidth = 1, rightWidth = 1, topHeight = 1 }; DwmExtendFrameIntoClientArea(this.Handle, ref margins); } break; case 0x0084: if (Sizeable) { base.WndProc(ref m); Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF); vPoint = PointToClient(vPoint); if (vPoint.X <= 5) { if (vPoint.Y <= 5) { m.Result = (IntPtr)Guying_HTTOPLEFT; } else if (vPoint.Y >= ClientSize.Height - 5) { m.Result = (IntPtr)Guying_HTBOTTOMLEFT; } else { m.Result = (IntPtr)Guying_HTLEFT; } } else if (vPoint.X >= ClientSize.Width - 5) { if (vPoint.Y <= 5) { m.Result = (IntPtr)Guying_HTTOPRIGHT; } else if (vPoint.Y >= ClientSize.Height - 5) { m.Result = (IntPtr)Guying_HTBOTTOMRIGHT; } else { m.Result = (IntPtr)Guying_HTRIGHT; } } else if (vPoint.Y <= 5) { m.Result = (IntPtr)Guying_HTTOP; } else if (vPoint.Y >= ClientSize.Height - 5) { m.Result = (IntPtr)Guying_HTBOTTOM; } } break; case WM_HOTKEY: if (Use_HotKey) { switch (m.WParam.ToInt32()) { case 0x1000: // Ctrl_Up: sizeY -= 1; break; case 0x1001: // Ctrl_Down: sizeY += 1; break; case 0x1002: // Ctrl_Left: sizeX -= 1; break; case 0x1003: // Ctrl_Right: sizeX += 1; break; case 0x1004: // Shift_Up: sizeHeight -= 1; break; case 0x1005: // Shift_Down: sizeHeight += 1; break; case 0x1006: // Shift_Left: sizeWidth -= 1; break; case 0x1007: // Shift_Right: sizeWidth += 1; break; case 0x1008: // Alt_Delete Delete_Control(true); convert = false; break; case 0x1009: // Alt_X Object_OperationCopy(); Delete_Control(true); convert = false; break; case 0x1010: // Alt_C Object_OperationCopy(); convert = false; break; case 0x1011: // Alt_V Object_OperationPast(0, 21); convert = false; break; case 0x1012: // Alt_Z Object_Operation(0); convert = false; break; case 0x1013: // Alt_R Object_Operation(1); convert = false; break; case 0x1014: // Alt_T ListSwap_Top(); convert = false; break; case 0x1015: // Alt_B ListSwap_Bottom(); convert = false; break; case 0x1016: // Alt_P new RBuild_Preview().View(); convert = false; break; default: break; } if (convert) { if (sizeWidth < 14) { sizeWidth = 14; } if (sizeHeight < 14) { sizeHeight = 14; } if (sizeX < 0) { sizeX = 0; sizeWidth = DraggableObjects[control_Num].Region.Width; } if ((sizeX + sizeWidth) > Print_PageType.Width) { sizeWidth = DraggableObjects[control_Num].Region.Width; sizeX = DraggableObjects[control_Num].Region.Left; } if (sizeY < 0) { sizeY = 0; sizeHeight = DraggableObjects[control_Num].Region.Height; } if ((sizeY + sizeHeight) > DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Bottom - 20) { sizeHeight = DraggableObjects[control_Num].Region.Height; sizeY = DraggableObjects[control_Num].Region.Top; } if (sizeY < (DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20)) { sizeY = DraggableObjects[control_Num].Region.Top; } DraggableObjects[control_Num].Setimage = LinBox(sizeWidth, sizeHeight, 1, DraggableObjects[control_Num].ControlType, control_Num); DraggableObjects[control_Num].Region = new Rectangle(sizeX, sizeY, sizeWidth, sizeHeight); Print_PageType.Invalidate(); View_Info = true; } } break; case WM_CREATE: // 创建窗口消息 if (Use_HotKey) { for (int i = 0; i < 4; i++) { AppHotKey.RegKey(Handle, hot_Keys[i], AppHotKey.KeyModifiers.Ctrl, keys[i]); AppHotKey.RegKey(Handle, hot_Keys[i + 4], AppHotKey.KeyModifiers.Shift, keys[i]); } for (int i = 4; i < 13; i++) { AppHotKey.RegKey(Handle, hot_Keys[i + 4], AppHotKey.KeyModifiers.Alt, keys[i]); } } break; case WM_DESTROY: // 销毁窗口消息 if (Use_HotKey) { for (int i = 0; i < 16; i++) { AppHotKey.UnRegKey(Handle, hot_Keys[i]); } } break; default: break; } }