急救,在线等待,如何关闭一个应用程序啊?
解决方案 »
- 问一个mmio相关的问题
- TCP 只接受连接时,服务器第一次接受3m正常,第2,3,就有问题出错了
- CEdit的CtlColor
- 请问如何从OnWndMsg中如何直接查找出消息名称字符串
- 有消息钩子,API钩子,那有没有事件钩子?
- 大家在用VC编程序的时候,遇到过这个警告吗?This file has been modified outside of the source of editor.Do you want to reload it?
- 谁有XMLTree/X的license?高分求救!
- 一个关于Cedit的问题
- 函数InternetOpen()的用法
- 怎样改变CPropertySheet的“确定”和“取消”按钮上文字
- 急!!!请帮忙(为什么CListCtrl的表头出不来)
- 如何用API函数操作文件的读写,请给出个例子,谢谢!必给分
2.SendMessage(hwnd,WM_DESTROY,..)
--------------------
各位,我只知道那个程序执行文件的所在位置,该如何结束啊?需要枚举系统中的进程,然后GetModuleFileName来得到文件名称,判断是否运行,如果运行的画,用TerminateProcess来终止他。
http://www.codeguru.com/system/PList.html
single interface to enumerate processes//enum process to find a certain module
void CPtbView::IsAppRun(CString modulename)
{
DWORD buf[4096];
DWORD num;
TCHAR filenamebuf[_MAX_PATH+1];
HMODULE hModule;
DWORD cbReturned;
BOOL bret=EnumProcesses(buf,4095,&num);
bool bfound=false;
CString msg;
if(!bret)
{
AfxMessageBox("Error EnumProcesses");
return;
}
for(int i=0;i<(int)num;i++)
{
HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION¦ PROCESS_VM_READ,false,buf[i]);
if(hProcess ==NULL)
continue;
bret=EnumProcessModules(hProcess ,&hModule, sizeof(hModule), &cbReturned );
if(bret)
{
DWORD dwret=GetModuleFileNameEx(hProcess ,hModule,filenamebuf,_MAX_PATH);
CloseHandle( hProcess ) ;
if(dwret==0)
{
msg.Format("%d",GetLastError());
AfxMessageBox(msg);
break;
}
else
{
TCHAR* pfind=_tcsstr(filenamebuf,modulename);
if(pfind)
{
bfound=true;
break;
}
}
}
}
if(bfound)
AfxMessageBox("Found it");
else
AfxMessageBox("Not found");
}void CPtbView::OnViewCheckrun()
{
IsAppRun("notepad.exe");
}
用1.FindWindow(..)
2.SendMessage(hwnd,WM_DESTROY,..)
将程序关闭. 不能根据执行文件的位置进行判断.
找到窗口的指针, lpszClassName为窗口的类名,这时可以设为NULL, lpszWindowName 设为窗口的名称.
CWnd* pw=(CWnd *)FindWindow(lpszClassName,lpszWindowName)
关闭窗口
pw->DestroyWindow();
或:
pw->PostMessage(WM_QUIT,0,0);
2.pw->DestroyWindow();
或:
pw->PostMessage(WM_QUIT,0,0);