5

How does one make a right click menu appear when right clicking in the console window of my own Console app like the following:

And yes, I do know that I can use the upper-left icon to make the menu functions appear, but I'm looking for the right-click solution!

(The problem seems to appear when I execute the .exe file directly instead of running it through CMD.EXE)

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Birdman
  • 5,244
  • 11
  • 44
  • 65
  • Are you running it in the debugger? http://stackoverflow.com/questions/1060240/what-happened-to-the-context-menu-in-my-console-application – Eric Petroelje Nov 16 '11 at 16:04
  • You may want to read this: http://stackoverflow.com/questions/1944481/console-app-mouse-click-x-y-coordinate-detection-comparison – Duke Hall Nov 16 '11 at 16:04
  • Doesn't matter if you run your application in Visual Studio (Debugging) or outside of visual studio (Application directly executed) – Birdman Nov 25 '11 at 21:20

3 Answers3

9

Use SetConsoleMode to clear the ENABLE_QUICK_EDIT_MODE mode. It's only polite to restore the flag to its previous setting when your program exits.

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • Thank you! How do the syntax look like? – Birdman Nov 16 '11 at 19:55
  • To access the API for this, copy the code from [here](http://www.pinvoke.net/default.aspx/kernel32.setconsolemode). Not sure how to get the console window handle, though. – sq33G Nov 16 '11 at 20:03
  • @sq33G we can use [`GetStdHandle`](https://learn.microsoft.com/en-us/windows/console/getstdhandle) right? – Sreenikethan I Aug 22 '21 at 07:24
2

The mouse messages are not going to your program, they are going to the Command Prompt window. Your program has no windows.

So, you could somehow hijack the messages from the Command Prompt see this:

c++ get other windows messages

Community
  • 1
  • 1
Lou Franco
  • 87,846
  • 14
  • 132
  • 192
1

Fixed with the following work-around since there's no direct solution to the question/problem:

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();
}
Birdman
  • 5,244
  • 11
  • 44
  • 65