控制台应用程序中的右键菜单
问题描述:
我已经搜索了一下,但似乎无法弄清楚如何在控制台窗口中右键单击我自己的控制台应用程序时显示控制台菜单,如下所示:控制台应用程序中的右键菜单
http://i44.tinypic.com/2jbl82w.png
右键单击控制台窗口时,如何使菜单显示在我自己的控制台应用程序中?
是的,我知道我可以使用左上角的图标来显示菜单功能,但我正在寻找右键单击解决方案!
(这个问题似乎是,当我通过CMD.EXE执行.exe文件,而不是直接运行它的出现)
答
修正了以下变通,因为没有直接的解决问题/问题:
string filelocation = Assembly.GetExecutingAssembly().Location;
string filename = Process.GetCurrentProcess().MainModule.ModuleName;
filename = filename.Replace(".exe", "");
Process[] processArray = Process.GetProcesses();
int processesExists = 0;
for (int i2 = 0; i2 < (processArray.Length - 1); i2++)
{
if (processArray[i2].ProcessName.Contains(filename))
{
processesExists++;
}
}
if (processesExists == 1 && !Console.Title.Contains("cmd"))
{
Process.Start("cmd.exe", "/C " + "\"" + filelocation + "\"");
}
if (!Console.Title.Contains("cmd"))
{
Process.GetCurrentProcess().Kill();
}
你在调试器中运行呢? http://stackoverflow.com/questions/1060240/what-happened-to-the-context-menu-in-my-console-application –
你可能想读这个:http://stackoverflow.com/questions/1944481/console-app-mouse-click-xy-coordinate-detection-comparison –
如果您在Visual Studio(调试)或Visual Studio之外运行应用程序(应用程序直接执行) – Birdman