PostMessage传递消息给窗口无反应
我用PostMessage给一个播放器发送了一个“空格”消息,返回值是1,说明却是发送了,但是播放器依然播放没有暂停。
然后我自己写了一个响应空格消息的小程序,并用PostMessage给它发送消息,是有效的。请问该如何让播放器也响应PostMessage发出的消息啊?
以下是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//后来添加的
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace Test_control
{
class Program
{
static void Main(string[] args)
{
SendMsg sm = new SendMsg();
int cmond=0;
String input;
for (; ; )
{
input = Console.ReadLine();
cmond = Convert.ToInt16(input);
if (cmond == 0)
break;
else
{
sm.StartOrStop();
}
}
}
}
public class SendMsg
{
[DllImport("user32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(
IntPtr hwnd,
int wMsg,
uint wParam,
uint lParam
);
IntPtr mainWindowHander;
public SendMsg()
{
Process[] allProcesses = Process.GetProcesses();
foreach(Process p in allProcesses)
{
if (p.ProcessName == "PotPlayerMini")
{
mainWindowHander = p.MainWindowHandle;
Console.WriteLine(p.ProcessName);
}
}
//如果没找到,即程序没有启动
if(mainWindowHander == IntPtr.Zero)
{
Console.WriteLine("not open");
Process p = new Process();
p.StartInfo.FileName = @"D:\SoftWare\PotPlayer 1.5.28069_wwwo\Potplayer\PotPlayerMini.exe";
p.Start();
Thread.Sleep(1000);
mainWindowHander = p.MainWindowHandle;
}
}
public void StartOrStop()
{
PostMessage(mainWindowHander, 0x0100, 0x20, 0x20390001);
PostMessage(mainWindowHander, 0x0101, 0x20, 0x20390001);
}
}
}
------解决方案--------------------
用SendInput或是keyboard_event
------解决方案--------------------
用SPY++查出千千播放的句柄,然后发消息 就可以了,可以发鼠标,也可以发BUTTON的CLICK消息