问题描述
- 今天写代码给360安全浏览器窗口发消WM_CLOSE息竟然它不睬我,想问问大神怎么回事?
-
想想这种情况应该是不可能的,浏览器在windows系统下运作可以不听操作系统的命令?怎么可能,只可能我获得的东西不正确void CtestDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
STARTUPINFO suInfo;
PROCESS_INFORMATION procInfo;memset (&suInfo, 0, sizeof(suInfo)); suInfo.cb = sizeof(suInfo); suInfo.dwFlags = STARTF_USESHOWWINDOW; suInfo.wShowWindow = TRUE; CHAR chCmdLine[] = " http://www.baidu.com/"; HKEY key = NULL; CHAR szXplorer[MAX_PATH]; DWORD dwBufLen; DWORD type = REG_SZ; ZeroMemory(szXplorer,MAX_PATH); if(ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\shell\open\command", 0, KEY_QUERY_VALUE, &key)) { LONG lRet; lRet = ::RegQueryValueEx(key,NULL,NULL,&type,(LPBYTE)szXplorer,&dwBufLen); if(lRet == ERROR_SUCCESS) strcat(szXplorer, chCmdLine); RegCloseKey(key); } BOOL bRet = CreateProcess(NULL/*"C://Program Files//360Chrome//Chrome//Application//360chrome.exe"*//*"c://program files//internet explorer//iexplore.exe"*/, szXplorer, NULL, NULL, false, NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &procInfo); if(bRet) { CloseHandle(procInfo.hThread); CloseHandle(procInfo.hProcess); } m_dwProcessId = procInfo.dwProcessId;
}
void CtestDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
HANDLE handle = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, FALSE, m_dwProcessId);
EnumWindows(EnumWindowsProc, m_dwProcessId);
CloseHandle(handle);
}BOOL CALLBACK CtestDlg::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD wndPid;
CString Title;
// lParam = procInfo.dwProcessId;// This gets the windows handle and pid of enumerated window. GetWindowThreadProcessId(hwnd, &wndPid); // This gets the windows title text // from the window, using the window handle CWnd::FromHandle( hwnd )->GetWindowText(Title); // this makes sure that the PID matches that PID we started, and window // text exists, before we kill it . I don't think this is really needed, // I included it because some apps have more than one window. if ( wndPid == (DWORD)lParam && Title.GetLength() != 0) { // Please kindly close this process ::PostMessage(hwnd, WM_CLOSE, 0, 0); return false; } else { // Keep enumerating return true; }
}
解决方案
是不是没取对句柄?用spy++看看。或者试试其他几个关闭的消息WM_DESTROY ,WM_CLOSE,WM_QUIT。或者发送鼠标点击消息,参数传关闭按钮的坐标。
解决方案二:
它如果能轻易发一个消息就关了,那才是奇怪的事情。
解决方案三:
几种可能:
1. 360应该是没有处理的WM_CLOSE消息,它不允许你这么发送消息来关闭它。
2. 你的消息没有发送给正确的窗口
解决方案四:
你的系统上也安装了360安全卫士吗,如果安装了可能会有影响。
360可能挂住了 sendmessage或者postmessage函数。
另外,你测试过 GetWindowThreadProcessId(hwnd, &wndPid) 值返回的是360安全浏览器的进程id不,和任务管理器里的比较一下