Solved

MinButton=true Maxbutton=False

Posted on 2001-08-10
10
1,076 Views
Last Modified: 2008-01-09
I am trying to turn off the MaxButton and the closebutton.
This is what I am doing:
frmConnect.MaxButton = False


But it will not let me do that. I tried to set the borderStyle property but it does not have the functionality that I need. In short what I want to do is to "gray out" the MaxButton and the close button. How can I do that?
0
Comment
Question by:DandL
  • 5
  • 3
  • 2
10 Comments
 
LVL 6

Expert Comment

by:kahlean
ID: 6372620
1. Set the border style to fixedsingle. Now the min and max botton will be gray out.

THen set the minbutton to true and maxbutton to false

Regards
0
 
LVL 1

Author Comment

by:DandL
ID: 6372653
That does not seem to work I get this error.
"Function marked as restricted or uses a type not supported in Visual Basic"

I want to be able to see all three buttons, but i only want to be able to click the min button.  What I ment by grayed out is that the button is unclickable.  Can this be done?
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372661
Set the property controlbox to false.
Form1.controlbox = False

WoK
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372671
You can also grey out the Minmax Buttons with:
Form1.MaxButton = False
Form1.MinButton = False

WoK






0
 
LVL 6

Expert Comment

by:kahlean
ID: 6372705
THe problem is that, if your set the controlbox to flase, the min and max button will disable as well. Nevertheless you can disable the close button without the api code here.
*********************************************************************

Option Explicit
Public defWindowProc As Long

Public Const GWL_WNDPROC As Long = (-4)
Public Const WM_NCHITTEST As Long = &H84
Public Const HTNOWHERE As Long = 0
Public Const HTCLOSE As Long = 20




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 CallWindowProc Lib "User32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


Public Sub SubClass(hWnd As Long)
 On Error Resume Next
 defWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
 End Sub

Public Sub UnSubClass(hWnd As Long)
 If defWindowProc Then
SetWindowLong hWnd, GWL_WNDPROC, defWindowProc
defWindowProc = 0
 End If
End Sub

Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
 Dim retVal As Long
retVal = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam)
If uMsg = WM_NCHITTEST Then
 If retVal = HTCLOSE Then retVal = HTNOWHERE
End If
WindowProc = retVal
End Function

*********************************************************

Call the form using this way

Private Sub Form_Load()
 Call SubClass(Me.hWnd)
End Sub

***********************************************************

You can set the max button to disable and the min button to enable. THe border style remain as fixed single or sizebale

Regards
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372731
Sorry, you can't reset the properties at runtime ...

WoK
0
 
LVL 6

Accepted Solution

by:
kahlean earned 100 total points
ID: 6372796
Sorry my earlier code only disable the close button but dont gray it out. The following code will. Just place the code as a class module and name it as clsDisableClose. For the min and max button set it to true and false at design time respectively. You can t do it at ruin time. I have tested this and it work
 
********************************************************************
Option Explicit

Private Const MF_BYCOMMAND As Long = &H0&
Private Const MF_GRAYED As Long = &H1&
Private Const SC_CLOSE As Long = &HF060&
Private Const MF_ENABLED As Long = &H0&
Private Const FOOLVB As Long = -10


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

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
       ByVal bRevert As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" _
       (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
       ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
   
Public Sub DisableClose(frm As Form)

Dim hMenu As Long
   hMenu = GetSystemMenu(frm.hwnd, 0)
   If hMenu Then
     Call ModifyMenu(hMenu, SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED, FOOLVB, "Close")
     Call DrawMenuBar(Form1.hwnd)
   End If

End Sub

****************************************************
Private Sub Form Load

     Dim disClose As clsDisableClose
     Set disClose = New clsDisableClose
     disClose.DisableClose Me
     Set disClose = Nothing

End Sub

************************************************************
0
 
LVL 1

Author Comment

by:DandL
ID: 6372904
I had to call it this way for it to work

 Call DisableClose(Me)


It would not recognize the type this way clsDisableClose or DisableClose.

Thanks for your help.  I am upping the points to 100 because it was more complex then I thought.

DandL
0
 
LVL 6

Expert Comment

by:kahlean
ID: 6372926
no problem dandl, glad i could help here

Regards
0
 
LVL 6

Expert Comment

by:kahlean
ID: 6372936
>>It would not recognize the type this way clsDisableClose or DisableClose.

This might because that you did not place it as a class module and the namne is not the same as the calling function. But anyway glad i could help here

REgards
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 59
VBA open file from excel cell 4 42
Add and format columns in vb6 7 56
How to set the row selection as it was prior leaving the datagrid in vb6 3 42
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question