By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,509 Members | 2,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,509 IT Pros & Developers. It's quick & easy.

Disable Application Restore Button

P: n/a
I have found the following code on this newsgroup that removes the
Access Application minimize, restore and close buttons.

Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
Private Const HWND_TOP = 0
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
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 GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
'
Function NoCloseInAccess()
Dim lngStyle As Long
lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
lngStyle = lngStyle And Not WS_SYSMENU
Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE Or SWP_DRAWFRAME)
End Function
Function DoCloseInAccess()
Dim lngStyle As Long
lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
lngStyle = lngStyle Or WS_SYSMENU
Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE Or SWP_DRAWFRAME)
End Function

The code works well but it is overkill for what I am wanting to do. I
only need to remove or disable the restore button of the application
window. Is this possible?

Any help is appreciated.

Jan 21 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 21 Jan 2006 01:24:54 -0800, "Wayne" <cq*******@volcanomail.com> wrote:
I have found the following code on this newsgroup that removes the
Access Application minimize, restore and close buttons.

Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
Private Const HWND_TOP = 0
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
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 GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
'
Function NoCloseInAccess()
Dim lngStyle As Long
lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
lngStyle = lngStyle And Not WS_SYSMENU
Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE Or SWP_DRAWFRAME)
End Function
Function DoCloseInAccess()
Dim lngStyle As Long
lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
lngStyle = lngStyle Or WS_SYSMENU
Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE Or SWP_DRAWFRAME)
End Function

The code works well but it is overkill for what I am wanting to do. I
only need to remove or disable the restore button of the application
window. Is this possible?

Any help is appreciated.


See this thread. (Watch for word wrap)

http://groups.google.com/group/comp....1445b0712088ab
Wayne Gillespie
Gosford NSW Australia
Jan 21 '06 #2

P: n/a
Thanks Wayne. This is exactly what I was looking for. Much
appreciated.

Jan 21 '06 #3

P: n/a
I have a similar problem with the restore button on my custom report
menu bar. I can tell the report that I don't want minimise, maximise
or close buttons (I have a custom menu item to close the report), but
I'm still left with the annoying restore button on the report menu bar.
Is there a way to remove this?

Jan 21 '06 #4

P: n/a
On 21 Jan 2006 03:09:16 -0800, "Wayne" <cq*******@volcanomail.com> wrote:
I have a similar problem with the restore button on my custom report
menu bar. I can tell the report that I don't want minimise, maximise
or close buttons (I have a custom menu item to close the report), but
I'm still left with the annoying restore button on the report menu bar.
Is there a way to remove this?


You need to pass the hWnd of the report to a variation of the fActivateMaximizeBox function which passes the report's
name as an argument.

Add this function to the standard module containg the API functions from the other thread.

Public Function fActivateReportMaximizeBox(Enable As Boolean, strName As String)
Dim CurStyle As Long
Dim hWnd As Long

hWnd = Reports(strName).hWnd '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MAXIMIZEBOX) Then
CurStyle = CurStyle Or WS_MAXIMIZEBOX
End If
Else
If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
CurStyle = CurStyle - WS_MAXIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)

End Function

Add this line to the OnOpen event of the report(s) you want to

Call fActivateReportMaximizeBox(False, Me.Name)

You can make the same basic change to anyone of the fumctions contained in the module.
If you want to also manipulate the buttons on forms, change -

hWnd = Reports(strName).hWnd
to
hWnd = Forms(strName).hWnd
Wayne Gillespie
Gosford NSW Australia
Jan 21 '06 #5

P: n/a
Thanks again for the reply Wayne. Not sure what the problem is but the
restore button is still available on my custom menu bar, even after
calling the new function in the OnOpen event of the report.

Jan 21 '06 #6

P: n/a
On 21 Jan 2006 12:54:52 -0800, "Wayne" <cq*******@volcanomail.com> wrote:
Thanks again for the reply Wayne. Not sure what the problem is but the
restore button is still available on my custom menu bar, even after
calling the new function in the OnOpen event of the report.


I misread you you were after, the code will only affect the max/min/close buttons on the window the report is displayed
in, not the menu bar.

Can you not remove the restore button from the menu bar manually? Right click on the menu bar and select Customize.
Click on the restore button and drag it off the menu bar. Then close the Customize form.
Wayne Gillespie
Gosford NSW Australia
Jan 22 '06 #7

P: n/a
No, the restore button isn't there in "customise" view. It's weird
really. As I posted earlier, I have set the minimise, maximise and
close buttons to "none" in the report's properties. If I enable the
minimise and maximise buttons, the minimise button is visible next to
the restore button on the custom menu bar. If I disable the
minimise/maximise buttons, only the minimise button is removed, with
the restore button still being visible.

I think that these properties are primarily for the report window of a
non-maximised report with a sizeable border style - at least that is
what my experiments seem to suggest, because on the sizeable window of
a non-maximised report the buttons are removed as expected if the
properties are set to none, the restore button included. When a report
is opened maximised, the buttons are tranferred to the menu bar, with
the restore button apparently not being able to be removed by using the
properties sheet. Maybe this is a bug - I don't really know.

What I am trying to achieve is to stop the user from accidentally
clicking the restore button and being confronted with a report that is
less than full screen. If reports had a "OnResize" event as forms do,
I assume it would be a simple matter of maximising the report on this
event.

Anyhow, I think I may just have to live with the restore button unless
anyone has a workaround to get rid of it.

Jan 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.