PDA

View Full Version : [SOLVED] Prevent minimize window



frsm
07-25-2007, 10:38 AM
hello all

how can i prevent minimizing the workbook's window ?

thankyou

Bob Phillips
07-25-2007, 11:23 AM
Hi frsm,

You must be our first visitor from Palestine, so welcome.

Try this code



Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetFocus Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
'Window styles
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const GWL_EXSTYLE As Long = (-20) 'The offset of a window's extended style
Private Const WS_CAPTION As Long = &HC00000 'Style to add a titlebar
Private Const WS_MINIMIZEBOX As Long = &H20000 'Tool Window: small titlebar
'Close menu item
Private Const SC_CLOSE As Long = &HF060
'Hide or show a window
Private Const SW_HIDE As Long = 0
Private Const SW_SHOW As Long = 5

Private Sub SetFormStyle()
Dim lStyle As Long, hMenu As Long
Dim hWnd As Long
'Get the userform's window handle
hWnd = FindWindow("XLMAIN", Application.Caption) 'XL97
lStyle = GetWindowLong(hWnd, GWL_STYLE)
lStyle = lStyle And Not WS_MINIMIZEBOX
SetWindowLong hWnd, GWL_STYLE, lStyle
lStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
'Update the window with the changes
DrawMenuBar hWnd
SetFocus hWnd
End Sub

frsm
07-25-2007, 12:10 PM
thank you very much for you nice replay and i hope to be an active participant in this forum

what about preventing restore down the window?
thanks alot

Bob Phillips
07-25-2007, 01:16 PM
I am sorry, I don't undesrtand what you mean by prevent restore down the window.

frsm
07-25-2007, 01:36 PM
hello again
i meant with restore down is the the opposite of maximize the worksheets window
in the top corner on the excel window there are icons one for maximize the second is for restore down and the third for minimized
i want to disable restoring down the excel window

thank you

Bob Phillips
07-25-2007, 02:09 PM
On my machine, I have 3 buttons on each worksheet window, and 3 buttons on the Excel window.

Which are you referring to?

malik641
07-25-2007, 05:45 PM
Bob,

frsm means when you have a window maximized, the maximize button changes to a "restore down" button.

frsm
07-26-2007, 12:18 AM
thank you malik ,yes thats right thats whats i mean exactly
i want the window to be maximized always and disable the restore mode

Bob Phillips
07-26-2007, 12:54 AM
Bob,

frsm means when you have a window maximized, the maximize button changes to a "restore down" button.

Aah thanks Joseph. I NEVER maximize windows, so I never see a restore button.

Bob Phillips
07-26-2007, 01:03 AM
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetFocus Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
'Window styles
Private Const GWL_STYLE As Long = (-16)
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_CAPTION As Long = &HC00000
Private Const WS_MAXIMIZEBOX As Long = &H10000


Private Sub SetFormStyle()
Dim lStyle As Long, hMenu As Long
Dim hWnd As Long
Application.WindowState = xlMaximized
'Get the userform's window handle
hWnd = FindWindow("XLMAIN", Application.Caption)
lStyle = GetWindowLong(hWnd, GWL_STYLE)
SetWindowLong hWnd, GWL_STYLE, lStyle And Not WS_MAXIMIZEBOX
End Sub

frsm
07-26-2007, 01:37 AM
thank you XLD
it is ok

malik641
07-26-2007, 05:10 AM
Aah thanks Joseph. I NEVER maximize windows, so I never see a restore button.No problem Bob.

At first I was quite surprised at the thought that maybe you didn't know what the restore button was...but then I said to myself, "Well, maybe he never maximizes his windows..." It was a long-shot, but a theory nonetheless :)