How do you disable resize on a window?
Thanks, August.
How do you disable resize on a window?
Thanks, August.
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
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.
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.
I wouldn't mind disableing the "Maximaze", "Minimize" and the "Close" buttons altogether.
>>> and the "Close" buttons
Handle the WM_CLOSE message.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
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.
I replaced my "WS_THICKFRAME" with "WS_BORDER" but it's not working!!!
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.
It's still not changing anything.
Could it have to do with that I am using Dev-C++?
What size do you want the window to be? Please be specific, Width and height?
Why not handle the WM_SIZE message to just automatically resize the window to whatever size you start with?
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)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.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); } }
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Okay, that works, but how do you disable the MAXIMIZE function? I may not beable to resize, but I can Maximize.
but how do you disable the MAXIMIZE function?Explicitly:Originally Posted by Ken Fitlike'&~' just means 'AND-NOT' ie WS_OVERLAPPEDWINDOW is the same asCode:WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOXtherefore WS_OVERLAPPEDWINDOW&~WS_THICKFRAME means, literally, use WS_OVERLAPPEDWINDOW without WS_THICKFRAME ie.Code:WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOXand 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|WS_MAXIMIZEBOXOr just explicitly specify those window styles you actually want your window to have.Code:WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.