Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 12
Default Adding and Graying MAXIMIZE button on vba E2007 form system menu

Hi,
I was trying to add MINIMIZE and MAXIMIXE buttons to vba E2007 form
system menu - and after that gray MAXIMIZE button. The problem is that
disabling by graying works only for the only initial default one
button 'X' for closing form and not working for the two new buttons
added programmatically. I was first positively surprised that the code
required for so customizing the vba form in win api is quite short,
but since it only works for 'X' button I must have missed something.
My code is:

Private Sub CommandButton1_Click()
Me.Hide 'secure a means to close the form after disabling 'X'
'after that I reset the project to restore the initial state of the
form
End Sub

Private Sub CommandButton2_Click()
'adding two buttons to system menu
hwnd = GetActiveWindow
Dim lng As Long
lng = GetWindowLong(hwnd, GWL_STYLE)
lng = lng Or WS_MINIMIZEBOX
lng = lng Or WS_MAXIMIZEBOX

Dim b As Long
b = SetWindowLong(hwnd, GWL_STYLE, lng)
b = SendMessage(hwnd, WM_NCACTIVATE, 1, 0) 'repaint non-client area

End Sub

Private Sub CommandButton3_Click()
'disabling 'X' button denoted by position GetMenuItemCount(hm) - 1
'I want this working for the two added buttons as well but it won't !
Dim hm As Long
hm = GetSystemMenu(hwnd, 0)

Dim b As Long
b = EnableMenuItem(hm, GetMenuItemCount(hm) - 1, MF_BYPOSITION Or
MF_GRAYED)
b = SendMessage(hwnd, WM_NCACTIVATE, 1, 0)'repaint

End Sub

I suspect that I'm making a simple mistake by having the two added
buttons not recognizable
for graying but I don't know how

Thanks for anny suggestions

Tom
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 12
Default Adding and Graying MAXIMIZE button on vba E2007 form system menu

Tom wrote:
Hi,
I was trying to add MINIMIZE and MAXIMIXE buttons to vba E2007 form
system menu - and after that gray MAXIMIZE button. The problem is that

That's me again. I forgot to paste win function declarations for easy
testing:
The declaration module is:
'-----------------------------------------

Public hwnd As Long




Public Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

Public Const MIIM_STATE As Long = &H1&
Public Const MFS_GRAYED As Long = &H3&
Public Const MF_BYPOSITION = &H400
Public Const MF_GRAYED = &H1&
Public Const MF_DISABLED = &H2&

Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long)
As Long


Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA"
_
(ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, _
lpcMenuItemInfo As MENUITEMINFO) As Long

Declare Function EnableMenuItem Lib "user32" _
(ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As
Long) As Long


Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_SYSMENU = &H80000
Public Const WS_CAPTION = &HC00000 ' WS_BORDER Or
WS_DLGFRAME
Public Const WS_POPUP = &H80000000
Public Const WS_BORDER = &H800000
Public Const WS_POPUPWINDOW = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)


Public Const GWL_STYLE = (-16)


Public Const WM_NCPAINT = &H85
Public Const WM_NCACTIVATE = &H86
Public Const WM_GETDLGCODE = &H87
Public Const WM_NCMOUSEMOVE = &HA0
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const WM_NCLBUTTONUP = &HA2
Public Const WM_NCLBUTTONDBLCLK = &HA3
Public Const WM_NCRBUTTONDOWN = &HA4
Public Const WM_NCRBUTTONUP = &HA5
Public Const WM_NCRBUTTONDBLCLK = &HA6
Public Const WM_NCMBUTTONDOWN = &HA7
Public Const WM_NCMBUTTONUP = &HA8
Public Const WM_NCMBUTTONDBLCLK = &HA9

Public Const WS_THICKFRAME = &H40000
Public Const WS_OVERLAPPED = &H0&
Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or _
WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)


Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long

Declare Function GetActiveWindow Lib "user32" () As Long

Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As
Long

Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As
Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
As Any) As Long

Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long


Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long)
As Long


'-------------
Tom
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 12
Default Adding and Graying MAXIMIZE button on vba E2007 form system menu

Tom wrote:
Tom wrote:
Hi,
I was trying to add MINIMIZE and MAXIMIXE buttons to vba E2007 form
system menu - and after that gray MAXIMIZE button. The problem is that

Here's me again. I finally stumbled on how it may be done. In order to
disable by graying max-button from form system menu, it's enough to
only specify WS_MINIMIZEBOX and WS_SYSMENU consts for
SetWindowLong(hwnd, GWL_STYLE, lng) function:
lng= WS_MINIMIZEBOX or WS_SYSMENU

Regards
Tom
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding command button to menu excel-tr Excel Programming 0 March 28th 07 02:01 AM
adding command button to menu urkec Excel Programming 0 March 28th 07 12:57 AM
How to invoke a user form from a custom button on the menu bar JLGWhiz Excel Programming 0 January 20th 07 03:32 AM
Adding a Menu Item into a sheet as a button [email protected] Excel Programming 3 March 23rd 05 06:37 PM
Maximize Form Adrian[_7_] Excel Programming 3 September 22nd 04 03:31 PM


All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"