PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → WD21 - Disabling Maximize
WD21 - Disabling Maximize
Débuté par André Labuschagné, 24 aoû. 2016 22:42 - 11 réponses
Posté le 24 août 2016 - 22:42
Hi All

How does one disable the maximize button? Only want minimize button and close X to be functional.

Cheers
André
Posté le 24 août 2016 - 22:53
Hi André,

It is fairly complex. A simple way is that if this is a popup window that you do not want the user to play with, set the fixed dimensions. Make it not resizable. You can also remove all windows borders (making you own).

If this is for a main window, you can use skinning. But the option will still be available in the system menu.

I had a piece of code that I got somewhere for MDI windows. (I do not know who is the “I” person making the comments in the following code.) Maybe this can show you some ways of doing that with API calls:

// // Code comes from Microsoft article http://support.microsoft.com/kb/137033 // // The below comes from help given by developers Mike Gagnon and Gregory Adams // who converted the MS article to VFP for me and then I converted to WinDev. // // Microsoft constants // WS_MINIMIZEBOX = 0x20000 // WS_MAXIMIZEBOX = 0x10000 // WM_NCACTIVATE = 0x0086 // GWL_STYLE = -16 // Declare the variables required hWindow_Handle is system int nGWL_Style is int nCurrentStyle is int // Setup the variables hWindow_Handle = Handle() // Handle of current window nGWL_Style = -16 // MS constant // Get the current style of the window title bar nCurrentStyle = API( "USER32" , "GetWindowLongA" , hWindow_Handle , nGWL_Style ) // Switch off the min and max buttons // Both min and max must be removed before they actually disappear // otherwise buttons are just disabled individually but still shown nCurrentStyle = BinaryAND( nCurrentStyle , BinaryNOT( 0x20000 ) ) // WS_MINIMIZEBOX = 0x20000 nCurrentStyle = BinaryAND( nCurrentStyle , BinaryNOT( 0x10000 ) ) // WS_MAXIMIZEBOX = 0x10000 nCurrentStyle = API( "USER32" , "SetWindowLongA" , hWindow_Handle , nGWL_Style , nCurrentStyle ) // Send a message to the window to redraw the borders and title bar which // hides the min and max buttons. This is not required if this code runs // in the Initialization event of the window i.e. before it is drawn. API( "USER32" , "PostMessageA" , hWindow_Handle , 0x0086 , 0 , 0 ) // WM_NCACTIVATE = 0x0086
Best regards,
Alexandre Leclerc
Posté le 24 août 2016 - 23:06
Hi Alexandre

Thanks a ton Alexandre. This is a free window. I will see what I can do. The code compiles alright but the maximize option stays in the title bar. Will investigate further.

Cheers
André
Posté le 24 août 2016 - 23:13
Hi Alexandre

Brilliant. It worked - you just have to get it into the correct calling spot.

Cheers
André
Posté le 25 août 2016 - 10:53
Hi Alex

I posted this. I call it in the Window initialization code to hide min/max buttons as needed.




Quote
Alexandre Leclerc

Hi André,



It is fairly complex. A simple way is that if this is a popup window that you do not want the user to play with, set the fixed dimensions. Make it not resizable. You can also remove all windows borders (making you own).



If this is for a main window, you can use skinning. But the option will still be available in the system menu.



I had a piece of code that I got somewhere for MDI windows. (I do not know who is the “I” person making the comments in the following code.) Maybe this can show you some ways of doing that with API calls:




//
// Code comes from Microsoft article http://support.microsoft.com/kb/137033
//
// The below comes from help given by developers Mike Gagnon and Gregory Adams
// who converted the MS article to VFP for me and then I converted to WinDev.
//

// Microsoft constants
// WS_MINIMIZEBOX = 0x20000
// WS_MAXIMIZEBOX = 0x10000
// WM_NCACTIVATE = 0x0086
// GWL_STYLE = -16


// Declare the variables required
hWindow_Handle is system int
nGWL_Style is int
nCurrentStyle is int

// Setup the variables
hWindow_Handle = Handle() // Handle of current window
nGWL_Style = -16 // MS constant

// Get the current style of the window title bar
nCurrentStyle = API( "USER32" , "GetWindowLongA" , hWindow_Handle , nGWL_Style )

// Switch off the min and max buttons
// Both min and max must be removed before they actually disappear
// otherwise buttons are just disabled individually but still shown

nCurrentStyle = BinaryAND( nCurrentStyle , BinaryNOT( 0x20000 ) ) // WS_MINIMIZEBOX = 0x20000
nCurrentStyle = BinaryAND( nCurrentStyle , BinaryNOT( 0x10000 ) ) // WS_MAXIMIZEBOX = 0x10000
nCurrentStyle = API( "USER32" , "SetWindowLongA" , hWindow_Handle , nGWL_Style , nCurrentStyle )

// Send a message to the window to redraw the borders and title bar which
// hides the min and max buttons. This is not required if this code runs
// in the Initialization event of the window i.e. before it is drawn.
API( "USER32" , "PostMessageA" , hWindow_Handle , 0x0086 , 0 , 0 ) // WM_NCACTIVATE = 0x0086


Best regards,

Alexandre Leclerc
Posté le 25 août 2016 - 14:07
@ JP,
Then you deserve the credits! Thank you for the code it has been useful when I needed it.

@ André,
I'm glad it did what you wanted.

Best regards,
Alexandre Leclerc
Posté le 25 août 2016 - 15:09
Alex

Not really :) Found something on the web and got help converting it to WinDev. It is amazing what one can find "out there" !
Posté le 25 août 2016 - 16:12
Can't you just go into the style tab of the window description and deselect maximize icon?
Posté le 25 août 2016 - 16:38
Quote
Curtis

Can't you just go into the style tab of the window description and deselect maximize icon?

Curtis, that does not work for MDI type windows.
Posté le 25 août 2016 - 16:38
Well you guys have been absolutely marvellous. This forum is fast becoming an extremely useful place to visit.

Curtis - will have a look at that but could not find anything.

Cheers
André
Posté le 26 août 2016 - 07:31
Hi,
just for completeness I wanted to mention that for maximized MDI-child windows within an MDI-parent these three buttons go into the main menue of the MDI parent (for most projects I'm using maximized MDI-childs within an MDI-parent frame, they look and behave like internal windows and it works since Version 9). To make the buttons disappear it's sufficient to not use a main menue in the MDI-parent. Popup-menues or a ribbon control are fine as a replacement.
Posté le 21 août 2019 - 12:07
Hi Gents,

is there any code, like the above one used to remove the maximize and minimize button, that can be used to change the color of the title bar in a Windows application? Would it be possible to change the color of buttons and text in the title bar itself?


Thanks.

BR.