当前位置:编程学习 > asp >>

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

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

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;
  }



补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,