简体   繁体   English

如何在Visual Studio的特定实例(2008)中打开源文件

[英]How to open source file in specific instance of Visual Studio (2008)

I have several instances of Visual Studio 2008 opened and I want to open a source file in a specific instance. 我已打开Visual Studio 2008的多个实例,我想在特定实例中打开源文件。 I plan to do this with Win32 API and something like ShellExecute(...) , but I can't find solution yet. 我计划使用Win32 API和诸如ShellExecute(...)类的方法来执行此操作,但是我还找不到解决方案。

Is there any way to do so? 有什么办法吗? Any thoughts? 有什么想法吗?

Unless the application opening the file (VS2008) has a message handler set up to initiate opening a file (not sure if it does or not; this would be the easiest method), you could probably simulate a drag-and-drop of the file to the application's client area (via message sending directly to the client window's message handler). 除非打开文件的应用程序(VS2008)设置了消息处理程序以启动打开文件(不确定是否打开文件;这将是最简单的方法),否则您可能会模拟文件的拖放操作到应用程序的客户区(通过直接发送到客户窗口的消息处理程序的消息)。 You would need to get a handle to the client window of VS2008 for the instance you are sending the message to. 您需要获取要将消息发送到的实例的VS2008客户端窗口的句柄。

Don't know what the purpose would be, though. 但是,不知道目的是什么。 You can generally call up a new instance to open the file using ShellExecute(), but that wouldn't refer to a specific instance that is already running. 通常,您可以使用ShellExecute()来调用一个新实例来打开文件,但这并不表示已在运行的特定实例。

Another method you might consider is to hook VS2008's message handler for the main window, and log all messages sent relating to menu commands. 您可能考虑的另一种方法是将VS2008的消息处理程序挂接到主窗口,并记录所有与菜单命令相关的消息。 You might be able to determine if there is a message event associated with opening a file. 您也许能够确定是否存在与打开文件相关的消息事件。 Figuring out the parameters sent to the WndProc() function would be another story. 弄清楚发送到WndProc()函数的参数将是另一回事。 Hopefully it would be sent as a string pointer (for the filename) to lParam. 希望它将作为字符串指针(用于文件名)发送到lParam。

You could try using AutoHotKey . 您可以尝试使用AutoHotKey It's got a built-in scripting language and has various alternative ways of identifying which application to send its messages to. 它具有内置的脚本语言,并具有多种其他方式来标识将其消息发送到哪个应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM