Attribute VB_Name = "mWin" Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Módulo de controle de janelas externas ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Constantes de instanciamento Private Const WH_CBT As Long = 5 Private Const SWP_NOSIZE As Long = &H1 Private Const SWP_NOZORDER As Long = &H4 Private Const SWP_NOACTIVATE As Long = &H10 ' Handle para janela-mãe Global ParenthWnd As Long ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Cria tela normal ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function WinProcCenterScreen(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim rectForm As RECT, rectMsg As RECT Dim X As Long, Y As Long On Error Resume Next ' Verifica se janela foi chamada If (lMsg = WH_CBT) Then ' Exibe a janela GetWindowRect wParam, rectMsg ' Define posição X = Screen.Width / Screen.TwipsPerPixelX / 2 - (rectMsg.Right - rectMsg.Left) / 2 Y = Screen.Height / Screen.TwipsPerPixelY / 2 - (rectMsg.Bottom - rectMsg.Top) / 2 SetWindowPos wParam, 0, X, Y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE End If End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Cria tela centralizada ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function WinProcCenterForm(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim rectForm As RECT, rectMsg As RECT Dim X As Long, Y As Long On Error Resume Next ' Verifica se janela foi chamada If (lMsg = WH_CBT) Then ' Define centro GetWindowRect ParenthWnd, rectForm ' Exibe janela GetWindowRect wParam, rectMsg ' Centraliza X = (rectForm.Left + (rectForm.Right - rectForm.Left) / 2) - ((rectMsg.Right - rectMsg.Left) / 2) Y = (rectForm.Top + (rectForm.Bottom - rectForm.Top) / 2) - ((rectMsg.Bottom - rectMsg.Top) / 2) SetWindowPos wParam, 0, X, Y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE End If End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Abre janela sem modal ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function showNonModal(Who As Form, Optional Centralize As Boolean = False) ' Deixa a janela visível Who.Visible = True Exit Function '' Deixa form sempre visível 'SetAlwaysOnTop Who, True ' '' Se deve centralizar a tela 'If Centralize Then ' ' ' Centraliza ' Who.Left = (Screen.Width - Who.Width) / 2 ' Who.Top = (Screen.Height - Who.Height) / 2 ' ' ' Porém se estiver fora dos limites ' If (Who.Left < 0) Then: Who.Left = 0 ' If (Who.Top < 0) Then: Who.Top = 0 'End If '' Print 'DoEvents ' '' Tira do sempre visível 'SetAlwaysOnTop Who, False End Function