Thread: disabling minimize and mazimize boxes on Microsoft display output

  1. #31
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    [QUOTE=Ivory348;1292093]
    Quote Originally Posted by Hodor View Post
    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
    Well, it should work. Change LONG_PTR ws; to LONG ws; If it still doesn't work your compiler might be broken

    Edit: you're not changing & to and are you? I can't actually see how what you wrote works because it's wrong (using logical not bitwise operators). So maybe someone else can explain why/how it accidentally works

  2. #32
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    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.
    How about a suggestion as to how to change the code so it will work?

  3. #33
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    [QUOTE=Hodor;1292095]
    Quote Originally Posted by Ivory348 View Post

    Well, it should work. Change LONG_PTR ws; to LONG ws; If it still doesn't work your compiler might be broken
    It still does not work

  4. #34
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    [QUOTE=Hodor;1292095]
    Quote Originally Posted by Ivory348 View Post

    Well, it should work. Change LONG_PTR ws; to LONG ws; If it still doesn't work your compiler might be broken
    It still does not work

  5. #35
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Code:
    ws xor (WS_MAXIMIZEBOX or WS_MINIMIZEBOX)
    The code above is weird. The xor is bitwise (there is no logical xor in C, even in iso646.h>. Anyway, the code above is the same as

    Code:
    ws ^ (WS_MAXIMIZEBOX || WS_MINIMIZEBOX)
    The bit inside the parenthesis is doing a logical (boolean) operation and will evaluate to either 0 or 1. Assuming that one of those bits is set (which they would be if the boxes are originally shown) then it will evaluate to 1, giving:

    Code:
    ws ^ 1
    Which is a bitwise operation that toggles the least significant bit of ws. So I can only conclude that what you've written is working by accident. It makes no sense to me, but maybe someone with a Windows computer and a debugger can explain. Edit: the reason that I'm bringing this up is because code that appears to work but apparently only works by accident is a red flag for me. If I came across that code I'd be investigating why/how toggling the least significant bit works and I'd also be wondering why the compiler wasn't warning about the incorrect types and mixing of boolean and bitwise operations
    Last edited by Hodor; 12-15-2019 at 07:42 PM.

  6. #36
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ivory348
    How about a suggestion as to how to change the code so it will work?
    That's precisely what I suggested in post #19. I don't know if it works or not; I made the suggestion based on john.c's initial suggestion combined with the Basic example that you say works. If you want a working answer served to you on a platter, bye! I'm not going to prepare one for you because I simply cannot: I'm on a Mac right now in the office, and while I dual boot Windows and Linux at home, I generally only program on Linux there.

    But come on, it's not hard to try and find a permutation that might work. I mean, there's a bunch of stuff you can try:

    Exhibit A:
    Code:
    void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd = GetConsoleWindow();
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    Exhibit B:
    Code:
    void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd = GetConsoleWindow();
        SetWindowLongPtr(hwnd, GWL_STYLE,
            GetWindowLongPtr(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    Exhibit C:
    Code:
    void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd = GetConsoleWindow();
        SetWindowLong(hwnd, GWL_STYLE,
            GetWindowLong(hwnd, GWL_STYLE) ^ (WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    Exhibit D
    Code:
    void disableMinimizeAndMaximizeButtons(void)
    {
        HWND hwnd = GetConsoleWindow();
        SetWindowLongPtr(hwnd, GWL_STYLE,
            GetWindowLongPtr(hwnd, GWL_STYLE) ^ (WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
    }
    Exhibit A is john.c's original suggestion, but with the GetConsoleWindow() call.
    Exhibit B is Exhibit A but trying GetWindowLongPtr and SetWindowLongPtr as in the Basic example.
    Exhibit C is the Basic example, but with GetWindowLong and SetWindowLong instead.
    Exhibit D is the Basic example directly translated to C.

    Compile each of them at a high warning level and and take note of any warning messages. There might even be a compile error because I am completely guessing about GetWindowLongPtr because the MSDN docs seem to say something different. If there are no warning messages and yet none of them manages to disable the "minimize and mazimize boxes", then it could be that there's something else missing that perhaps the API in the Basic version handles for you.
    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

  7. #37
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Ok, I take back the bit about the compiler warning. With the code below gcc (with -Wall -Wextra) does not produce a warning but clang does. Probably because the || does evaluate to 0 or 1 as I explained above

    Code:
    #include <stdio.h>
    #include <stdint.h>
    
    const unsigned long WS_MAXIMIZEBOX = 1 << 2;
    const unsigned long WS_MINIMIZEBOX = 1 << 3;
    
    int main(void)
    {
        unsigned long ws = WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
        
        ws = ws ^ (WS_MAXIMIZEBOX || WS_MINIMIZEBOX);
        
        printf("0x%lx\n", ws);
        
        return 0;
    }
    The above code is obviously contrived and outputs 0xd (binary 1101)

    The original value of ws, in the code above, is (1 << 2) | (1 << 3), i.e. 1100. ws ^ 1 toggles the least significant bit resulting in 1101. So, my conclusion that your code is working by accident stands. You may as well just write

    Code:
    ws ^= 1;
    SetWindowLong(hwnd, GWL_STYLE, ws);
    But that's a bit scary to me
    [/code]

  8. #38
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Quote Originally Posted by laserlight View Post
    That's precisely what I suggested in post #19.. . . ..
    This is the case: Departing from the code that was suggested to me in the first place: I compared that code to basic code that works. (Changing that basic code to solve the problem will never work.) The comparison indicated that the code originally suggested to me wasn't quite right so I changed that code to be like the basic code. The resulting code does not suppress minimizing and maximizing when the relevant buttons are pressed. The problem is very tightly defined. Making random changes until by chance success is hit doesn't seem to me to be an alternative for professional expertise.

  9. #39
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ivory348
    Making random changes until by chance success is hit doesn't seem to me to be an alternative for professional expertise.
    It's systematic, not random, but yes, you risk running into the equivalent of "undefined behaviour" that way. But it's useful exploratory work to try and understand what works and what doesn't, after which you can relook the why to be sure you didn't arrive at a solution that only works by chance. This is part and parcel of problem solving.

    Here's something else that I suggest that you do: change your Basic code to:
    Code:
    fbgfxHwnd = GetConsoleWindow()
    ws = GetWindowLongPtr( fbgfxHwnd, GWL_STYLE )
    SetWindowLongPtr( fbgfxHwnd, GWL_STYLE, ws and not (WS_MAXIMIZEBOX or WS_MINIMIZEBOX) )
    Run it and see if it still works. I believe it would, because Hodor's argument seems sound to me. This would establish that my exhibit C and D can be discarded.

    Have you tried exhibit B? If the MSDN docs are applicable, I suspect that you actually need a suffix, i.e., GetWindowLongPtrA and SetWindowLongPtrA. But if you've tried the code you should then have gotten a compile error.
    Last edited by laserlight; 12-16-2019 at 02:26 AM.
    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

  10. #40
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I'd also like to add that I am not a person who will not admit that I am wrong (I've already demonstrated that in this thread). The reason that I could have been wrong about the warning is the entire reason I wrote the test code in post 37 actually. That said I've been bit twiddling for a long long (no pun intended) time and at no point was anything I said regarding that in doubt. The code given that you say works doesn't seem to match what Microsoft's documentation says. If I was a Windows programmer there is no reason for me to even be aware of the least significant bit of that object; that's what #defines (or equivalent) are for. Toggling the least significant bit, even if it works, is "magic" and not something that should be done. Microsoft is a lot of things but they're not dumb and the interfaces are sane in the sense that they do not rely on magic values. If what you wrote truly works then find out what the least significant bit does (it'll be defined somewhere) and use the defined value to toggle the bit instead.

  11. #41
    Registered User Ivory348's Avatar
    Join Date
    Oct 2019
    Posts
    75
    Quote Originally Posted by laserlight View Post
    It's systematic, not random <snipped>
    We have been at I for a number of days now, without getting anywhere. So my conclusion is that the query I posted is outside forum's scope of expertise. Thanks to those who participated.

  12. #42
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Quote Originally Posted by Ivory348 View Post
    We have been at I for a number of days now, without getting anywhere. So my conclusion is that the query I posted is outside forum's scope of expertise. Thanks to those who participated.
    You have proven yourself to be a moron and an a-hole. You are outside this forum's scope of humanity.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  13. #43
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    They got a working answer days ago from the FreeBasic forum of all places
    disabeling the minimize and maximize box - freebasic.net

  14. #44
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by adeyblue View Post
    They got a working answer days ago from the FreeBasic forum of all places
    disabeling the minimize and maximize box - freebasic.net
    Yep, that make sense asking a Basic programming question on a website that support Basic programming is likely to get a answer faster.

    Edit: In case you did not figure it out the stupid OP was converting the C code to Basic and doing it poorly!

    Tim S.
    Last edited by stahta01; 12-16-2019 at 03:49 PM.
    "...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

  15. #45
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Oh, well. They're stuck with an answer that accidentally works

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