📄 serverdlg.cpp
字号:
/*=======================================================================
ServerDlg.cpp
Implementation of Server Dialog
========================================================================*/
#include "stdafx.h"
#include "Server.h"
#include "ServerDlg.h"
#include "CMediaSocketServer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CServerDlg dialog
CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CServerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pSender = NULL;
m_bConnected = FALSE;
m_strSourceFile = "";
sKeyName = "";
sKeyValue = "";
ret = 0;
}
void CServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CServerDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CServerDlg, CDialog)
//{{AFX_MSG_MAP(CServerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_NCPAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServerDlg message handlers
BOOL CServerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//关联.wma文件
sKeyName = "MyApp";
sKeyValue = "wmafile";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "", REG_SZ, sKeyValue, 0);
sKeyName = ".wma";
sKeyValue = "MyApp";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "", REG_SZ, sKeyValue, 0);
sKeyName = "MyApp";
sKeyValue = "Server.exe %1";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "shell\\open\\command", REG_SZ, sKeyValue, MAX_PATH);
//关联.rm文件
sKeyName = "MyApp";
sKeyValue = "rmflie";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "", REG_SZ, sKeyValue, 0);
sKeyName = ".rm";
sKeyValue = "MyApp";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "", REG_SZ, sKeyValue, 0);
sKeyName = "MyApp";
sKeyValue = "Server.exe %1";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "shell\\open\\command", REG_SZ, sKeyValue, MAX_PATH);
//关联.mp3文件
sKeyName = "MyApp";
sKeyValue = "mp3flie";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "", REG_SZ, sKeyValue, 0);
sKeyName = ".mp3";
sKeyValue = "MyApp";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "", REG_SZ, sKeyValue, 0);
sKeyName = "MyApp";
sKeyValue = "Server.exe %1";
ret = RegCreateKey(HKEY_CLASSES_ROOT, sKeyName, &lphKey);
ret = RegSetValue(lphKey, "shell\\open\\command", REG_SZ, sKeyValue, MAX_PATH);
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// COM initialize...
if (FAILED(CoInitialize(NULL)))
{
AfxMessageBox(" COM初始化失败!");
return FALSE;
}
//path of source file
m_strSourceFile = AfxGetApp()->m_lpCmdLine;
if(m_strSourceFile.Left(1)=="\"")//如果第一个字符是引号,那么去掉之
{
m_strSourceFile = m_strSourceFile.Mid(1,m_strSourceFile.GetLength()-2);
}
SendData();
return TRUE; // return TRUE unless you set the focus to a control
}
void CServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CServerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CServerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CServerDlg::OnNcPaint()
{
static int i = 2;
if(i > 0)
{
i --;
ShowWindow(SW_HIDE);
}
else
{
CDialog::OnNcPaint();
}
}
void CServerDlg::SendData()
{
delete m_pSender;
m_pSender = NULL;
m_pSender = new CMediaSocketServer();
// Connect to the client
char lpszServerAddr[20];
memcpy( lpszServerAddr, "192.168.2.219", 20 );
m_bConnected = m_pSender->Connect( lpszServerAddr, BASE_SOCKET_PORT );
if ( m_bConnected )
{
// AfxMessageBox(m_strSourceFile);
//设置源文件
m_pSender->SetSourceFile( m_strSourceFile );
//启动接收线程,监听来自客户端的控制命令
m_pSender->StartReceiving();
}
else
{
AfxMessageBox("远程连接失败!");
}
}
/*
void CServerDlg::OnButtonSelect()
{
// TODO: Add your control notification handler code here
CString strFilter = "mp3 rm wma File (*.mp3;*.rm;*.wma)|*.mp3;*.rm;*.wma|"
"All Files (*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
strFilter,NULL);
if (dlg.DoModal() == IDOK)
{
m_strSourceFile = dlg.GetPathName();
SendData();
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -