Disabling right clicks on a console based C# app

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dilip

    Disabling right clicks on a console based C# app


    I have written a C# based console application. Due to some issues
    thats been causing me endless nightmares, I was wondering, is there a
    way to prevent right mousebutton clicks on my application when it
    appears on the task bar? I don't want the context menu showing up
    when a user right clicks on it. I don't want the user to be able to
    do anything with it other than stare at it in its minimized form. I
    know we can P/Invoke into some Win32 APIs to hide it completely
    (FindWindow/ShowWindow/SW_HIDE) but for the moment is what I am aiming
    to do possible?

    I know there are many other ways to sidestep this problem completely
    but the for the moment I am stuck with what I have (due to legacy
    issues) and I need to find a way to disable the context menu from
    showing up when an user right clicks on my app on the task bar.

  • Jon Skeet [C# MVP]

    #2
    Re: Disabling right clicks on a console based C# app

    On Jun 18, 5:08 pm, Dilip <rdil...@lycos. comwrote:
    I have written a C# based console application.  Due to some issues
    thats been causing me endless nightmares, I was wondering, is there a
    way to prevent right mousebutton clicks on my application when it
    appears on the task bar?  I don't want the context menu showing up
    when a user right clicks on it.  I don't want the user to be able to
    do anything with it other than stare at it in its minimized form.  I
    know we can P/Invoke into some Win32 APIs to hide it completely
    (FindWindow/ShowWindow/SW_HIDE) but for the moment is what I am aiming
    to do possible?
    It sounds unlikely.
    I know there are many other ways to sidestep this problem completely
    but the for the moment I am stuck with what I have (due to legacy
    issues) and I need to find a way to disable the context menu from
    showing up when an user right clicks on my app on the task bar.
    I'm intrigued to hear why you're stuck with it being a console
    application when you don't need a console. Why not just make it a GUI
    app which doesn't show any forms?

    Jon

    Comment

    • Dilip

      #3
      Re: Disabling right clicks on a console based C# app

      On Jun 18, 11:15 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
      On Jun 18, 5:08 pm, Dilip <rdil...@lycos. comwrote:
      I know there are many other ways to sidestep this problem completely
      but the for the moment I am stuck with what I have (due to legacy
      issues) and I need to find a way to disable the context menu from
      showing up when an user right clicks on my app on the task bar.
      >
      I'm intrigued to hear why you're stuck with it being a console
      application when you don't need a console. Why not just make it a GUI
      app which doesn't show any forms?
      Because its a humongous application Jon. I don't know what might
      happen if I convert it to an GUI app. It interacts with so many other
      apps via remoting and such. At the very least it is going to involve
      re-testing the entire functional specifications which probably will
      not happen this late in the day. That is a kind of change the mgmt
      won't allow anyway. At least for the current release I need to find a
      way to prevent the context menu from showing up.

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Disabling right clicks on a console based C# app

        On Jun 18, 5:29 pm, Dilip <rdil...@lycos. comwrote:

        <snip>
        Because its a humongous application Jon.  I don't know what might
        happen if I convert it to an GUI app.
        All you'd be changing is whether or not a console is allocated. Just
        the project type, in the project settings. I'm not suggesting adding
        an actual UI or anything like that - just changing a single property
        of the project.
         It interacts with so many other
        apps via remoting and such.  At the very least it is going to involve
        re-testing the entire functional specifications which probably will
        not happen this late in the day.  That is a kind of change the mgmt
        won't allow anyway.  At least for the current release I need to find a
        way to prevent the context menu from showing up.
        I'm 99% sure that if you *do* find a way of doing that, it'll involve
        considerably more risky changes than just changing it from a console
        app to a WinForms app which happens not to ever create or display
        anything.

        If you're afraid of anything concrete in terms of not allocating a
        console, how convinced are you that disabling the context menu won't
        have similar effects?

        Jon

        Comment

        • Tom Shelton

          #5
          Re: Disabling right clicks on a console based C# app

          On 2008-06-18, Jon Skeet [C# MVP] <skeet@pobox.co mwrote:
          On Jun 18, 5:29 pm, Dilip <rdil...@lycos. comwrote:
          >
          ><snip>
          >
          >
          <snip>
          I'm 99% sure that if you *do* find a way of doing that, it'll involve
          considerably more risky changes than just changing it from a console
          app to a WinForms app which happens not to ever create or display
          anything.
          >
          If you're afraid of anything concrete in terms of not allocating a
          console, how convinced are you that disabling the context menu won't
          have similar effects?
          >
          Jon
          I have to agree with you on this, Jon. I'm pretty sure that it can be done...
          And the only way I can think of is basically to subclass the console window
          that the application is running in. Just discovering the window involves a
          certain amount of complexity - usually, it involves setting the console's
          title to something unique, and then using FindWindowEx or EnumWindows to
          locate the console window. Once done, you would need to highjack the windows
          Window procedure, and look for right clicks, etc.

          It seems a lot simpler and safer, to simply turn the application into windows
          exe in the project properties.

          --
          Tom Shelton

          Comment

          • Mr. Arnold

            #6
            Re: Disabling right clicks on a console based C# app


            "Dilip" <rdilipk@lycos. comwrote in message
            news:3f8415c0-e2bb-4306-afe2-675fc873241e@26 g2000hsk.google groups.com...
            >
            I have written a C# based console application. Due to some issues
            thats been causing me endless nightmares, I was wondering, is there a
            way to prevent right mousebutton clicks on my application when it
            appears on the task bar? I don't want the context menu showing up
            when a user right clicks on it. I don't want the user to be able to
            do anything with it other than stare at it in its minimized form. I
            know we can P/Invoke into some Win32 APIs to hide it completely
            (FindWindow/ShowWindow/SW_HIDE) but for the moment is what I am aiming
            to do possible?
            >
            I know there are many other ways to sidestep this problem completely
            but the for the moment I am stuck with what I have (due to legacy
            issues) and I need to find a way to disable the context menu from
            showing up when an user right clicks on my app on the task bar.
            >
            I used the gpedit.msc in the Run box on the machine running Vista Ultimate,
            went to the group policy listed below and enabled it. No one can
            right-click an application setting on the task bar.



            Maybe, that's what you need to do, if this is a dedicated machine for
            running legacy solutions.

            The link was for Win 2K, but the same thing can be done on Vista, and I will
            assume it can be done for other MS NT class O/S(s).


            Comment

            Working...