www.pudn.com > mini_remote.zip > ProcessDlg.cpp
// ProcessDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MainCtrl.h"
#include "ProcessDlg.h"
void ShowProcessList(void *m_Dlg)
{
CProcessDlg *dlg = (CProcessDlg *)m_Dlg;
SOCKET hSocket = dlg->m_hConnectSocket;
COMMAND_MSG msg;
memset(&msg,0,sizeof(COMMAND_MSG));
msg.msg_id = CMD_PROCESSINFO;
while(1)
{
int nRet=send(hSocket,(char *)&msg,sizeof(msg),NULL);
if(nRet==SOCKET_ERROR)
{
if(WSAGetLastError()==WSAEWOULDBLOCK)
{
Sleep(50);
continue;
}
else
{
return;
}
}
else
break;
}
while(1)
{
PROCESS_INFO info;
memset(&info,0,sizeof(PROCESS_INFO));
int nRet=recv(hSocket,(char *)&info,sizeof(PROCESS_INFO),NULL);
if(nRet==SOCKET_ERROR)
{
if(WSAGetLastError()==WSAEWOULDBLOCK)
{
Sleep(50);
continue;
}
else
return;
}
else
{
dlg->SetDlgItemText(IDC_RICHEDIT,info.ProcessName);
return;
}
}//end of while
}
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProcessDlg dialog
CProcessDlg::CProcessDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProcessDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProcessDlg)
//}}AFX_DATA_INIT
}
void CProcessDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProcessDlg)
DDX_Control(pDX, IDC_REFLASH, m_btn_2);
DDX_Control(pDX, IDC_KILLPROCESS, m_btn_1);
DDX_Control(pDX, IDC_EDIT_PID, m_edit_1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProcessDlg, CDialog)
//{{AFX_MSG_MAP(CProcessDlg)
ON_BN_CLICKED(IDC_KILLPROCESS, OnKillprocess)
ON_BN_CLICKED(IDC_REFLASH, OnReflash)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProcessDlg message handlers
BOOL CProcessDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_btn_1.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
m_btn_1.SetFontColor(RGB(100,50,280));
m_btn_2.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
m_btn_2.SetFontColor(RGB(100,50,280));
CString str = "在主机:"+strIP+"上";
SetWindowText(str);
AfxBeginThread((AFX_THREADPROC) ShowProcessList,this);
return TRUE;
}
void CProcessDlg::OnKillprocess()
{
CString m_pid;
GetDlgItemText(IDC_EDIT_PID,m_pid);
if (m_pid.IsEmpty())
{
MessageBox("空进程ID","err",MB_OK);
return;
}
COMMAND_MSG msg;
memset(&msg,0,sizeof(COMMAND_MSG));
msg.msg_id = CMD_KILLPROCESS;
strcpy(msg.wParam,m_pid.GetBuffer(0));
while(1)
{
int nRet=send(m_hConnectSocket,(char *)&msg,sizeof(msg),NULL);
if(nRet==SOCKET_ERROR)
{
if(WSAGetLastError()==WSAEWOULDBLOCK)
{
Sleep(50);
continue;
}
else
return;
}
else
return;
}
}
void CProcessDlg::OnReflash()
{
AfxBeginThread((AFX_THREADPROC) ShowProcessList,this);
}