gpt4 book ai didi

c++ - WinKill() 源代码

转载 作者:行者123 更新时间:2023-11-27 22:56:38 29 4
gpt4 key购买 nike

有人可以分享 WinKill() from AutoIt 的源代码吗? ?

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

最佳答案

正如我们在下面的源代码中看到的那样,该源代码取自最新的 AutoIt 开源版本(以前是开源的)并且可用 here , 函数向窗口发送 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()

关于c++ - WinKill() 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32336995/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com