Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code creates a window which can be minimized and maximzed but i want to disable the maximize button. how can i do ths?

C#
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(windowWidth,windowHeight);
glutInitWindowPosition(50,50);
glutCreateWindow("gaMe");
Posted

1 solution

I forget right now how to get the handle of a GLUT window (if indeed GLUT includes a method to do this), though typically the following code will perform this task:

C++
long dwStyle = GetWindowLong(hwnd, GWL_STYLE);
dwStyle ^= WS_MAXIMIZEBOX;
SetWindowLong(hwnd, GWL_STYLE, dwStyle);



1. Get the current window style
2. Toggle the maximize-box bit
3. Send the new style back to the window


You'll just have to either (a) get GLUT to give you a handle for this window, or (2) use the standard windows functions for getting a handle to this window - should be reasonably trivial, since you've created the window and know what it's window text(title) is.



EDIT: Nope, GLUT no includes a function to retrieve a HWND of the main window, you'll have to do this yourself. Please find below a function that will do the lot for you.

Function
C++
void toggleGlutWindowMaximizeBox(char *szWindowTitle)
{
    long dwStyle;
    HWND hwndGlut;

    hwndGlut = FindWindow(NULL, szWindowTitle);

    dwStyle = GetWindowLong(hwndGlut, GWL_STYLE);
    dwStyle ^= WS_MAXIMIZEBOX;
    SetWindowLong(hwndGlut, GWL_STYLE, dwStyle);
}


Example of Use
C++
char *szWindowTitle = "GLUT Shapes";
....
....
....
glutCreateWindow(szWindowTitle);
toggleGlutWindowMaximizeBox(szWindowTitle);
 
Share this answer
 
v2
Comments
Sweety Khan 30-Sep-11 6:24am    
cOol its done thanx a lOt.
but clear these things
findWindow is used to get the handle of the specified window
wndows style is value of long type
am i right?
what is the fn of ^= and WS_MAXIMIZEBOX?
enhzflep 30-Sep-11 6:41am    
Pleasure. :)

1) Yes, FindWindow gets the HWND of a window
2) WindowStyle is 32 yes/no flags stored in a long (also 32 bits)
3) ^= means "XOR equals" - a logical eXclusive OR.

XOR Function
-------------
A | B | Result
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0

WS_MAXIMIZEBOX = "#define WS_MAXIMIZEBOX 0x10000"
- this is 00000000000000010000000000000000b
So, the code:
<pre>dwStyle ^= WS_MAXIMIZEBOX</pre>
Has the effect of flipping/toggling Bit 16 of dwStyle.

Sweety Khan 1-Oct-11 12:35pm    
oh means 16th bit of dwStyle is 1 n it represents tht maximize button is enable, by XORing it with 1 it becomes 0(disable). awesome description
enhzflep 1-Oct-11 12:37pm    
Spot-on!
Though, to be fair - I think your description is clearer and more succinct!
Sweety Khan 1-Oct-11 12:44pm    
:) one thing more u define window title name as char *szWindowStyle = "game", why *?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900