2011-11-16 88 views
5

我已經搜索了一下,但似乎無法弄清楚如何在控制檯窗口中右鍵單擊我自己的控制檯應用程序時顯示控制檯菜單,如下所示:控制檯應用程序中的右鍵菜單

http://i44.tinypic.com/2jbl82w.png

右鍵單擊控制檯窗口時,如何使菜單顯示在我自己的控制檯應用程序中?

是的,我知道我可以使用左上角的圖標來顯示菜單功能,但我正在尋找右鍵單擊解決方案!

(這個問題似乎是,當我通過CMD.EXE執行.exe文件,而不是直接運行它的出現)

+0

你在調試器中運行呢? http://stackoverflow.com/questions/1060240/what-happened-to-the-context-menu-in-my-console-application –

+0

你可能想讀這個:http://stackoverflow.com/questions/1944481/console-app-mouse-click-xy-coordinate-detection-comparison –

+0

如果您在Visual Studio(調試)或Visual Studio之外運行應用程序(應用程序直接執行) – Birdman

回答

1

修正了以下變通,因爲沒有直接的解決問題/問題:

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(); 
} 
2

鼠標消息不會到你的計劃,他們打算到命令提示符窗口。你的程序沒有窗口。

所以,你可以以某種方式劫持從命令提示符消息看到:

c++ get other windows messages

9

使用SetConsoleMode清除ENABLE_QUICK_EDIT_MODE模式。當程序退出時,將標誌恢復到之前的設置只是禮貌。

+0

謝謝! 語法如何? – Birdman

+0

要爲此訪問API,請從[here](http://www.pinvoke.net/default.aspx/kernel32.setconsolemode)複製代碼。但不知道如何獲得控制檯窗口句柄。 – sq33G

相關問題