C# - 从C#应用程序将消息发送到谷歌浏览器

问题描述:

我一直在寻找过来,我还没有发现我怎么会从C#做到这一点。

I've been searching around, and I haven't found how I would do this from C#.

我是想使它所以我可以告诉谷歌Chrome浏览器去转发 返回 打开新标签页 关闭标签 打开新窗口关闭窗口从我的C#应用​​程序STRONG>

I was wanting to make it so I could tell Google Chrome to go Forward, Back, Open New Tab, Close Tab, Open New Window, and Close Window from my C# application.

我做了Winamp的使用

I did something similar with WinAmp using

[DllImport("user32", EntryPoint = "SendMessageA")]
private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam);

和别人几下。但我不知道该送什么消息或如何查找窗口,将它传递给,或任何东西。

and a a few others. But I don't know what message to send or how to find what window to pass it to, or anything.

所以,能不能有人告诉我怎么我会发送这些命令6从C#Chrome浏览器?谢谢

So could someone show me how I would send those 6 commands to Chrome from C#? thanks

编辑:
好吧,我越来越否决,所以也许我是不够清楚,或人假设我没有尝试算出这个对我自己的。

Ok, I'm getting voted down, so maybe I wasn't clear enough, or people are assuming I didn't try to figure this out on my own.

首先,我不是很好的与整个的DllImport东西。我仍然在学习它是如何工作的。

First off, I'm not very good with the whole DllImport stuff. I'm still learning how it all works.

我发现如何做到在Winamp同样的想法在几年前,我一直在寻找我的代码。我做了,所以我可以跳过一首歌,回去,播放,暂停,并从我的C#代码停止Winamp的。我开始通过导入:

I found how to do the same idea in winamp a few years ago, and I was looking at my code. I made it so I could skip a song, go back, play, pause, and stop winamp from my C# code. I started by importing:

	[DllImport("user32.dll", CharSet = CharSet.Auto)]
	public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
	[DllImport("user32.dll", CharSet = CharSet.Auto)]
	static extern int SendMessageA(IntPtr hwnd, int wMsg, int wParam, uint lParam);
	[DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
	public static extern int GetWindowText(IntPtr hwnd, string lpString, int cch);
	[DllImport("user32", EntryPoint = "FindWindowExA")]
	private static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);
	[DllImport("user32", EntryPoint = "SendMessageA")]
	private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam);



然后我发现使用这种利用这些常数我发送消息的代码。

Then the code I found to use this used these constants for the messages I send.

	const int WM_COMMAND = 0x111;
	const int WA_NOTHING = 0;
	const int WA_PREVTRACK = 40044;
	const int WA_PLAY = 40045;
	const int WA_PAUSE = 40046;
	const int WA_STOP = 40047;
	const int WA_NEXTTRACK = 40048;
	const int WA_VOLUMEUP = 40058;
	const int WA_VOLUMEDOWN = 40059;
	const int WINAMP_FFWD5S = 40060;
	const int WINAMP_REW5S = 40061;



我会得到的 HWND 的(程序发送消息到)方式:

I would get the hwnd (the program to send the message to) by:

IntPtr hwnd = FindWindow(m_windowName, null);



然后我会发送邮件到该程序:

then I would send a message to that program:

SendMessageA(hwnd, WM_COMMAND, WA_STOP, WA_NOTHING);



我以为我会做的非常相似,这对谷歌浏览器的东西。但我不知道其中的一些价值观应该是什么样的,我用Google搜索周围试图找到答案,但我不能,这就是为什么我在这里问。所以我的问题是如何得到的值:

I assume that I would do something very similar to this for Google Chrome. but I don't know what some of those values should be, and I googled around trying to find the answer, but I couldn't, which is why I asked here. So my question is how do I get the values for:

m_windowName WM_COMMAND

,然后为不同的命令值,转发 返回 新标签页 关闭标签页 新窗口 关闭窗口

and then, the values for the different commands, forward, back, new tab, close tab, new window, close window?

位于 http://dev.chromium.org/developers


修改:发送消息到一个窗口只是工作的一半。该窗口有回应的消息,并采取相应的行动。如果窗口不知道消息或不关心人,你就没有机会通过发送窗口消息来控制它。

EDIT: Sending a message to a window is only half of the work. The window has to respond to that message and act accordingly. If that window doesn't know about a message or doesn't care at all you have no chance to control it by sending window messages.

您正在寻找一处你如何遥控Winamp的实现细节。发送消息只是一个方式做它,它是Winamp的开发人员选择的方式。您正在使用这些消息是有特定含义的只有的Winamp的用户定义的消息。

You're looking at an implementation detail on how you remote controlled Winamp. Sending messages is just one way to do it and it's the way the Winamp developers chose. Those messages you're using are user defined messages that have a specific meaning only to Winamp.

您有什么在第一步要做的就是找​​出的如果的铬支持一些远程控制的以及这些机制。

What you have to do in the first step is to find out if Chromium supports some kind of remote controlling and what those mechanisms are.