程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c++-今天寫代碼給360安全浏覽器窗口發消WM_CLOSE息竟然它不睬我,想問問大神怎麼回事?

c++-今天寫代碼給360安全浏覽器窗口發消WM_CLOSE息竟然它不睬我,想問問大神怎麼回事?

編輯:編程綜合問答
今天寫代碼給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. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved