WinKill() source code

WinKill() source code

本文关键字:code source WinKill      更新时间:2023-10-16

谁能从AutoIt分享WinKill()的源代码?

我想知道它是如何工作的消息(是/否/取消),以确保它被正确处理。我想用它来清理桌面从意外弹出窗口

从AutoIt的最新开源版本(以前是开源的)获取的源代码中可以看到,该函数向窗口发送WM_CLOSE消息。如果窗口没有在500ms内关闭,那么它会杀死创建该窗口的进程。

///////////////////////////////////////////////////////////////////////////////
// WinKill()
// Closes a window - uses more force than WinClose
///////////////////////////////////////////////////////////////////////////////
AUT_RESULT AutoIt_Script::F_WinKill(VectorVariant &vParams, Variant &vResult)
{
    Win_WindowSearchInit(vParams);
    if (Win_WindowSearch() == false)
        return AUT_OK;                          // Required window not found
    Util_WinKill(m_WindowSearchHWND);
    Util_Sleep(m_nWinWaitDelay);                // Briefly pause before continuing
    return AUT_OK;
} // WinKill()
///////////////////////////////////////////////////////////////////////////////
// Util_WinKill()
//
// Closes a window with extreme predjudice
//
///////////////////////////////////////////////////////////////////////////////
void Util_WinKill(HWND hWnd)
{
    DWORD      dwResult;
    LRESULT lResult = SendMessageTimeout(hWnd, WM_CLOSE, 0, 0, SMTO_ABORTIFHUNG, 500, &dwResult);   // wait 500ms
    if( !lResult )
    {
        // Use more force - Mwuahaha
        // Get the ProcessId for this window.
        DWORD   pid;
        GetWindowThreadProcessId( hWnd, &pid );
        // Open the process with all access.
        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
        // Terminate the process.
        TerminateProcess(hProcess, 0);
        CloseHandle(hProcess);
    }
} // Util_WinKill()

这不是一个开源函数。你不可能知道来源。然而,理解起来并不复杂。这是一个简单的函数,有很多If…then…打电话检查标准,然后简单地杀死窗户。与cmd命令非常相似。

AutoIt具有本地和标准功能。原生插件是开源的,你可以在AutoIt安装目录的Include文件夹中找到它们。另一方面,标准的不是开源的。