Thread: disabling minimize and mazimize boxes on Microsoft display output

  1. #16
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    I seem to need to define the words "does work". The function is supposed to disable the effects of pressing the minimize and maximize button. So if after implementing the code, pressing the respective buttons still leads to maximizing and minimizing, then the code does not work. I have the code in the list of prototypes at the head of the coding. I call the function from main. The definition of the function 100% as john gave it to me.

    The basic function that works is coded like so;
    Code:
    fbgfxHwnd = GetConsoleWindow()
    ws = GetWindowLongPtr( fbgfxHwnd, GWL_STYLE )
    SetWindowLongPtr( fbgfxHwnd, GWL_STYLE, ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX) )
    If I compare this code to the code that I was given there are some differences.

  2. #17
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Yes, I know what a function is.
    Yes I know how to call a function.
    Yes I called the function form main.
    No I am no bloody idiot.

  3. #18
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Ivory348 View Post
    I seem to need to define the words "does work". The function is supposed to disable the effects of pressing the minimize and maximize button. So if after implementing the code, pressing the respective buttons still leads to maximizing and minimizing, then the code does not work. I have the code in the list of prototypes at the head of the coding. I call the function from main. The definition of the function 100% as john gave it to me.

    The basic function that works is coded like so;
    Code:
    fbgfxHwnd = GetConsoleWindow()
    ws = GetWindowLongPtr( fbgfxHwnd, GWL_STYLE )
    SetWindowLongPtr( fbgfxHwnd, GWL_STYLE, ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX) )
    If I compare this code to the code that I was given there are some differences.
    That's not even C but what you were given is more correct; you don't really know the current states of WS_MAXIMIZEBOX and WS_MINIMIZEBOX so using XOR is not a great solution (you should be using AND to clear the bits... XOR toggles them)

    Edit: Why are you refusing to show your C code? I'm beginning to suspect you haven't written any C

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ivory348
    I seem to need to define the words "does work". The function is supposed to disable the effects of pressing the minimize and maximize button. So if after implementing the code, pressing the respective buttons still leads to maximizing and minimizing, then the code does not work.
    Yes. But notice that until now, you didn't say "pressing the respective buttons still leads to maximizing and minimizing". That's the answer to "how does it not work?" that was asked of you since post #6. It's like... "does work" for a car means being able to start it and drive to your destination. But if you tell the mechanic "the car doesn't work", that's not as helpful as "the car keeps overheating so I have to stop driving a few minutes after starting the car".

    Quote Originally Posted by Ivory348
    I have the code in the list of prototypes at the head of the coding. I call the function from main. The definition of the function 100% as john gave it to me.
    Show, don't just tell: show the code of the function call. Look, get into the habit of showing code. "I call the function from main". Very good, maybe you called it wrongly.

    Quote Originally Posted by Ivory348
    The basic function that works is coded like so;
    (...)
    If I compare this code to the code that I was given there are some differences.
    Then change the bitwise expression to match the Basic code that you say works, e.g.,
    Code:
    void disableMinimizeAndMaximizeButtons(HWND hwnd)
    {
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) ^ (WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    You may well have done this because you stated:
    Quote Originally Posted by Ivory348
    Changing the function for it to be similar to a function in Basic that I know of, and which does work. Both didn't solve the problem.
    But because you didn't post the C code that you actually tried, it is reasonable to suppose that you changed the code incorrectly.

    Furthermore, you should check that the Basic xor and or operators are for bitwise xor and bitwise or.
    Last edited by laserlight; 12-15-2019 at 06:54 PM.
    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. #20
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    This is how I changed the code:
    Code:
    void disableMinimizeAndMaximizeButtons()
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
        ws =  GetWindowLong(hwnd, GWL_STYLE);
        SetWindowLong(hwnd, GWL_STYLE, ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX));
    }

  6. #21
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Ivory348 View Post
    This is how I changed the code:
    Code:
    void disableMinimizeAndMaximizeButtons()
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
        ws =  GetWindowLong(hwnd, GWL_STYLE);
        SetWindowLong(hwnd, GWL_STYLE, ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX));
    }
    That's not C (unless you have a #define for xor I guess, but that's crazy)

  7. #22
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Are you saying that

    Code:
    void disableMinimizeAndMaximizeButtons()
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
        ws =  GetWindowLong(hwnd, GWL_STYLE);
        SetWindowLong(hwnd, GWL_STYLE, ws & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
    }
    does not work? I'm just asking because using XOR isn't strictly correct because you're assuming they're currently set (that the bits representing them are currently 1), which is why in my opinion using the AND approach is better (makes no assumptions about their current state)

    Edit: why is ws LONG_PTR? GetWindowLong() returns LONG, not LONG_PTR. Perhaps that's your problem
    Last edited by Hodor; 12-15-2019 at 07:11 PM.

  8. #23
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ivory348
    This is how I changed the code:
    Did you get any warning from the compiler? I would expect a warning because it sounds unlikely that GetWindowLong will return a LONG_PTR.

    Speaking of that, another thing to investigate is whether there's an equivalent of GetWindowLongPtr in C: a quick check of MSDN docs shows that it may be so, although there seems to be some difference in naming due to a possible name suffix.

    This is definitely wrong:
    Code:
    ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX))
    In C, the or operator is an alias for the logical || operator not the bitwise | operator. While xor is an alias for the bitwise ^ operator, you likely have to #include <iso646.h> to be able to use it, which makes it puzzling why you didn't get an error or at least a warning (unless you simply ignored the warning.)
    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

  9. #24
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Yes sir, that is what I am saying

  10. #25
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Could you possibly make a suggestion of how, what you say is wrong, should be changed?

  11. #26
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Quote Originally Posted by laserlight View Post
    Did you get any warning from the compiler? I would expect a warning because it sounds unlikely that GetWindowLong will return a LONG_PTR.

    Speaking of that, another thing to investigate is whether there's an equivalent of GetWindowLongPtr in C: a quick check of MSDN docs shows that it may be so, although there seems to be some difference in naming due to a possible name suffix.

    This is definitely wrong:
    Code:
    ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX))
    In C, the or operator is an alias for the logical || operator not the bitwise | operator. While xor is an alias for the bitwise ^ operator, you likely have to #include <iso646.h> to be able to use it, which makes it puzzling why you didn't get an error or at least a warning (unless you simply ignored the warning.)

    Could you possibly make a suggestion of how, what you say is wrong, should be changed?

  12. #27
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Hodor
    I'm just asking because using XOR isn't strictly correct because you're assuming they're currently set (that the bits representing them are currently 1), which is why in my opinion using the AND approach is better (makes no assumptions about their current state)
    Yeah, I agree that john.c's formulation of current_value & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX) makes more sense. The Basic code does do bitwise operations if the operands are numeric rather than boolean though, but I wonder if LONG_PTR in Basic gets interpreted as numeric instead of boolean in this context. The other issue is the difference between GetWindowLong and GetWindowLongPtr, but I am unfamiliar with this API so I do not know which should be preferred.

    Quote Originally Posted by Ivory348
    Could you possibly make a suggestion of how, what you say is wrong, should be changed?
    I posted that in post #19.
    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

  13. #28
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Ivory348 View Post
    Could you possibly make a suggestion of how, what you say is wrong, should be changed?
    She's saying that xor and or are logical operaters (boolean), not bitwise operators. So it should be

    Code:
    ws ^ (WS_MAXIMIZEBOX | WS_MINIMIZEBOX))
    But I still don't understand why

    Code:
    ws & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX)
    would not work and that's worrying (to me) because I think the latter is the better approach

  14. #29
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    [QUOTE=Hodor;1292086]Are you saying that

    Code:
    void disableMinimizeAndMaximizeButtons()
    {
        HWND hwnd;
        LONG_PTR ws;
        hwnd = GetConsoleWindow();
        ws =  GetWindowLong(hwnd, GWL_STYLE);
        SetWindowLong(hwnd, GWL_STYLE, ws & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
    }
    does not work? .. . . . . . . no does not work

  15. #30
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by laserlight View Post
    Yeah, I agree that john.c's formulation of current_value & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX) makes more sense. The Basic code does do bitwise operations if the operands are numeric rather than boolean though, but I wonder if LONG_PTR in Basic gets interpreted as numeric instead of boolean in this context. The other issue is the difference between GetWindowLong and GetWindowLongPtr, but I am unfamiliar with this API so I do not know which should be preferred.


    I posted that in post #19.
    Based on the documentation I can only assume that the LONG_PTR I can only assume is a mistake and maybe messing up the bitwise operations somehow. I can only assume because I don't have a Windows compiler and am just reading the documentation.

    I didn't know C had the aliases xor, or, and etc. Probably because I've never looked because I don't find the original operators difficult to understand. Thanks for pointing that out. I don't think I'll ever use them though because they seem more confusing than using, for example, && and &, where it's clear you're using logical or bitwise

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 10-25-2019, 05:13 AM
  2. Replies: 0
    Last Post: 10-25-2019, 05:13 AM
  3. Microsoft display
    By zach in forum Windows Programming
    Replies: 1
    Last Post: 09-07-2019, 01:48 PM
  4. LCD 16x2 Display only shows black boxes?
    By ElectronicX in forum C Programming
    Replies: 4
    Last Post: 06-12-2012, 08:17 AM
  5. output file display -- Need Help
    By boostpower in forum C Programming
    Replies: 2
    Last Post: 04-06-2006, 01:50 PM

Tags for this Thread