Solved

two simple question !

Posted on 2000-03-22
11
138 Views
Last Modified: 2010-05-02
A vb program has three form, named main, left and right form. When
 the program is executed, all form should appear on the screen.
   
         - How to disable user to resize main form, while I want to select
           sizeable for form and still have minimize, maximize and close button ?

         - When minimal button is pressed in main form, other forms will also
            be minimized ? And when main form is maximized, all other forms
            should also be maximized ?


Thanks !    
0
Comment
Question by:sing_web
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 2646866
Simplest and most straightforward approach would be to use a MDI form to hold the three forms. Assuming the forms are equal size.. you can issue Tile Horizontal commands to always keep the three properly aligned and sized.. <smile>.
0
 
LVL 32

Accepted Solution

by:
bhess1 earned 25 total points
ID: 2646913
1 - how to disable resizing.

Add these constants to your project - set the values to the height & width of your form:

Const LockedFormWidth = 500
Const LockedFormHeight = 400


In the Form_Resize event

Sub Form1_Resize()
  If Me.Height <> LockedFormHeight Or Me.Width<>LockedFormWidth Then
    Me.Height=LockedFormHeight
    Me.Width=LockedFormWidth
  End If
End Sub

You can't actually stop them from resizing the form, but you can instantly set it back to the correct width and height.

2 - Minimize and maximize forms in sync.

Add this global variable into your project:

Global LastWindowState as Integer


Add this to your Form_Load event:

   LastWindowState = -1   ' Not yet loaded window


More code in the Form_Resize event:

Sub Form1_Resize()

  If LastWindowState = vbMinimized and Me.WindowState <> vbMinimized Then
    Form2.WindowState = vbNormal
    Form3.WindowState = vbNormal
  End If

  If Me.WindowState = vbNormal Then   ' Do this if not Minimized or Maximized
    If Me.Height <> LockedFormHeight Or Me.Width<>LockedFormWidth Then
      Me.Height=LockedFormHeight
      Me.Width=LockedFormWidth
    End If
  Else     ' Minimized or Maximized
    If Me.WindowState = vbMinimized Then   ' Window minimized
      Form2.WindowState = vbMinimized
      Form3.WindowState = vbMinimized
    End If
  End If

  LastWindowState = Me.WindowState

End Sub

So, if the user Maximizes Form1, then Form2 and Form3 are returned to normal state.  If Form1 is minimized, form2 and form3 are minimized.  If form1 is restored to normal, then form2 and form3 are returned to normal.  If form1 is resized, it resizes itself back to the proper size.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2646918
If your form has a fixed border, you can change the MinButton and MaxButton properties True in design time.

In the Resize event of the main form, you can set the WindowState of the other forms as well:

Option Explicit

Private Sub Form_Load()
    Form2.Show
End Sub

Private Sub Form_Resize()
    Form2.WindowState = Me.WindowState
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2646946
Actually, you can stop the user from resizing the form even if the BorderStyle is set to Sizable:

"HOWTO: Limit a Window's Minimum and Maximum Size"

http://support.microsoft.com/support/kb/articles/Q185/7/33.ASP
0
 

Author Comment

by:sing_web
ID: 2646999
bhess1 :

I think this code will not work because I had this idea before.

Sub Form1_Resize()
   If Me.Height <> LockedFormHeight Or       Me.Width<>LockedFormWidth Then
          Me.Height=LockedFormHeight
          Me.Width=LockedFormWidth
   End If
 End Sub


when you try to minimize it, you will get error.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:sing_web
ID: 2647011
bhee1 :

your second answer should put in the form_activate, right ?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2647013
Why not set the form to Fixed-Single, and enable the min and max buttons?
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2647031
"when you try to minimize it, you will get error."

That's why you check the WindowState, and only reset the size if it is vbNormal.

This code works best in the form_resize event.  You could add the resizing code to form_load, but form_resize is called the first time you show a form as well.
0
 
LVL 27

Expert Comment

by:Ark
ID: 2647301
Hi
Your question is not simple, and Complete solytion require subclassing, because Form_resize event occure AFTER resizing, so you'll see  changing size. Anyway, here is a code
'--bas module code
Type POINTAPI
     x As Long
     y As Long
End Type
Type MINMAXINFO
     ptReserved As POINTAPI
     ptMaxSize As POINTAPI
     ptMaxPosition As POINTAPI
     ptMinTrackSize As POINTAPI
     ptMaxTrackSize As POINTAPI
End Type

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Const WM_SYSCOMMAND = &H112
Const SC_MINIMIZE = &HF020&
Const SC_MAXIMIZE = &HF030&
Const SC_CLOSE = &HF060&

Public Const GWL_WNDPROC = (-4)
Const GWL_STYLE = (-16)
Const WS_MAXIMIZE = &H1000000
Const WM_GETMINMAXINFO = &H24

Public OldProc As Long
Public StartWidth As Long
Public StartHeight As Long
Dim MMinfo As MINMAXINFO

Public Function WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case wMsg
    Case WM_GETMINMAXINFO
         If GetWindowLong(hwnd, GWL_STYLE) And WS_MAXIMIZE Then
            WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
            Exit Function
         End If
         CopyMemory MMinfo, ByVal lParam, LenB(MMinfo)
' Max/Min size when tracking
         MMinfo.ptMinTrackSize.x = StartWidth
         MMinfo.ptMinTrackSize.y = StartHeight
         MMinfo.ptMaxTrackSize.x = StartWidth
         MMinfo.ptMaxTrackSize.y = StartHeight
         CopyMemory ByVal lParam, MMinfo, LenB(MMinfo)
         Exit Function
    Case WM_SYSCOMMAND
         Select Case wParam
                Case SC_MINIMIZE
'All your code here to minimize other windows
                Case SC_CLOSE
                     'Close code
                Case SC_MAXIMIZE
                     'Max_Code
'All your code here to maximize other windows
         End Select
    End Select
    WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
End Function

'--Form code--
Private Sub Form_Load()
 StartWidth = Width / Screen.TwipsPerPixelX
 StartHeight = Height / Screen.TwipsPerPixelY
 OldProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
 SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    SetWindowLong Me.hwnd, GWL_WNDPROC, OldProc
End Sub

'Don't stop this code from IDE - it cause GPF
' I thing it's a complete solution, but post it as comment because you can choose more easy (but not complite) way from previous code
Cheers
0
 

Author Comment

by:sing_web
ID: 2647346
bhee1 :

your second answer should put in the form_activate, right ?
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2650074
No, the second answer also goes into the resize event
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 47
VBA to copy paste columns form one file to other 20 79
passing parameter in sql procedure 9 50
Adding to a VBA? 6 48
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now