注册 登录
编程论坛 C# 论坛

请教向桌面发送按键或者字符

eddybccn 发布于 2020-03-27 22:00, 1593 次点击

这两段代码都不行,求助一下
 
程序代码:
IntPtr hWndParent = (IntPtr)FindWindowEx(0, 0, "WorkerW", null);
            IntPtr hWndItem;
            IntPtr hWnd;
            while (true)
            {
                hWndItem = (IntPtr)FindWindowEx((int)hWndParent, 0, "SHELLDLL_DefView", null);
                if (hWndItem != IntPtr.Zero)
                {
                    hWnd = (IntPtr)FindWindowEx((int)hWndItem, 0, "SysListView32", "FolderView");
                    break;
                }
                hWndParent = (IntPtr)FindWindowEx(0, (int)hWndParent, "WorkerW", null);
            }

         
            // 激活
            
// SetActiveWindow(GetDesktopWindow());
            
// SetActiveWindow(tempHwnd);
            
//  SetForegroundWindow(parent);
            
// SetFocus(hWndItem);

            SendKeys.Send("as");
            SendKeys.SendWait("df");





程序代码:
IntPtr pWnd = FindWindow("Progman", null);
            pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefVIew", null);
           pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null);
           // pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", "FolderView");
         
// IntPtr tWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;

            SetParent(this.Handle, pWnd);
            SendKeys.Send("as");
            SendKeys.SendWait("df");
1 回复
#2
eddybccn2020-03-28 20:19
自问自答了
程序代码:
IntPtr hWndParent = (IntPtr)FindWindowEx(0, 0, "WorkerW", null);
            IntPtr hWndItem;
            IntPtr hWnd;
            while (true)
            {
                hWndItem = (IntPtr)FindWindowEx((int)hWndParent, 0, "SHELLDLL_DefView", null);
                if (hWndItem != IntPtr.Zero)
                {
                    hWnd = (IntPtr)FindWindowEx((int)hWndItem, 0, "SysListView32", "FolderView");
                    SetForegroundWindow(hWnd);
                    break;
                }
                hWndParent = (IntPtr)FindWindowEx(0, (int)hWndParent, "WorkerW", null);
            }

            SendKeys.Send("as");
            SendKeys.SendWait("df");

1