Thread: Disableing the "resize" function on a window

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Disableing the "resize" function on a window

    How do you disable resize on a window?
    Thanks, August.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Don't use the WS_THICKFRAME style. For example, if you want a normal window without a sizing border you would use:
    Code:
    WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME

  3. #3
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    Also, if you want to prevent maximize but still want to have the minimize and close boxes you can:

    1) Get a handle to the windows system menu
    2) Use this handle to get another handle to the menu item for the maximise box (SC_MAXIMIZE)
    3) Disable the menu item.

    Cheers.

  4. #4
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    If you want to get into styling windows like this, you might do better to go to MSND and look up the window styles. Shoudn't be hard to find what you're looking for.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I wouldn't mind disableing the "Maximaze", "Minimize" and the "Close" buttons altogether.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> and the "Close" buttons

    Handle the WM_CLOSE message.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Could someone give me an example of this?
    (I am new to WIN32-C++, I guess I should have said that from the start.)
    I tried several different things but the compiler keeps coming back with errors.

  8. #8
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I replaced my "WS_THICKFRAME" with "WS_BORDER" but it's not working!!!

  9. #9
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    The best way to disable resizing on any window, no matter what style is to handle the WM_GETMINMAXINFO message.
    Last edited by Darryl; 04-20-2005 at 08:03 AM.

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    It's still not changing anything.
    Could it have to do with that I am using Dev-C++?

  11. #11
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    What size do you want the window to be? Please be specific, Width and height?

  12. #12
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Why not handle the WM_SIZE message to just automatically resize the window to whatever size you start with?

  13. #13
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Taking anonytmouse's original suggestion here's an example (use &~ to remove a style, so if you don't want a maximize button then deal with the WS_MAXIMIZEBOX style bit accordingly)
    Code:
    #include <windows.h>
    #include <tchar.h>
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
    
    int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR pStr,int nCmd)
    {
    HWND       hwnd;
    MSG        msg;
    TCHAR      classname[]=_T("kenf's_wnd");
    WNDCLASSEX wcx={0};
    
    wcx.cbSize       =sizeof(wcx); 
    wcx.lpfnWndProc  =WndProc; 
    wcx.hInstance    =hInst; 
    wcx.hIcon        =(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0, LR_SHARED); 
    wcx.hCursor      =(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0, LR_SHARED);
    wcx.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1); 
    wcx.lpszClassName=classname; 
    
    if (RegisterClassEx(&wcx))
      {
      hwnd=CreateWindowEx(0,classname,_T("Title"),
                          WS_OVERLAPPEDWINDOW&~WS_THICKFRAME, 
                          GetSystemMetrics(SM_CXSCREEN)/4,
                          GetSystemMetrics(SM_CYSCREEN)/4,
                          GetSystemMetrics(SM_CXSCREEN)/2,
                          GetSystemMetrics(SM_CYSCREEN)/2,
                          0,0,hInst,0);
      if (hwnd)
        {
        ShowWindow(hwnd,nCmd);
        UpdateWindow(hwnd);
        
        while (GetMessage(&msg,0,0,0)>0)
          {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
          }
        return msg.wParam;
        }
      else
        {
        MessageBox(0,_T("Wnd creation failure"),_T("Error"),MB_OK|MB_ICONERROR);
        return 0;
        }
      }
    MessageBox(0,_T("Wnd registration failure"),_T("Error"),MB_OK|MB_ICONERROR);
    return 0;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    switch (uMsg)
      {
      case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
      default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
      }
    }
    If you want to permit resizing a window but limit the extent to which a user can do so then handle WM_GETMINMAXINFO messages as Darryl suggested earlier.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  14. #14
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, that works, but how do you disable the MAXIMIZE function? I may not beable to resize, but I can Maximize.

  15. #15
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    but how do you disable the MAXIMIZE function?
    Quote Originally Posted by Ken Fitlike
    use &~ to remove a style, so if you don't want a maximize button then deal with the WS_MAXIMIZEBOX style bit accordingly
    Explicitly:
    Code:
    WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOX
    '&~' just means 'AND-NOT' ie WS_OVERLAPPEDWINDOW is the same as
    Code:
    WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
    therefore WS_OVERLAPPEDWINDOW&~WS_THICKFRAME means, literally, use WS_OVERLAPPEDWINDOW without WS_THICKFRAME ie.
    Code:
    WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
    and WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOX is WS_OVERLAPPEDWINDOW without WS_THICKFRAME and without WS_MAXIMIZEBOX:
    Code:
    WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
    Or just explicitly specify those window styles you actually want your window to have.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM