C++ WinKill()源代码

C++ WinKill()源代码,c++,autoit,C++,Autoit,有人能分享你的源代码吗 我想知道它如何处理消息(是/否/取消),以确保正确处理。我想用它清除桌面上意外弹出的窗口。它不是一个开源函数。你不可能知道来源。然而,理解起来并不复杂。这是一个简单的函数,包含很多If…then。。。调用以检查标准,然后简单地关闭窗口。与使用cmd命令的操作非常类似 AutoIt具有本机和标准功能。本机是开源的,您可以在Include文件夹中的AutoIt安装目录中找到它们。 另一方面,标准的不是开源的。它们是用C++编写的。 它不是开源函数。你不可能知道来源。然而,理解

有人能分享你的源代码吗


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

它不是一个开源函数。你不可能知道来源。然而,理解起来并不复杂。这是一个简单的函数,包含很多If…then。。。调用以检查标准,然后简单地关闭窗口。与使用cmd命令的操作非常类似

AutoIt具有本机和标准功能。本机是开源的,您可以在Include文件夹中的AutoIt安装目录中找到它们。
另一方面,标准的不是开源的。它们是用C++编写的。

它不是开源函数。你不可能知道来源。然而,理解起来并不复杂。这是一个简单的函数,包含很多If…then。。。调用以检查标准,然后简单地关闭窗口。与使用cmd命令的操作非常类似

AutoIt具有本机和标准功能。本机是开源的,您可以在Include文件夹中的AutoIt安装目录中找到它们。
另一方面,标准的不是开源的。它们是用C++编写的。

,如下面所见,在源代码中,从最新的开源AutoIP(当它是开放源代码)时可用的,该函数将WMYCalm消息发送到窗口。如果窗口在500毫秒内未关闭,则会终止创建窗口的进程

///////////////////////////////////////////////////////////////////////////////
// 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()

正如我们在下面的源代码中所看到的,源代码取自AutoIt的最新开源版本(当它以前是开源的时候),并且可用,该函数向窗口发送WM_CLOSE消息。如果窗口在500毫秒内未关闭,则会终止创建窗口的进程

///////////////////////////////////////////////////////////////////////////////
// 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()