本帖最后由 mirbnbhdt01 于 2014-01-08 16:24:27 编辑

解决方案 »

  1.   

    [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern bool SetWindowPos(IntPtr hWnd,
            int hWndInsertAfter,
            int X,
            int Y,
            int cx,
            int cy,
            int uFlags
            );        public static void SetWindowPos(IntPtr hWnd)
            {
                SetWindowPos(hWnd, -1, 0, 0, 0, 0, 3);
                Thread.Sleep(500);
                SetWindowPos(hWnd, -2, 0, 0, 0, 0, 3);
            }
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern bool IsWindowVisible(IntPtr hWnd);
      

  2.   

    IsWindowVisible   先看是不是隐藏了
    然后设置 SetWindowPos(句柄)
      

  3.   

    private void continuePlay(){
                string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1);
                Console.WriteLine("fileName:"+fileName);
                string titleName = fileName+" - The KMPlayer";
                //取得句柄
                IntPtr ParenthWnd = FindWindow(null, titleName);
                if (ParenthWnd != IntPtr.Zero)
                {
                    //选中当前的句柄窗口
                    //SetForegroundWindow(ParenthWnd);
                    SetWindowPos(ParenthWnd);
                    Console.WriteLine("暂停");
                    Thread.Sleep(1000);
                    SendKeys.SendWait(" ");
                }
            }我调用这个方法向那个窗口发送一个空格 我这应该怎么写呢 能帮我修改下这个方法吗
      

  4.   

    找到文本框没?   找到了  就直接设置文本 
    如果是窗体接收空格指令  用sendmessage即可
      

  5.   


    是这样的 我这打开了一个视频播放器 然后想在另外一个面板设置2个按钮 一个播放 一个暂停 来对这个播放器进行操作 暂停我就打算模拟键盘的空格键 在32位系统下 我这程序是没问题的 但是64位下面SetForegroundWindow()这个方法就不能对播放器窗口激活 导致SendKeys.SendWait(" ");没办法执行
      

  6.   

    ClickCharKey2(MainHwnd, 32);
    private void ClickCharKey2(IntPtr hwnd, char key)
            {
                SystemApi.SendMessage(hwnd, SystemApi.WM_KEYDOWN, key, 0);
                Thread.Sleep(500);
                SystemApi.SendMessage(hwnd, SystemApi.WM_KEYUP, key, 0);
            }
    public const int WM_KEYDOWN = 0x0100;
            public const int WM_KEYUP = 0x0101;
            public const int WM_CHAR = 0x0102;
            public const int WM_IME_KEYDOWN = 0x0290;//适用于tab键
    DllImport("user32.dll", EntryPoint = "SendMessage")]
            public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
      

  7.   

    private void ClickCharKey2(IntPtr hwnd, char key)这个方法的char key参数传的是空格的键值吗?
      

  8.   

    ClickCharKey2(MainHwnd, 32);这个就是发送空格 MainHwnd这个是那个窗体的句柄
      

  9.   

    我遇到的是同样的问题呀,请问你解决了吗?共享一下方法可以吗?我是想把窗体置前并模拟鼠标按键,在32位系统没问题,64位的就不行了。我也是用setforegroundwindow,现在都没解决。