📄 screenppc.cpp
字号:
// ScreenPPC.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#define PACKETSIZE 100000
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScreenPPCApp
BEGIN_MESSAGE_MAP(CScreenPPCApp, CWinApp)
//{{AFX_MSG_MAP(CScreenPPCApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScreenPPCApp construction
CScreenPPCApp::CScreenPPCApp()
: CWinApp()
{
// TODO: add construction co`de here,
// Place all significant initialization in InitInstance
m_bClientConnected=false;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CScreenPPCApp object
CScreenPPCApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CScreenPPCApp initialization
BOOL CScreenPPCApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CScreenPPCDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CScreenPPCView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BOOL CScreenPPCApp::ConnectSocket(LPCTSTR lpszHandle, LPCTSTR lpszAddress, UINT nPort)
{
m_pSocket = new CChatSocket(CCeSocket::FOR_DATA);
if (!m_pSocket->Create())
{
delete m_pSocket;
m_pSocket = NULL;
AfxMessageBox(CString("Socket Creation Failed"));
return FALSE;
}
if(!m_pSocket->Connect(lpszAddress, nPort + 700))
{
AfxMessageBox(CString("Socket failed to Connect to the remote host"));
delete m_pSocket;
m_pSocket = NULL;
return FALSE;
}
return TRUE;
}
void CScreenPPCApp::SendMsg(char csMsg)
{
m_pSocket->Send (&csMsg,1,0);
}
BOOL CScreenPPCApp::StartApplication()
{
m_strHandle="7";
m_strServer=m_pActiveView->m_csHostName;
m_nChannel=7;
if (ConnectSocket(m_strHandle, m_strServer, m_nChannel))
return TRUE;
else
{
AfxMessageBox(CString("Connection to the Socket Failed"));
return FALSE;
}
}
void CScreenPPCApp::ProcessPendingRead()
{
char szMessage[255];
m_pSocket->Receive (&szMessage,255,0);
if(strcmp(szMessage,"SUCCESS")==0)
{
AfxMessageBox(CString("Successful login..."));
}
else
{
AfxMessageBox(CString("Unsuccessful login..."));
}
AfxGetMainWnd()->SendMessage (WM_CLOSE,0,0);
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog(); // Added for WCE apps
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CScreenPPCApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CScreenPPCApp commands
// Added for WCE apps
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
bool CScreenPPCApp::CheckForAuthentication()
{
if(!StartApplication())
{
AfxMessageBox(CString("Application failed to initialize.Now exiting.."));
return FALSE;
}
m_bClientConnected=true;
char szHostName[25];
gethostname(szHostName,25);
m_pSocket->Send (szHostName,25,0);
char szUsername[255];
char szPassword[255];
strcopy(szUsername,m_pActiveView->m_csUsername);
strcopy(szPassword,m_pActiveView->m_csPassword);
//send the user name and the password
m_pSocket->Send (szUsername,255,0);
m_pSocket->Send (szPassword,255,0);
return TRUE;
}
void CScreenPPCApp::strcopy(char *szDest,CString csStr)
{
for(int ni=0;ni<csStr.GetLength ();ni++)
{
szDest[ni]=(char)csStr.GetAt(ni);
}
szDest[csStr.GetLength ()]='\0';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -