Announcement

Collapse
No announcement yet.

AllocConsole w/out close button?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AllocConsole w/out close button?

    I am using a console in a PB/DLL6 application as a sort of debug
    screen because a listbox wouldn't keep up. This is a propeitary
    web server that is sometimes running close to a hundred threads
    at a time. Anyways, the problem is this:

    When I create a console with AllocConsole, it has the standard
    minimize, maximize and close buttons on it. Minimize and maximize
    I don't really care about (although I'd like to get rid of them
    as well) but the close button is a problem. If the user clicks
    on the close button, not only does it close the console, but
    it closes the entire application because the messages don't seem
    to be differentiated between the console or my main dialogue.

    On my main dialogue I have a "Close Debug" button that calls the
    FreeConsole and that works fine.... my app stays running and the
    console closes.

    So the question is, is there a way to keep the console from
    being created with a system menu (AllocConsole has no options
    it appears) or is there a way for my application to tell a close
    from the console apart from one for the main dialogue ?

    This application is using EzGui2.0 but I've verified the same
    behaviour using just DDT as well.

    Ideas ?



    ------------------
    --
    Steve Ryckman
    mailto:[email protected][email protected]</A>
    http://the.nevets.net
    --
    Steve Ryckman, VP Technical Services
    Security Information & Management Systems, Inc.
    mailto:[email protected][email protected]</A>
    http://www.simsware.com

  • #2
    > So the question is, is there a way to keep the console from being created with a system menu
    No, but you can delete "close" item in system menu similar like for GUI window.
    + take a look SetConsoleCtrlHandler


    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      SetConsoleCtrlHandler would be a "broader" solution, because it would allow you to intercept Close, Ctrl-C, and Ctrl-Break, and to handle Windows logoff and shutdown as well. The Close button would still be visible -- there's no way to get rid of it -- but SetConsoleCtrlHandler would allow you to "handle" it, instead of just closing the console window.

      Be advised, however, that SetConsoleCtrlHandler is not fully functional on Windows 95/98/ME systems. But I suspect that you would not be running that type of program on anything but NT or 2000 anyway.

      If you do need a solution that works on 95/98/ME (or even if you don't) you might want to consider my company's Console Tools add-on. It was designed for PB/CC apps but it works fine with AllocConsole too. The current version provides a method of detecting 9x shutdown and logoff events, and lots of other console-related functions that might be useful for a debug window.

      -- Eric

      ------------------
      Perfect Sync Development Tools
      Perfect Sync Web Site
      Contact Us: mailto:[email protected][email protected]</A>

      [This message has been edited by Eric Pearson (edited June 20, 2001).]
      "Not my circus, not my monkeys."

      Comment


      • #4
        Thanks for reminding me about Console Tools, I have the pro version
        but didn't even think about it for a PB/DLL app's console. That
        makes sense. Yes, this is strictly a Win2000 Server product
        anyways so 9x versions aren't a concern.

        ------------------
        --
        Steve Ryckman
        mailto:[email protected][email protected]</A>
        http://the.nevets.net
        --
        Steve Ryckman, VP Technical Services
        Security Information & Management Systems, Inc.
        mailto:[email protected][email protected]</A>
        http://www.simsware.com

        Comment


        • #5
          Steve --

          Check out the InitCTInternals function in the Console Tools Help File. It's used only when your program creates a console with AllocConsole.

          If you need any help, just let us know!

          -- Eric


          ------------------
          Perfect Sync Development Tools
          Perfect Sync Web Site
          Contact Us: mailto:[email protected][email protected]</A>
          "Not my circus, not my monkeys."

          Comment


          • #6
            Actually, using Console Tools I found that:

            lResult& = DeleteWindowMenuItem(%MENUITEM_CLOSE)

            Works quite nicely under Windows 2000 even though the docs say
            it only works for Windows 95/98.

            I played with SetConsoleCtrlHandler a bit but although it allowed
            me to know about the close, it didn't allow me to prevent it
            from occuring.

            With DeleteWindowMenuItem it grays out the close button on the
            console yet doesn't disturb the main dialogue just fine. So
            what magic is DeleteWindowMenuItem using to accomplish this feat?



            ------------------
            --
            Steve Ryckman
            mailto:[email protected][email protected]</A>
            http://the.nevets.net
            --
            Steve Ryckman, VP Technical Services
            Security Information & Management Systems, Inc.
            mailto:[email protected][email protected]</A>
            http://www.simsware.com

            Comment


            • #7
              1) DeleteWindowMenuItem(%MENUITEM_CLOSE) = DeleteMenu GetSystemMenu(hWndConsole, 0), %SC_CLOSE, %MF_BYCOMMAND
              2) SetConsoleCtrlHandler is necessary to prevent Ctrl-Break (and Ctrl-C)


              ------------------
              E-MAIL: [email protected]

              Comment


              • #8
                > lResult& = DeleteWindowMenuItem(%MENUITEM_CLOSE)
                >
                > Works quite nicely under Windows 2000 even though the docs say
                > it only works for Windows 95/98.

                Where do the docs say that?

                > I played with SetConsoleCtrlHandler a bit but although
                > it allowed me to know about the close, it didn't allow
                > me to prevent it from occuring.

                Right, I forgot about that. Sorry. That API provides notification but no control.

                Semen said:

                > SetConsoleCtrlHandler is necessary to prevent
                > Ctrl-Break (and Ctrl-C)

                That's true about Ctrl-Break, but you can get around Ctrl-C in other ways, such as SetConsoleMode.

                Steve, if you want to handle Ctrl-Break, use the Console Tools OnCtrlBreak function. For Ctrl-C you should use the SetConsoleMode API.

                -- Eric


                ------------------
                Perfect Sync Development Tools
                Perfect Sync Web Site
                Contact Us: mailto:[email protected][email protected]</A>

                [This message has been edited by Eric Pearson (edited June 20, 2001).]
                "Not my circus, not my monkeys."

                Comment


                • #9
                  Eric:

                  Sorry, read the docs for DeleteWindowMenuItem again and it isn't
                  saying that the function isn't supported on NT/2000, but is
                  saying Toolbar items on 95/98 are difficult to restore. I read
                  that wrong, sorry about that.

                  Semen:

                  Thanks for pointing me towards GetSystemMenu. I wouldn't mind
                  using Console Tools if it was a real console app and I would
                  benefit from the other ease of use, but just for one call I
                  don't want to have to include the DLL and so forth.

                  Thanks to everyone for their help on this. In fact, it never
                  even occured to me that Ctrl-C/Break would cause the main app
                  to terminate until everyone mentioned it. All I'm using the
                  console for is outputting text and I had no idea I'd have to
                  watch for those events as well. Thank goodness this is mostly
                  an internal application and we caught that before someone
                  Ctrl-C'd the server down on accident with files open all over
                  the place.

                  Thanks again guys.



                  ------------------
                  --
                  Steve Ryckman
                  mailto:[email protected][email protected]</A>
                  http://the.nevets.net
                  --
                  Steve Ryckman, VP Technical Services
                  Security Information & Management Systems, Inc.
                  mailto:[email protected][email protected]</A>
                  http://www.simsware.com

                  Comment


                  • #10
                    Originally posted by Steve Ryckman:

                    So the question is, is there a way to keep the console from
                    being created with a system menu (AllocConsole has no options
                    it appears) or is there a way for my application to tell a close
                    from the console apart from one for the main dialogue ?

                    This application is using EzGui2.0 but I've verified the same
                    behaviour using just DDT as well.

                    Ideas ?
                    Here might be a solution. Somewhere on the BBS someone has
                    posted examples of how to get the console handle. You also
                    own Console Tools which has a function that does that as well.

                    Grab the system menu and use the EnableMenuItem API Call
                    to disable it. Should look something like this:
                    Code:
                    Dim hMenu As Long, X%, Y%, Res&
                    Dim MenuString As Asciiz * 256
                    Dim conHdl As Long
                    
                        conHdl = SomeRoutineToGetTheConsoleHandle()
                        hMenu = GetSystemMenu(conHdl, %False)
                        X% = GetMenuItemCount(hMenu)
                        For Y% = 0 to X% - 1
                            GetMenuString hMenu, Y%, MenuString, 256, %MF_BYPOSITION
                            If Instr(MenuString, "&Close") Then 
                                Res& = EnableMenuItem(hMenu, Y%, %MF_GRAYED + %MF_BYPOSITION) 
                                Exit For
                            End If
                        Next Y%
                        DrawMenuBar hMenu
                    The only other thing you would have to worry about is if someone
                    Hit ctrl + C to exit the console window. But there is an
                    API call to block that as well. I believe it is setConsoleMode.
                    Not sure, been a while...

                    Hope that helps
                    Mark

                    ------------------

                    Comment

                    Working...
                    X