dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How Can I Disable Maximize Button for Console Window?

  1. #1
    Join Date
    Sep 2008
    Posts
    119

    Question How Can I Disable Maximize Button for Console Window?

    I need to make my console application in a fixed size window & disable the maximize button. Can you give me any suggestions please?

    I tried to do the following for setting the size, but its does not have any effect to the console window size, it does not work even though the code compiles...

    Code:
    #include <iostream>
    #include <windows.h> 
    using namespace std;
    
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
    int main() {
        SMALL_RECT windowSize = {0, 0, 100, 100};
        SetConsoleWindowInfo(hConsole, TRUE, &windowSize);
        SetConsoleTitle(L"TEST");
        cout<<"\nPlease press enter to exit"<<endl;
        cin.get();
        return 0;
    }
    My requirements in short are:

    1. Disable maximize button
    2. Set fixed size for console window
    3. Add an icon beside the title name
    4. Change the font of the text in the screen

    I program in C++ under windows Vista, if you can tell me the proper functions, this can help!

    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: How Can I Disable Maximize Button for Console Window?

    try this

    Code:
    DWORD newStyle = WS_CAPTION | DS_MODALFRAME | WS_MINIMIZEBOX | WS_SYSMENU;
    SetWindowLong(hConsole , GWL_STYLE,  newStyle);
    SetWindowPos(hConsole , NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
    I hepe it works.

    regards
    Please 'Rate This Post' if it helped (encourage us to help you more)
    Build GUI in minute using rad c++
    Free IDE + GUI code generator - screenshot
    Free WINAPI sourcecode and tutorials

  3. #3
    Join Date
    Sep 2008
    Posts
    119

    Re: How Can I Disable Maximize Button for Console Window?

    Quote Originally Posted by Ali Imran View Post
    try this

    Code:
    DWORD newStyle = WS_CAPTION | DS_MODALFRAME | WS_MINIMIZEBOX | WS_SYSMENU;
    SetWindowLong(hConsole , GWL_STYLE,  newStyle);
    SetWindowPos(hConsole , NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
    I hepe it works.

    regards
    Thanks for your support. I already solved it several weeks ago...I appreciate your help

  4. #4
    Join Date
    Aug 2019
    Posts
    1

    Re: How Can I Disable Maximize Button for Console Window?

    Quote Originally Posted by Ali Imran View Post
    try this

    Code:
    DWORD newStyle = WS_CAPTION | DS_MODALFRAME | WS_MINIMIZEBOX | WS_SYSMENU;
    SetWindowLong(hConsole , GWL_STYLE,  newStyle);
    SetWindowPos(hConsole , NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
    I hepe it works.

    regards

    Your code functions almost perfectly, the only thing I found was you need to add SWP_SHOWWINDOW as paramenter.

    Code:
    SetWindowPos(hConsole , NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW);
    Otherwise the console is hidden.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)