[RESOLVED] Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Hi Guys,
I have a custom title bar(TitleBar) with custom minimize,maximize and close buttons.
I need a code to make a form following behaviours :
1)Minimize the form.
2)Normal i.e like Form.SindowState = vbNormal
i found the code to maximize from the below post :
http://www.vbforums.com/showthread.php?t=394260
In form load I use the maximize code from above link. Now the question is when the user clicks minimize form button how to minimize? and when the user double clicks the TitleBar how to bring form to Normal?
The answer should depend on the above link. Because thats the code I used to Maximize.
Please reply.
The maximize code(from above link) is :
Code:
1.
Option Explicit
2.
3.
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
4.
ByVal uAction As Long, _
5.
ByVal uParam As Long, _
6.
lpvParam As Any, _
7.
ByVal fuWinIni As Long) As Long
8.
9.
Private Const SPI_GETWORKAREA As Long = 48
10.
11.
Private Type RECT
12.
lLeft As Long
13.
lTop As Long
14.
lRight As Long
15.
lBottom As Long
16.
End Type
17.
18.
Private Sub Form_Load()
19.
Dim deskRECT As RECT
20.
21.
Call SystemParametersInfo(SPI_GETWORKAREA, 0&, deskRECT, 0&)
22.
23.
With deskRECT
24.
Me.Move .lLeft * Screen.TwipsPerPixelX, _
25.
.lTop * Screen.TwipsPerPixelX, _
26.
(.lRight - .lLeft) * Screen.TwipsPerPixelX, _
27.
(.lBottom - .lTop) * Screen.TwipsPerPixelX
28.
End With
29.
End Sub
Thank you.
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
How about?
Code:
Option Explicit
Private Sub Form_Load()
Me.WindowState = vbMaximized
End Sub
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Quote:
Originally Posted by
RhinoBull
How about?
Code:
Option Explicit
Private Sub Form_Load()
Me.WindowState = vbMaximized
End Sub
I am assuming the form is borderless since custom titlebar is in use. Setting form to vbMaximized will cover taskbars if form is borderless. The code posted will get available real estate less the taskbars.
Though minimizing a borderless form won't put it on the taskbar if that is what the OP wants; it will be minimized above the taskbar. In order to get the borderless form minimized to the taskbar, I think the form will need to have the window styles of system menu & caption added back. May want to search using key terms: borderless minimize taskbar
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Here is one solution that will allow you to treat a minimized window as if it were you're actual borderless form.
1) Add a new form to your project. It will never be seen and has no code. In sample code below, it is Form2
2) Copy the following code below & modify for your project
Code:
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE As Long = &H10
Private WithEvents frmProxy As Form
Private Sub Command1_Click()
' .... when minimzing
Form2.Caption = Me.Caption ' or whatever caption you want on the taskbar
Form2.Move Me.Left, Me.Top
Form2.WindowState = vbMinimized
Form2.Show
Me.Visible = False
Set frmProxy = Form2 ' whatever form will act as your minimize proxy
End Sub
Private Sub frmProxy_Resize()
If frmProxy.Visible Then
frmProxy.Visible = False ' triggers another _Resize event
Else
If frmProxy.WindowState = vbMaximized Then
' maximize your form
End If
Me.Visible = True
PostMessage frmProxy.hWnd, WM_CLOSE, 0, 0
Set frmProxy = Nothing
End If
End Sub
Private Sub frmProxy_Unload(Cancel As Integer)
Set frmProxy = Nothing
Unload Me
End Sub
The above works for minimizing, because your form is never really minimized, it is just hidden. And when the minimized proxy form is restored or maximized, you maximize your form, as needed, then show your form while hiding and unloading the proxy form. Simple
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Sorry for giving little wrong information there...
I can minimize the form using
windowstate=vbminimized.
the problem is here.
When I double click on my custom TitleBar, the form should be normal.
For this windowstate = vbnormal does not work.
Now assume the window is maximized by above code, now I double click on custom titlebar, the form should come middle of the screen like we do normall dbl click on windows.
here is my Dbl click event :
Code:
Private Sub UCMenuBar_DblClick()
me.windowstate = vbnormal '
End Sub
'Doesnt work because the form is not really maximized
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
You're using the wrong constant. Use vbDefault not vbNormal
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Take a look at this nicely wrapped class - it's basically plug-and-play.
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Quote:
Originally Posted by
LaVolpe
You're using the wrong constant. Use vbDefault not vbNormal
vbdefault and vbNormal : Both have a value of 0. Does it make any diff?
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Quote:
Originally Posted by
tonydsouza1987
vbdefault and vbNormal : Both have a value of 0. Does it make any diff?
Ummm, it doesn't. Canned response; my bad.
I was misreading. Anyway I was thinking the form was minimized, it is maximized. Yes, that code won't do anything because it is not maximized. You should probably cache the current position & size of your form before you maximize it. Then when you want to restore, set your form position & size to the cached values
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Quote:
Originally Posted by
LaVolpe
Ummm, it doesn't. Canned response; my bad.
I was misreading. Anyway I was thinking the form was minimized, it is maximized. Yes, that code won't do anything because it is not maximized. You should probably cache the current position & size of your form before you maximize it. Then when you want to restore, set your form position & size to the cached values
Hey LaVolpe... can you give me some code to do that please???
And just to mention that I am still using your LVButton.. its superb.. I guess it does not take much time to figure u out the above code.. Thanks for your concern.....
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
1) Create 4 form-level variables at top of your form
2) Move that code you have in form_load to its own sub, maybe called MaximizeMe()
3) With that code you are moving, add code to save the form's Top, Left, Width, & Height values to those 4 new variables
4) Whenever you need to maximize the form, call MaximizeMe
5) Whenever you need to restore from "maximized" state, supply the 4 variables to Me.Move left, top, width, height
Re: Customize Minimize/Maximize/Normal behavior of form having custom titlebar
Quote:
Originally Posted by
LaVolpe
1) Create 4 form-level variables at top of your form
2) Move that code you have in form_load to its own sub, maybe called MaximizeMe()
3) With that code you are moving, add code to save the form's Top, Left, Width, & Height values to those 4 new variables
4) Whenever you need to maximize the form, call MaximizeMe
5) Whenever you need to restore from "maximized" state, supply the 4 variables to Me.Move left, top, width, height
Thank You Very much LaVolpe.. That Works.... :check: