Welcome Guest.


Close the window of other applications with VB (known window handle)

Asked by: Walsh 32 views IT July 2, 2022

'I wrote a code and found the window handle with FindWindow to find the window handle, and then send the information with SendMessage to close it to close it. But I display the return value in the FindWindow function, and the handle is right. But the SendMessage function seems to be useless. Even the simplest windows (such as VBS pop -up window, VB testing window is not used with Cancel) can't be turned off. What is the problem? I did n’t use an error, but I could n’t get it off, and I did n’t add a statement on Error ResuMe NEXT or GOTO. Not to mention the end, I do a pop -up window interception. When it comes out, it is closed. Do n’t manually operate it. It ’s better to turn off the button directly.我的代码:

Private Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

private Declare Function SendMessage Lib "user32 "Alias" SendMessagea "(byval hwnd as long, byval wmsg as long, byval waram as long, lparam as long 'statement

A = Findwindow (" title ")

'Sendmessage window:

Sendmessage a, WM_Close, 0, 0

Don't ask for the great god.

Addition: I am closed by the window is not the process. The detection process exists. Write one by yourself

1 Answers

  1. +7Votes  

    Your WM_CLOSE is not defined, of course,

    Define a

    Private const WM_Close = &H10

    or direct

    Sendmessage a, &H10, 0, 0

    Walsh- July 2, 2022 |