程序控制开始菜单的弹出 C#
发表于:2007-06-30来源:作者:点击数:
标签:
基本思路为,寻找开始菜单按钮窗口,并模拟用户单击 void pop() { User32.Enum Windows (new EnumProc(Enum), 0); } private bool Enum(IntPtr hWnd, uint param) { User32.STRINGBUFFER buffer=new User32.STRINGBUFFER(); User32.GetClassName(hWnd, ref b
基本思路为,寻找开始菜单按钮窗口,并模拟用户单击
void pop()
{
User32.Enum
Windows(new EnumProc(Enum), 0);
}
private bool Enum(IntPtr hWnd, uint param)
{
User32.STRINGBUFFER buffer=new User32.STRINGBUFFER();
User32.GetClassName(hWnd, ref buffer, 256);
if (buffer.szText == "Shell_TrayWnd")
{
User32.EnumChildWindows(hWnd, new EnumProc(Enum2), 0);
return false;
}
else return true;
}
IntPtr lastForeGroundWindow;
private bool Enum2(IntPtr hWnd, uint param)
{
User32.STRINGBUFFER buffer = new User32.STRINGBUFFER();
User32.GetClassName(hWnd, ref buffer, 256);
if (buffer.szText == "Button")
{
if (User32.SendMessage(hWnd, WndMsg.BM_GETSTATE, 0, 0) == User32.BST_PUSHED)
{
User32.SetForegroundWindow(lastForeGroundWindow);
}
else
{
lastForeGroundWindow = User32.GetForegroundWindow();
User32.SetForegroundWindow(hWnd);
User32.PostMessage(hWnd, WndMsg.BM_CLICK, 0, 0);
}
return true;
}
else
return false;
}
原文转自:http://www.ltesting.net