基本思路为,寻找开始菜单按钮窗口,并模拟用户单击
void pop()
{
user32.enumwindows(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;
}