www.pudn.com > IP_phone.rar > NC_ClientDlg.cpp
// NC_ClientDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NC_Client.h"
#include "NC_ClientDlg.h"
#include "SystemInfoDLG.h"
#include "NetSettingInfoDlg.h"
#include "IPAddressDlg.h"
//#include "winuser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CCompress g_comp;
CWaveOut *g_wave_out;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
////////////////////////////////////////////
static void DrawCreditsBackground(CDC *pDC, RECT rect, BOOL bAnimate, DWORD lParam);
////////////////////////////////////////////
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperLink m_Mail; //超链接形式显示EMAIL
CXPButton m_ok;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
////////////////////////////////
CCreditsCtrl m_wndCredits;//荣誉显示
///////////////////////////////
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}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)
DDX_Control(pDX, IDC_STATIC_MAIL, m_Mail);
DDX_Control(pDX, IDOK, m_ok);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
////////////////////////////////////////////////////
//显示效果框
srand((unsigned)time(NULL));
CString s;
s = "
";
s += "IP电话会议系统—Client
";
s += "
";
s += "飞翔工作室出品
";
//格式化并加入字符串
m_wndCredits.FormatDataString(s);
// 绘制闪电效果
//m_wndCredits.m_pBackgroundPaint = CAboutDlg::DrawCreditsBackground;
// m_wndCredits.m_dwBackgroundPaintLParam = TRUE;
// 默认背景置黑色
m_wndCredits.m_crInternalTransparentColor = RGB(255,255,255);
//滚动速度
m_wndCredits.m_nTimerSpeed = 40;
//用户拖拉滚动
m_wndCredits.m_bCanScroll = TRUE;
/////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CNC_ClientDlg dialog
//系统变量初始化
CNC_ClientDlg::CNC_ClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNC_ClientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNC_ClientDlg)
m_state = _T("");
bconnect=false;
bwait=false;
bstart=false;
btest=false;
send_socket=new CSendSocket();
rec_socket=new CRecSocket(this);
wave_in=new CWaveIn(send_socket,this);
g_wave_out=new CWaveOut();
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CNC_ClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNC_ClientDlg)
DDX_Control(pDX, IDC_SYS, m_menu_sys);
DDX_Control(pDX, IDC_INF, m_menu_inf);
DDX_Control(pDX, IDC_HLP, m_menu_hlp);
DDX_Control(pDX, IDC_ICON_STATE, m_icon_state);
DDX_Text(pDX, IDC_EDIT_STATE, m_state);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNC_ClientDlg, CDialog)
//{{AFX_MSG_MAP(CNC_ClientDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_APP_EXIT, OnAppExit)
ON_WM_CLOSE()
ON_COMMAND(ID_SHOW, OnTrayShow)
ON_COMMAND(ID_EXIT, OnTrayExit)
ON_COMMAND(ID_APP_HIDE, OnAppHide)
ON_COMMAND(ID_APP_INF_SYS, OnAppInfSys)
ON_COMMAND(ID_APP_INF_NETWORK, OnAppInfNetwork)
ON_WM_DESTROY()
ON_COMMAND(ID_APP_CONNECT, OnAppConnect)
ON_WM_TIMER()
ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
ON_COMMAND(ID_APP_TEST, OnAppTest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNC_ClientDlg message handlers
BOOL CNC_ClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
/////////////////////////////////////////////////////////
//加载菜单
//sys menu
// m_menu_sys.SetFlat(TRUE);
// m_menu_sys.OffsetColor(CButtonST::BTNST_COLOR_BK_IN,30);
#ifdef BTNST_USE_BCMENU
m_menu_sys.SetMenu(IDR_MENU_SYS, m_hWnd, TRUE, IDR_TOOLBAR);
#else
m_menu_sys.SetMenu(IDR_MENU_SYS, m_hWnd);
#endif
m_menu_sys.SetAlign(CButtonST::ST_ALIGN_VERT);
m_menu_sys.DrawFlatFocus(TRUE);
//info menu
m_menu_inf.SetFlat(TRUE);
m_menu_inf.OffsetColor(CButtonST::BTNST_COLOR_BK_IN,30);
#ifdef BTNST_USE_BCMENU
m_menu_inf.SetMenu(IDR_MENU_INFO, m_hWnd, TRUE, IDR_ICONBAR);
#else
m_menu_inf.SetMenu(IDR_MENU_INFO, m_hWnd);
#endif
m_menu_inf.SetAlign(CButtonST::ST_ALIGN_VERT);
m_menu_inf.DrawFlatFocus(TRUE);
//hlp menu
m_menu_hlp.SetFlat(TRUE);
m_menu_hlp.OffsetColor(CButtonST::BTNST_COLOR_BK_IN,30);
#ifdef BTNST_USE_BCMENU
m_menu_hlp.SetMenu(IDR_MENU_HLP, m_hWnd, TRUE, IDR_TOOLBAR);
#else
m_menu_hlp.SetMenu(IDR_MENU_HLP, m_hWnd);
#endif
m_menu_hlp.SetAlign(CButtonST::ST_ALIGN_VERT);
m_menu_hlp.DrawFlatFocus(TRUE);
//添加一个平面工具条
if (!m_wndtoolbar.CreateEx( this,TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS,
CRect(0,28,0,0)) || !m_wndtoolbar.LoadToolBar(IDR_TOOLBAR) )
{
TRACE0("failed to create toolbar\n");
return FALSE;
}
m_wndtoolbar.ShowWindow(SW_SHOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
//加载状态图标
LoadStateIcon(0);
//显示状态信息
m_state="本地消息:系统启动成功!!!";
UpdateData(FALSE);
//初始化音频输入/输出
if (!g_wave_out->Ini())
{
AfxMessageBox("音频输出初始化错误!");
return false;
}
else
{
AddSysMsg(0,"音频输出初始化成功!");
}
if (!wave_in->Ini())
{
g_wave_out->Release();
AfxMessageBox("音频输入初始化错误!");
return false;
}
else
{
AddSysMsg(0,"音频输入初始化成功!");
}
UpdateData(FALSE);
SetTimer(0,5,NULL);
/////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CNC_ClientDlg::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 CNC_ClientDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
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
{
/*//背景颜色
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect, RGB(0xff,0xff,0xff));
*/
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CNC_ClientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CNC_ClientDlg::OnOK()
{
}
void CNC_ClientDlg::OnCancel()
{
}
///////////////
void CNC_ClientDlg::LoadStateIcon(int state)
{
switch(state)
{
case 0:
m_icon_state.SetIcon(AfxGetApp()->LoadIcon(IDI_RED));
break;
case 1:
m_icon_state.SetIcon(AfxGetApp()->LoadIcon(IDI_YELLOW));
break;
case 2:
m_icon_state.SetIcon(AfxGetApp()->LoadIcon(IDI_GREEN));
break;
}
}
////////////////
void CNC_ClientDlg::AddSysMsg(int flag,CString msg)
{
switch(flag)
{
case 0:
m_state+="\r\n";
m_state+="本地:";
m_state+=msg;
break;
case 1:
m_state+="\r\n";
m_state+="服务器:";
m_state+=msg;
break;
}
}
///////////////
//工具栏提示
BOOL CNC_ClientDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
// UNICODE消息
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
//TCHAR szFullText[512];
CString strTipText;
UINT nID = pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
// idFrom为工具条的HWND
nID = ::GetDlgCtrlID((HWND)nID);
}
if (nID != 0) //不为分隔符
{
strTipText.LoadString(nID);
strTipText = strTipText.Mid(strTipText.Find('\n',0)+1);
#ifndef _UNICODE
if (pNMHDR->code == TTN_NEEDTEXTA)
{
lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
}
else
{
_mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
}
#else
if (pNMHDR->code == TTN_NEEDTEXTA)
{
_wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
}
else
{
lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
}
#endif
*pResult = 0;
// 使工具条提示窗口在最上面
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
return TRUE;
}
return TRUE;
}
void CNC_ClientDlg::OnAppAbout()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
////////////////////////////////////
void CNC_ClientDlg::Split()
{
CWindowAnima wa(this);
wa.Scatter6(90,10);
}
///////////////////////////////////
void CNC_ClientDlg::OnAppExit()
{
// Split();
CDialog::OnOK();
}
void CNC_ClientDlg::OnClose()
{
//Split();
CDialog::OnOK();
}
//系统托盘处理
////////////////////////////////////////////////////////
void CNC_ClientDlg::OnTrayShow()
{
ShowWindow(SW_SHOW);
m_TrayIcon.RemoveIcon();
}
void CNC_ClientDlg::OnTrayExit()
{
m_TrayIcon.RemoveIcon();
exit(1);
}
LRESULT CNC_ClientDlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
{
return m_TrayIcon.OnTrayNotification(wParam,lParam);
}
//隐藏窗口
void CNC_ClientDlg::OnAppHide()
{
m_TrayIcon.Create(this,WM_ICON_NOTIFY,"IP电话会议系统",m_hIcon,IDR_POPMENU);
ShowWindow(SW_HIDE);
}
////////////////////////////////////////////////////////////////////
void CNC_ClientDlg::OnAppInfSys()
{
CSystemInfoDLG dlg;
dlg.DoModal();
}
void CNC_ClientDlg::OnAppInfNetwork()
{
CNetSettingInfoDlg dlg;
dlg.DoModal();
}
//创建风格框架
/////////////////////////////////////////////////////////////////////////
BOOL CNC_ClientDlg::SetSkin(CString file)
{
// m_skinWin.LoadSkin( file );
// m_btnres.LoadSkin( file );
if ( m_bFirst )
{
m_skinWin.InstallSkin( this );
//EnumChildWindows( m_hWnd, EnumChildProc, (LPARAM)this );
m_bFirst = FALSE;
}
SetWindowPos( 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |SWP_FRAMECHANGED );
return TRUE;
}
/*
//用于设定skin里的button,未使用
#define GetWindowStyle(hwnd) ((DWORD)GetWindowLong(hwnd, GWL_STYLE))
BOOL CALLBACK EnumChildProc(HWND hwnd,// handle to child window
LPARAM lParam // application-defined value
)
{
char classname[200];
CNC_ClientDlg *dlg = (CNC_ClientDlg *)lParam;
DWORD style;
GetClassName( hwnd, classname, 200 );
style = GetWindowStyle( hwnd );
if ( strcmp( classname, "Button" ) == 0 )
{
style = (UINT)GetWindowLong(hwnd, GWL_STYLE) & 0xff;
if ( style == BS_PUSHBUTTON || style == BS_DEFPUSHBUTTON )
dlg->SubClassButton( hwnd );
}
return TRUE;
}
BOOL CNC_ClientDlg::SubClassButton( HWND hwnd )
{
CSkinButton * btn = new CSkinButton();
CWnd* pWnd = CWnd::FromHandlePermanent(hwnd);
if ( pWnd == NULL)
{
btn->SubclassWindow( hwnd );
btn->SetResource( &m_btnres );
return TRUE;
}
return FALSE;
}
*/
//////////////////////////////////////////////////////
void CNC_ClientDlg::OnDestroy()
{
CDialog::OnDestroy();
POSITION pos;
pos = m_wndList.GetHeadPosition();
while( pos )
{
CObject *ob = m_wndList.GetAt(pos);
if ( ob->GetRuntimeClass() == RUNTIME_CLASS(CSkinButton) )
{
delete (CSkinButton*)ob;
}
m_wndList.GetNext(pos);
}
}
//////////////////////////////////////////////////////
void CNC_ClientDlg::OnAppConnect()
{
if(bconnect)
AfxMessageBox("系统已经连接!");
else
{
CIPAddressDlg dlg;
if(dlg.DoModal()!=IDOK)
return;
else
con_socket=new CConnectionSocket(this);
if (!con_socket->Create())
return;
else
{
Sever_ip=dlg.ip;
con_socket->Connect(/*"127.0.0.1"*/Sever_ip,2001);
if(GetLastError()!= WSAEWOULDBLOCK)
{
AfxMessageBox("连接失败!");
delete con_socket;
}
}
bconnect=true;
}
}
//////////////////////////////////////////////////////
void CNC_ClientDlg::OnAppTest()
{
if(btest)
{
btest=false;
}
else
{
btest=true;
}
}
//////////////////////////////////////////////////////
void CNC_ClientDlg::OnTimer(UINT nIDEvent)
{
if(!bstart&&!btest)
return;
ShowWave();
CDialog::OnTimer(nIDEvent);
}
//////////////////////////////////////////////////////
void CNC_ClientDlg::ShowWave()
{
/* CRect rect;
GetClientRect(rect);
CDC* dc;
dc=GetDC();
CPen* pOldPen;
CPen pen(PS_SOLID,0,RGB(0,255,0));
pOldPen=dc->SelectObject(&pen);
dc->MoveTo(207,rect.bottom/2-20);
for(int x=207;x<(rect.right-10);x++)
{
//int y=rect.bottom/2-wavebuffer[(x-207)*5]/1500-25;//1024
int y=rect.bottom/2-wavebuffer[(x-207)%80]/1500-25;//60
dc->LineTo(x,y);
}
count++;
if(count%2!=0)
return;
CRect rectange;
rectange.SetRect(205,74,393,122);
CBrush Brush(RGB(66,65,66));
CBrush* pOldBrush=dc->SelectObject(&Brush);
dc->Rectangle(rectange);
dc->SelectObject(pOldPen);
dc->DeleteDC();
*/
}
//////////////////////////////////////////////////////
BOOL CNC_ClientDlg::Start()
{
if(bstart)
return false;
//初始化发送和接受socket
if (!rec_socket->Ini())
{
//m_sopListen->Close();
}
if (!send_socket->Ini ())
{
rec_socket->CloseSocket ();
}
//设定服务器地址,并释放临界区资源
send_socket->SetIp(Sever_ip);
send_socket->SetPort(send_port);
wave_in->EnableSend(true);
bstart=true;
return bstart;
}
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////