110,538
社区成员
发帖
与我相关
我的任务
分享
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern System.IntPtr GetForegroundWindow(); //获取当前窗口句柄
/// <summary>
/// 移动窗口(窗口句柄,位置x,位置y,窗口宽,窗口高,是否重新绘制)
/// </summary>
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool MoveWindow(System.IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
/// <summary>
/// 注册全局热键(窗口句柄,热键ID(自定义不可重复),组合键(Ctrl,shift,alt)这些按键,普通按键)
/// </summary>
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int RegisterHotKey(System.IntPtr hwnd, int id, int fsModifiers, int vk);
private void hotkey1_Click()
{
RegisterHotKey(this.Handle, 13579, 2, (int)Keys.Oemtilde);
}
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == 13579) //判断热键
{
//MessageBox.Show("213");
//Application.Restart();
MoveWindow(GetForegroundWindow(), 2, 2, 500, 500, true);
}
base.WndProc(ref m);
}