?
Solved

Customizing The Control Box

Posted on 2003-03-12
8
Medium Priority
?
358 Views
Last Modified: 2012-05-04
Hello,

i was wondering on how, or if it is possible to customize the control box were your minimize and maximize and the red close button are?
if anyone who's how Help will be greatly appreciated
thanks
0
Comment
Question by:kgo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Accepted Solution

by:
JMoon5FTM earned 80 total points
ID: 8123045
You need to subclass your window and handle WM_NCPAINT messages, like so:

Private Declare Function SetWindowLongA lib "user32" (byval hWnd as long, byval Offset as long, byval newValue as long) as long
private declare function CallWindowProcA lib "user32" (byval pProc as long, byval hWnd as long, byval message as long, byval wParam as long, byval lParam as long) as long

Dim DefProc as Long

sub EnableCustomBorderPaint()
   DefProc = SetWindowLongA(form1.hwnd, -4, addressof MyProc)
End Sub

Function MyProc(byval hWnd as long, byval message as long, byval wParam as long, byval lParam as long) as long
   if message = WM_NCPAINT then
      'Call Windows API functions to paint the window
   else
      'Pass the message on for default handling
      MyProc = CallWindowProcA(DefProc, hWnd, message, wParam, lParam)
   end if
end function
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 8123068
Yes, total control can be attained with APIs.  Please elaborate on exactly what kind of form you want to control. (MDI, modal, child?)  Or just try some of this, I took it from an MDI form where only a Close(X) button is allowed, also note that you should control the form menu(upper left) as well as the buttons(upper right):

Option Explicit

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 DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, _
 ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long

Const MF_BYPOSITION = &H400&
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WS_SYSMENU = &H80000

Private Const HELP_FINDER = 11


Private Sub RemoveMenus(frm As Form, _
  remove_restore As Boolean, _
  remove_move As Boolean, _
  remove_size As Boolean, _
  remove_minimize As Boolean, _
  remove_maximize As Boolean, _
  remove_separator As Boolean, _
  remove_close As Boolean)
Dim hMenu As Long
 
' Get the form's system menu handle.
hMenu = GetSystemMenu(hWnd, False)
'Do NOT rearrange this code as it operates by relative position!
If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION
If remove_separator Then DeleteMenu hMenu, 5, MF_BYPOSITION
If remove_maximize Then DeleteMenu hMenu, 4, MF_BYPOSITION
If remove_minimize Then DeleteMenu hMenu, 3, MF_BYPOSITION
If remove_size Then DeleteMenu hMenu, 2, MF_BYPOSITION
If remove_move Then DeleteMenu hMenu, 1, MF_BYPOSITION
If remove_restore Then DeleteMenu hMenu, 0, MF_BYPOSITION
End Sub

Private Sub MDIForm_Load()
Dim CurStyle As Long
Dim NewStyle As Long

CurStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
CurStyle = CurStyle And Not (WS_MINIMIZEBOX)
CurStyle = CurStyle And Not (WS_MAXIMIZEBOX)
CurStyle = CurStyle And Not (WS_THICKFRAME)
'CurStyle = CurStyle And Not (WS_SYSMENU)

NewStyle = SetWindowLong(Me.hWnd, GWL_STYLE, CurStyle)

RemoveMenus Me, True, False, _
   True, True, True, True, False

Me.Show
End Sub


0
 

Expert Comment

by:CleanupPing
ID: 8900197
kgo:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 49

Expert Comment

by:DanRollins
ID: 9664553
Moderator, my recommended disposition is:

    Accept JMoon5FTM's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 9664744
Well, I think my answer was better, more to the point and a "real" answer to the question...
0
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 9745279
Your suggestion modifies the menu - kgo specifically asks to modify the red close button.  This requires custom painting, not menu alteration.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 9752106
JMoon5FTM,
The question was "i was wondering on how, or if it is possible to customize the control box were your minimize and maximize and the red close button are?"
And you said "Your suggestion modifies the menu - kgo specifically asks to modify the red close button.  This requires custom painting, not menu alteration."

Well, you obviously did not try to run the code... Yes, it does modify the menu but it ALSO gives him a means of totally controlling the upper right control buttons as well - that is the first thing that occurs in the form load event.  In the example:

CurStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
CurStyle = CurStyle And Not (WS_MINIMIZEBOX)
CurStyle = CurStyle And Not (WS_MAXIMIZEBOX)
CurStyle = CurStyle And Not (WS_THICKFRAME)
'CurStyle = CurStyle And Not (WS_SYSMENU)
NewStyle = SetWindowLong(Me.hWnd, GWL_STYLE, CurStyle)

removes the minimize and maximize buttons from the window and also gives him a clue as to how to disable/remove the system menu altogether - and the function call:

RemoveMenus Me, True, False, _
   True, True, True, True, False

removes all but the move and close options from the window's system menu thereby making the menu consistent with the window's control buttons.

What good does it do to disable or remove a minimize button, for example, and not alter the window's system menu to prevent using it to do the same function? If you don't, you have lost the control you tried to attain by altering the buttons... my example allows the programmer how to take complete control of the window's control functions.  It MORE than answers his question, it affords him the complete control a thinking person will ultimately seek.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

777 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