Thread: Disabeling buttons on the windows display

  1. #1
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75

    Disabeling buttons on the windows display

    Code:
    void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
           SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    This code works alright. In the heat of the discussion I missed it, for which I humbly apologize. I am unable to refer this contribution to the person who made it, but do so implicitly, with many thanks attached.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,311
    Thanks for the update. That person was actually john.c who posted the original code that you criticised as "not working":
    Code:
    void disableMinimizeAndMaximizeButtons(HWND hwnd)
    {
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    The above code is equivalent to what you found worked, if you call it like this:
    Code:
    disableMinimizeAndMaximizeButtons(GetConsoleWindow());
    And yes, unfortunately, john.c is also the one who insulted you, but surely you can see it from his point of view now that you realised that his code works if you call it properly?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75

    Re disabeling buttons

    I am unable to respond the Laserlight. So I am creating a new post to be able to do so.

    This was the code proposed:

    Code:
    void disableMinimizeAndMaximizeButtons(HWND hwnd)
    {
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    This code is flawed, I changed it to look like so:
    -----------------------------------------------------

    (Below is the * code . . . the corrected code)

    Code:
    extern void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
           SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    The * code I tried out in the environment of an application. There it did NOT work.

    After making a test environment for the second time in order to try out everything that was proposed to me again, I found that the * code did in fact work.

    After searching for a cause I discovered that in the original test environment there was a routine that blocked the * code from working. Who would think of the possibility of two routines biting each other?

    The naughty routine is a security check, requiring a pin code to be entered. Why it is getting in the way of the * code, I have not found out yet.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,311
    Quote Originally Posted by Ivory348
    I am unable to respond the Laserlight. So I am creating a new post to be able to do so.
    I think Salem closed it hoping to preempt another squabble. Anyway, I'll merge the threads since it looks like we might be able to have a proper discussion.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,311
    Quote Originally Posted by Ivory348
    This code is flawed, I changed it to look like so:
    -----------------------------------------------------

    (Below is the * code . . . the corrected code)
    Code:
    extern void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
           SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    No, the code that you changed it to is equivalent. Here's why:
    • The extern keyword is unnecessary because function names have external linkage by default.
    • Whether you call GetConsoleWindow() as an actual argument of the function, or call it to provide an initial value to a local variable within the function, it is the same: either way hwmd is set to the return value of GetConsoleWindow().
    • When you're providing a non-static local variable with the return value of a function call immediately after declaring it, it is equivalent to initialising it with the return value of that function call.
    • In your "corrected code", ws is unused, therefore its declaration can be deleted.

    This means that your "corrected code" is equivalent to:
    Code:
    void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd = GetConsoleWindow();
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    This is in turn equivalent to:
    Code:
    void disableMinimizeAndMaximizeButtons(HWND hwnd)
    {
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    
    // ...
    
    disableMinimizeAndMaximizeButtons(GetConsoleWindow());
    except that having hwnd as a parameter is more flexible since you could call the function with a different argument.

    Quote Originally Posted by Ivory348
    After making a test environment for the second time in order to try out everything that was proposed to me again, I found that the * code did in fact work.

    After searching for a cause I discovered that in the original test environment there was a routine that blocked the * code from working. Who would think of the possibility of two routines biting each other?

    The naughty routine is a security check, requiring a pin code to be entered. Why it is getting in the way of the * code, I have not found out yet.
    Yeah, it looks like that was the key to the puzzle as to why john.c's code failed to work. You should find that if you substitute john.c's code back into your code to replace your * code, along with the correct function call, it will now work.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Quote Originally Posted by laserlight View Post
    <snipped>.
    Your final code works. I have the extern in because I have the code in a header file, having followed the instructions of how to do a header file. My word, what an exercise! Now the only thing I don't know yet how to do in C is to position the output frame in the middle of the console and to block moving it about. In C## these things are a piece of cake. The positioning can be done of course but not the fixing. Although I don't like having to do a calculating exercise to get the output frame in the center.

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    775
    Quote Originally Posted by Ivory348 View Post
    I have the extern in because I have the code in a header file, having followed the instructions of how to do a header file.
    You don't need "extern" on a function declaration. Surely you didn't include the function's definition in a header file, right? This is the only part of the function that should be in a header file:
    Code:
    void disableMinimizeAndMaximizeButtons(void);

  8. #8
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    If you're disabling the min/max buttons to work around a bug in your program then I think this is the wrong way to go about it. Changing the UI to work around a bug makes no sense and confuses users.

    What is the bug that manifests itself if the min/max buttons are there?

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,008
    Quote Originally Posted by Hodor View Post
    If you're disabling the min/max buttons to work around a bug in your program then I think this is the wrong way to go about it. Changing the UI to work around a bug makes no sense and confuses users.

    What is the bug that manifests itself if the min/max buttons are there?
    I am guessing that it is a console program that looks bad if the number of columns is changed.

    But, it could be an poorly written GUI program that has issues with size changes.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Quote Originally Posted by stahta01 View Post
    I am guessing that it is a console program that looks bad if the number of columns is changed.

    But, it could be an poorly written GUI program that has issues with size changes.

    Tim S.
    Maximizing after minimizing produced havoc on the c-output frame of my application, on a windows console. Why that happens is not the issue, neither is the question whether disabling the maximize and minimize box is good coding practice or not. It simply is the programmer's choice. An undesired occurrence does not always imply a coding shortcoming. The max/minimizing discussion in which many have vigorously participated has come to satisfactory end. I do not wish to start it all over again. However, I do thank you for your post.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-27-2012, 12:50 AM
  2. display a picture in windows dialogue
    By mr_empty in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2008, 12:09 AM
  3. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  4. Putting tool buttons onto windows
    By eth0 in forum Windows Programming
    Replies: 7
    Last Post: 04-10-2006, 04:15 PM
  5. Attach Windows/Buttons To Diff DC's
    By Sebastiani in forum Windows Programming
    Replies: 3
    Last Post: 11-30-2001, 12:12 AM

Tags for this Thread