首页 > 开发 > 综合 > 正文

程序控制开始菜单的弹出 C#

2024-07-21 02:15:55
字体:
来源:转载
供稿:网友


   

 基本思路为,寻找开始菜单按钮窗口,并模拟用户单击

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;
  }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表