- 博客(0)
- 资源 (1)
- 收藏
- 关注
FreeCode2008.rar
// CmdShellDlg.cpp : implementation file
//
#include "stdafx.h"
#include "darkshell.h"
#include "CmdShellDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCmdShellDlg dialog
CCmdShellDlg::CCmdShellDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCmdShellDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCmdShellDlg)
m_Cmd = _T("net user");
//}}AFX_DATA_INIT
}
void CCmdShellDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCmdShellDlg)
DDX_Control(pDX, IDC_EDIT_SHELL, m_EdtShell);
DDX_Text(pDX, IDC_EDIT_CMD, m_Cmd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCmdShellDlg, CDialog)
//{{AFX_MSG_MAP(CCmdShellDlg)
ON_BN_CLICKED(IDC_BTN_RUN, OnBtnRun)
ON_BN_CLICKED(IDC_BTN_CLEAN, OnBtnClean)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCmdShellDlg message handlers
BOOL CCmdShellDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the small icon for this dialog
SetIcon(AfxGetApp()->LoadIcon(IDI_ICOBTN_SHELL), FALSE);
CenterWindow();
// TODO: Add extra initialization here
TCHAR szIp[100];
DWORD dwPort = m_hServer.GetPeerName(szIp);
CString strTitle; strTitle.Format(_T("超级终端@%s:%d"), szIp, dwPort);
SetWindowText(strTitle);
//设置回调
m_hServer.SetCallBack(this);
//开始CmdShell
m_hServer.Begin();
return TRUE;
}
void CCmdShellDlg::OnCancel()
{
// TODO: Add extra cleanup here
m_hServer.SendCmd(_T("exit\r\n"));
m_hServer.Close();
//非模式对话框,需要这样销毁对话框
DestroyWindow();
//CDialog::OnCancel();
}
void CCmdShellDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
//delete掉主对话框中new出来的指针
delete this;
CDialog::PostNcDestroy();
}
BOOL CCmdShellDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
int nVirtKey = (int)pMsg->wParam;
if (nVirtKey == VK_RETURN)
{
//如果是回车在这里做你要做的事情,或者什么也不作
return TRUE;
}
if (nVirtKey == VK_ESCAPE)
{
//如果是ESC在这里做你要做的事情,或者什么也不作
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
//回调函数
void CCmdShellDlg::OnRecvMsg(LPCTSTR szMsg)
{
m_EdtShell.AddText(szMsg);
}
void CCmdShellDlg::OnBtnRun()
{
// TODO: Add your control notification handler code here
UpdateData();
m_Cmd +=_T("\r\n");
m_hServer.SendCmd(m_Cmd);
}
void CCmdShellDlg::OnBtnClean()
{
// TODO: Add your control notification handler code here
m_EdtShell.ClearEdit();
}
2009-11-28
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人