如何改变弹出的messageBox的弹出位置? 位置大小可不可以改变? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 貌似简单的功能,其实挺复杂的原理就是在对话激活的时候控制其位置关键是怎么捕获其激活的事件参考如下代码:using System.Runtime.InteropServices;public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);[DllImport("user32.dll")]public static extern IntPtr SetWindowsHookEx(int hookid, HookProc pfnhook, IntPtr hinst, int threadid);[DllImport("user32.dll")]public static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);[DllImport("kernel32.dll")]public static extern IntPtr GetModuleHandle(string modName);[DllImport("user32.dll")]public static extern bool UnhookWindowsHookEx(IntPtr hhook);[DllImport("user32.dll")]public static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle rect);[DllImport("user32.dll")]public static extern bool MoveWindow( IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);public const int WH_CBT = 5;public const int HCBT_ACTIVATE = 5;IntPtr hookHandle = IntPtr.Zero;private IntPtr CBTHookCallback(int nCode, IntPtr wParam, IntPtr lParam){ switch(nCode) { case HCBT_ACTIVATE: Rectangle vRectangle = new Rectangle(); GetWindowRect(wParam, ref vRectangle); vRectangle.Width = vRectangle.Width - vRectangle.Left; vRectangle.Height = vRectangle.Height - vRectangle.Top; MoveWindow(wParam, // 右下 Screen.GetWorkingArea(this).Width - vRectangle.Width, Screen.GetWorkingArea(this).Height - vRectangle.Height, vRectangle.Width, vRectangle.Height, false); UnhookWindowsHookEx(hookHandle); break; } return CallNextHookEx(hookHandle, nCode, wParam, lParam);}private void button1_Click(object sender, EventArgs e){ hookHandle = SetWindowsHookEx(WH_CBT, new HookProc(CBTHookCallback), GetModuleHandle(null), 0); MessageBox.Show("Zswang 路过");} 只能通过API函数控制,ZSWANG说 的够详细了 zswang好厉害 楼主这么不给分呀 如何利用WMI获取当前用户登陆Windows的时间 c#往定义好的模板里面填充数据,如何写? 问一句 c#的语句 ! 为什么我的页面调用javascript函数,总是提示_Default.aspx.cs没有定义,或者说括号无效,冒号也无效????? 80分全部奉上,求大傢的幫助! 初学请教 菜鸟问题 递归获取所有子集 遍历datatable,如果不计数,如何知道到了最后一行? 为什么我用Icon.Save保存下来的图标会失真? 求用Wise For Windows Installer打包问题 关于反射,帮我看下程序段有什么问题
原理就是在对话激活的时候控制其位置
关键是怎么捕获其激活的事件
参考如下代码:
using System.Runtime.InteropServices;public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);[DllImport("user32.dll")]
public static extern IntPtr SetWindowsHookEx(int hookid,
HookProc pfnhook, IntPtr hinst, int threadid);[DllImport("user32.dll")]
public static extern IntPtr CallNextHookEx(IntPtr hhook,
int code, IntPtr wparam, IntPtr lparam);[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string modName);[DllImport("user32.dll")]
public static extern bool UnhookWindowsHookEx(IntPtr hhook);[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle rect);[DllImport("user32.dll")]
public static extern bool MoveWindow(
IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);public const int WH_CBT = 5;
public const int HCBT_ACTIVATE = 5;
IntPtr hookHandle = IntPtr.Zero;private IntPtr CBTHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
switch(nCode)
{
case HCBT_ACTIVATE:
Rectangle vRectangle = new Rectangle();
GetWindowRect(wParam, ref vRectangle);
vRectangle.Width = vRectangle.Width - vRectangle.Left;
vRectangle.Height = vRectangle.Height - vRectangle.Top;
MoveWindow(wParam, // 右下
Screen.GetWorkingArea(this).Width - vRectangle.Width,
Screen.GetWorkingArea(this).Height - vRectangle.Height,
vRectangle.Width, vRectangle.Height, false);
UnhookWindowsHookEx(hookHandle);
break;
}
return CallNextHookEx(hookHandle, nCode, wParam, lParam);
}private void button1_Click(object sender, EventArgs e)
{
hookHandle = SetWindowsHookEx(WH_CBT, new HookProc(CBTHookCallback),
GetModuleHandle(null), 0);
MessageBox.Show("Zswang 路过");
}
楼主这么不给分呀