Quantcast
Channel: Fechar um form em tempo ocioso
Viewing all articles
Browse latest Browse all 2

Fechar um form em tempo ocioso

$
0
0

olá a todos. Gostaria de uma ajuda

tenho um form emvba que ocupa toda atela do computador, e no mesmo tem duas textbox nas quais o usuario digita a senha e caso esteja certa o form fecha e abre um form com uma contagem regressiva de tempo de uma hora. Minha dúvida é o seguinte e se o usuario sair do computador antes desse tempo o pc ficará lá ligado até que de uma hora e eu gostaria de que o frm de login fechasse caso passasse um tempo de 5 minutos ou seja fechar em tempo ocioso. Como faço isso em vba

(declaração geral userform1)

Private Declare Function FindWindowA _
Lib "USER32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function RemoveMenu _
Lib "USER32" ( _
ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) _
As Long
Private Const MF_BYPOSITION As Long = &H400
Private Declare Function GetSystemMenu Lib "USER32" (ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "USER32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowRect Lib "USER32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ReleaseCapture Lib "USER32" () As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "USER32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Private FensterRegion&, Region&
Private Hauptfensternummer&, Clientfensternummer&
Private dummy As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Const GW_CHILD = 5
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Declare Function ShowWindow Lib "USER32" _
    (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
'Private Declare Function FindWindow Lib "user32" _
'    Alias "FindWindowA" (ByVal lpClassName As String, _
'    ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "USER32" _
    Alias "FindWindowExA" (ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long
    Sub TaskBar(blnValue As Boolean)
    Dim lngHandle As Long
    Dim lngStartButton As Long

    lngHandle = FindWindow("Shell_TrayWnd", "")
    If blnValue Then
        ShowWindow lngHandle, 5
    Else
        ShowWindow lngHandle, 0
    End If
End Sub

________________________________________________________
(botão entrar userform1(login))

Private Sub CommandButton4_Click()
If TextBox1.Text = TextBox2.Text Then
Unload UserForm1
UserForm2.Show
End If
End Sub

______________________________________________________

(inicialização do form login(UserForm1))

Private Sub UserForm_Initialize()
Dim lFrmHdl As Long, iCount As Integer
lFrmHdl = FindWindowA(vbNullString, Me.Caption)
If lFrmHdl <> 0 Then
For iCount = 0 To 1
      RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
Next iCount
End If
Call SemLEgenda
Application.WindowState = xlMaximized
With Me
.Width = Application.Width
.Height = Application.Height
Dim A As Boolean
A = False
TaskBar (A)
Range("B1").Select
    ActiveCell.FormulaR1C1 = "12:03:00 AM"
    Range("B2").Select
'inicioTempo
'UserForm1.Show
'UserForm2.Show
End With
End Sub

______________________________________________________

(form com a contagem regressiva(userform2))

inicialização do form

Private Sub UserForm_Initialize()

Dim hwnd As Long
    hwnd = FindWindowA(vbNullString, Me.Caption)
    SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF
inicioTempo
End Sub

______________________________________________________

geral do userform2

Private Declare Function FindWindowA Lib "USER32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "USER32" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "USER32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
________________________________________________________

modulos


módulo 1

Sub TaskBar(blnValue As Boolean)
    Dim lngHandle As Long
    Dim lngStartButton As Long

    lngHandle = FindWindow("Shell_TrayWnd", "")
    If blnValue Then
        ShowWindow lngHandle, 5
    Else
        ShowWindow lngHandle, 0
    End If
End Sub

______________________________________________________

módulo 2

Sub inicioTempo()
Application.OnTime Now + TimeValue("00:00:01"), "proximo"
End Sub

Sub proximo()
If Range("B1") = 0 Then
Unload UserForm2
UserForm1.Show
Exit Sub
End If
'Plan1.Range("E1").Value = Plan1.Range("E1").Value - TimeValue("00:00:01")
Range("B1").Value = Range("B1").Value - TimeValue("00:00:01")
inicioTempo
UserForm2.Label2.Caption = Format(Range("B1").Value, "hh:mm:ss")
'contar
End Sub



Sub paraContagem()
Application.OnTime Now + TimeValue("00:00:01"), "proximo", , False
End Sub





Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images