Ir para conteúdo
Fórum Script Brasil
  • 0

Run-time error '424': Object required


platchuk

Pergunta

Galera, terminei um projeto aqui mas quando eu executo uso um timer/button pra executar uma açao da o erro Run-time error '424': Object required

2r4lzma.jpg

será q alguma coisa deve ta errada no code? vou postar ele pra vocês verem:

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
Declare Function sendmessagebystring Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function getwindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Public Const WM_CLOSE = &H10
    Public Const GW_CHILD = 5
    Public Const GW_HWNDFIRST = 0
    Public Const GW_HWNDLAST = 1
    Public Const GW_HWNDNEXT = 2
    Public Const GW_HWNDPREV = 3
    Public Const GW_MAX = 5
    Public Const GW_OWNER = 4
Public Sub KillWin(Title As String)
    Dim a, hwnd
    hwnd = FindWindowByTitle(Title)
    a = sendmessagebystring(hwnd, WM_CLOSE, 0, 0)
End Sub
Function FindWindowByTitle(Title As String)
    Dim a, b, Caption
    a = getwindow(frmMain.hwnd, GW_OWNER)
    Caption = GetCaption(a)
    If InStr(1, LCase(Caption), LCase(Title)) <> 0 Then
        FindWindowByTitle = b
        Exit Function
    End If
    b = a
    Do While b <> 0: DoEvents
        b = getwindow(b, GW_HWNDNEXT)
        Caption = GetCaption(b)
        If InStr(1, LCase(Caption), LCase(Title)) <> 0 Then
            FindWindowByTitle = b
            Exit Do
            Exit Function
        End If
    Loop
End Function
Function GetCaption(hwnd)
    Dim hwndLength%, hwndTitle$, a%
    hwndLength% = GetWindowTextLength(hwnd)
    hwndTitle$ = String$(hwndLength%, 0)
    a% = GetWindowText(hwnd, hwndTitle$, (hwndLength% + 1))
    GetCaption = hwndTitle$
End Function

Private Sub Command1_Click()
Call KillWin("WPE")
End Sub

Editado por platchuk
Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

você ta executando o .exe já compilado, então fica dificil de saber.

agora, se você executar o projeto a partir do editor do visual basic (apertando F5), na hora q o erro ocorrer, você aperta "Debug" e ele vai mostrar qual a linha q esta errada.

sem saber qual a linha fica complicado.

mas pela mensagem do erro, olhando aqui, eu chuto q o seu form não se chame frmMain como você colocou na funcao FindWindowByTitle().

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...