Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
11
Erster Beitrag:
vor 1 Jahr, 2 Monaten
Letzter Beitrag:
vor 1 Jahr, 2 Monaten
Beteiligte Autoren:
André Labuschagné, JP, Alexandre Leclerc, GuenterP, Curtis

WD21 - Disabling Maximize

Startbeitrag von André Labuschagné am 24.08.2016 20:42

Hi All

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

Cheers
André

Antworten:

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

von Alexandre Leclerc - am 24.08.2016 20:53
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é

von André Labuschagné - am 24.08.2016 21:06
Hi Alexandre

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

Cheers
André

von André Labuschagné - am 24.08.2016 21:13
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


von JP - am 25.08.2016 08:53
@ 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

von Alexandre Leclerc - am 25.08.2016 12:07
Alex

Not really :) Found something on the web and got help converting it to WinDev. It is amazing what one can find "out there" !

von JP - am 25.08.2016 13:09
Can't you just go into the style tab of the window description and deselect maximize icon?

von Curtis - am 25.08.2016 14:12
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.

von JP - am 25.08.2016 14: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é

von André Labuschagné - am 25.08.2016 14:38
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.

von GuenterP - am 26.08.2016 05:31
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.