Main.cpp
上传用户:oldpeter23
上传日期:2013-01-09
资源大小:1111k
文件大小:49k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: Main.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. #include "wndx.h"
  13. #include <Windowsx.h>
  14. #include <VFW.h>
  15. #include <stdio.h>
  16. #include "waveshow.h"
  17. #include "resource.h"
  18. #include "Splash.h"
  19. #include "AVIOMgr.h"
  20. #include "VolumeOutWave.h"
  21. #include "VolumeInXXX.h"
  22. #include "VideoWnd.h"
  23. #include "TrayNotify.h"
  24. #include "SlideBar.h"
  25. #include "AddrBook.h"
  26. #include "GraphDlg.h"
  27. #include "RippleWnd.h"
  28. #include "NewMsgBox.h"
  29. #include "MsgTalk.h"
  30. #include "Main.h"
  31. /*------------------------------------------------------------------------------*/
  32. #define PORT 1159//the default port is 1159
  33. CMainWnd MainWnd;
  34. CAVIOMgr  AVIO;
  35. SETUP CSetupDlg::Setup;
  36. /*------------------------------------------------------------------------------*/
  37. //
  38. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  39. {
  40. //初始化WndX系统
  41. InitXSystem(hInstance);
  42. /* INITIALIZE COMMON CONTROLS */
  43. INITCOMMONCONTROLSEX iccex;     
  44.     iccex.dwICC = ICC_WIN95_CLASSES;
  45.     iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  46.     InitCommonControlsEx(&iccex);
  47. //确保只有一个实例
  48. HANDLE hMutex=CreateMutex(0,FALSE,"NETTALK_MUTEX_ONCE");
  49. if(hMutex)
  50. {
  51. if(GetLastError()==ERROR_ALREADY_EXISTS)
  52. return 0;
  53. }
  54. //显示软件封面
  55. CSplash* Splash=new CSplash(3000);
  56. Splash->CreateSplash(IDD_SPLASH);
  57. //初始化Socket
  58. InitializeSocket();
  59. //初始化AVIO(将Socket绑定到某个Port)
  60. if(!AVIO.Init(PORT))
  61. {
  62. //如果失败,退出
  63. CMsgBox::MessageBox(0,IDS_ERR_INIT,IDS_ERR,0,IDI_ERR);
  64. return 0;
  65. }
  66. //创建主窗口
  67. MainWnd.Create(LPCTSTR(IDD_MAIN_DLG),0);
  68. //
  69. AVIO.SetMainWnd(MainWnd);
  70. MSG msg;
  71. while(GetMessage(&msg,0,0,0))
  72. {
  73. PreTranslateMessageX(&msg);
  74. TranslateMessage(&msg);
  75. DispatchMessage(&msg);
  76. }
  77. AVIO.Destroy();
  78. CleanUpSocket();
  79. return msg.wParam;
  80. }
  81. /*------------------------------------------------------------------------------*/
  82. CMainWnd::CMainWnd()
  83. {
  84. m_bHilightTitleBar=0;
  85. SetRect(&m_rcDataRate,20,218,140,231);
  86. SetRect(&m_rcFps,10,175,45,189);
  87. SetRect(&m_rcVideo,6,28,182,172);
  88. m_bmpVideo=0;
  89. m_bSendVideo=TRUE;
  90. }
  91. /*------------------------------------------------------------------------------*/
  92. CMainWnd::~CMainWnd()
  93. {
  94. }
  95. /*------------------------------------------------------------------------------*/
  96. //主窗口消息
  97. LRESULT CMainWnd::WndProc(UINT uMsg,WPARAM wParam,LPARAM lParam)
  98. {
  99. switch(uMsg)
  100. {
  101. case WM_HOTKEY://热键弹出
  102. if(wParam==1)
  103. {
  104. ShowWindow(m_hWnd,SW_SHOWNORMAL);
  105. SetForegroundWindow(m_hWnd);
  106. SetActiveWindow(m_hWnd);
  107. }
  108. break;
  109. case WM_USER_SETUP:
  110. OnSetup((SETUP*)lParam);
  111. break;
  112. case WM_TRAYNOTIFY:
  113. OnTrayNotify(wParam,lParam);
  114. break;
  115. case IOM_AUDIO:
  116. OnAudioData((BOOL)wParam,(CAVIOMgr*)lParam);
  117. break;
  118. case WM_INITDIALOG:
  119. return OnInitDialog();
  120. case WM_DESTROY:
  121. OnDestroy();
  122. break;
  123. case WM_CLOSE:
  124. OnClose();
  125. break;
  126. case WM_LBUTTONDOWN:
  127. {
  128. POINT point;
  129. point.x=GET_X_LPARAM(lParam); 
  130. point.y=GET_Y_LPARAM(lParam); 
  131. OnLButtonDown(wParam,point);
  132. }break;
  133. case WM_LBUTTONUP:
  134. {
  135. POINT point;
  136. point.x=GET_X_LPARAM(lParam); 
  137. point.y=GET_Y_LPARAM(lParam); 
  138. OnLButtonUp(wParam,point);
  139. }break;
  140. case WM_MOUSEMOVE:
  141. {
  142. POINT point;
  143. point.x=GET_X_LPARAM(lParam); 
  144. point.y=GET_Y_LPARAM(lParam); 
  145. OnMouseMove(wParam,point);
  146. }break;
  147. case WM_COMMAND:
  148. return OnCommand(wParam,lParam);
  149. break;
  150. case WM_ERASEBKGND:
  151. OnEraseBkgnd((HDC)wParam);
  152. return TRUE;
  153. case WM_TIMER:
  154. OnTimer(wParam);
  155. break;
  156. case WM_SETCURSOR:
  157. return OnSetCursor((HWND)wParam,LOWORD(lParam),HIWORD(lParam));
  158. break;
  159. case WM_CTLCOLOREDIT:
  160. return (LRESULT)OnCtrlColorEdit((HDC)wParam,(HWND)lParam);
  161. break;
  162. case WM_CTLCOLORSTATIC:
  163. return (LRESULT)OnCtrlColorStatic((HDC)wParam,(HWND)lParam);
  164. break;
  165. case IOM_NOTIFY:
  166. OnIOMNotify(wParam,lParam);
  167. break;
  168. case WM_SLD:
  169. {
  170. if(((HWND)lParam)==((HWND)m_sldAudioOut))
  171. {
  172. //设置输出音量
  173. m_VoOutCtrl.SetCurrentVolume((m_VoOutCtrl.GetMaximalVolume()-m_VoOutCtrl.GetMinimalVolume())*m_sldAudioOut.GetPos()/100);
  174. }
  175. else
  176. if(((HWND)lParam)==((HWND)m_sldAudioIn))
  177. {
  178. //设置输入音量
  179. m_VoInCtrl.SetCurrentVolume((m_VoInCtrl.GetMaximalVolume()-m_VoInCtrl.GetMinimalVolume())*m_sldAudioIn.GetPos()/100);
  180. }
  181. else
  182. if(((HWND)lParam)==((HWND)m_sldVideoQ))
  183. {
  184. //设置视频质量
  185. m_VQ=m_sldVideoQ.GetPos();
  186. AVIO.SetVideoQuality(m_VQ);
  187. }
  188. }
  189. break;
  190. default:
  191. return CDialogX::WndProc(uMsg,wParam,lParam);
  192. }
  193. return TRUE;
  194. }
  195. /*------------------------------------------------------------------------------*/
  196. BOOL CMainWnd::OnInitDialog()
  197. {
  198. HDC hdc=GetDC(m_hWnd);
  199. m_bmpVideo=CreateCompatibleBitmap(hdc,176,144);
  200. ReleaseDC(m_hWnd,hdc);
  201. //set window region
  202. POINT pt[13]={{0,10},{10,0},{262,0},{262,32},{269,39},{269,160},
  203. {265,164},{265,228},{256,237},{20,237},{11,228},{11,221},{0,210}};
  204. HRGN hRgn=CreatePolygonRgn(pt,13,ALTERNATE);
  205. SetWindowRgn(m_hWnd,hRgn,FALSE);
  206. //set window style
  207. DWORD dwStyle=GetWindowLong(m_hWnd,GWL_STYLE);
  208. SetWindowLong(m_hWnd,GWL_STYLE,dwStyle|WS_SYSMENU|WS_MINIMIZEBOX);
  209. //set window caption and icon
  210. SetWindowText(m_hWnd,"NetTalk");
  211. SendMessage(m_hWnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(hInstX,LPCTSTR(IDI_MAIN)));
  212. //title bar region
  213. POINT pt2[5]={{11,4},{170,4},{151,23},{4,23},{4,11}};
  214. m_hrgnTitle=CreatePolygonRgn(pt2,5,ALTERNATE);
  215. m_TrayNotify.SetHwnd(m_hWnd);
  216. m_TrayNotify.SetIcon(LoadIcon(hInstX,LPCTSTR(IDI_MAIN)));
  217. m_TrayNotify.SetTip("NetTalk-115软件工厂");
  218. m_TrayNotify.SetMsg(WM_TRAYNOTIFY);
  219. m_TrayNotify.SetID(1);
  220. m_TrayNotify.ShowIcon(TRUE);
  221. //
  222. m_hbCtrlBg=CreateSolidBrush(0);
  223. m_hbFpsBg=CreateSolidBrush(0x00b9b4b3);
  224. //initialize buttons(load the bitmaps,set the position)
  225. m_btnCall.LoadBitmaps(IDB_CALL1,IDB_CALL2,IDB_CALL3);
  226. m_btnCall.Associate(m_hWnd,IDC_CALL);
  227. SetWindowPos(m_btnCall,0,0,0,64,24,SWP_NOMOVE);
  228. m_btnHang.LoadBitmaps(IDB_HANG1,IDB_HANG2,IDB_HANG3);
  229. m_btnHang.Associate(m_hWnd,IDC_HANG);
  230. SetWindowPos(m_btnHang,0,0,0,64,24,SWP_NOMOVE);
  231. m_btnAddr.LoadBitmaps(IDB_ADDR1,IDB_ADDR2,IDB_ADDR3);
  232. m_btnAddr.Associate(m_hWnd,IDC_ADDR);
  233. SetWindowPos(m_btnAddr,0,0,0,64,24,SWP_NOMOVE);
  234. m_btnSetup.LoadBitmaps(IDB_SETUP1,IDB_SETUP2,IDB_SETUP3);
  235. m_btnSetup.Associate(m_hWnd,IDC_SETUP);
  236. SetWindowPos(m_btnSetup,0,0,0,64,24,SWP_NOMOVE);
  237. m_btnClose.LoadBitmaps(IDB_CLOSE1,IDB_CLOSE2,IDB_CLOSE3);
  238. m_btnClose.Associate(m_hWnd,IDC_CLOSE);
  239. SetWindowPos(m_btnClose,0,0,0,11,11,SWP_NOMOVE);
  240. m_btnMin.LoadBitmaps(IDB_MIN1,IDB_MIN2,IDB_MIN3);
  241. m_btnMin.Associate(m_hWnd,IDC_MIN);
  242. SetWindowPos(m_btnMin,0,0,0,11,11,SWP_NOMOVE);
  243. m_btnHelp.LoadBitmaps(IDB_HELP1,IDB_HELP2,IDB_HELP3);
  244. m_btnHelp.Associate(m_hWnd,IDC_HP);
  245. SetWindowPos(m_btnHelp,0,0,0,11,11,SWP_NOMOVE);
  246. m_btnAbout.LoadBitmaps(IDB_ABOUT1,IDB_ABOUT2,IDB_ABOUT3);
  247. m_btnAbout.Associate(m_hWnd,IDC_ABOUT);
  248. SetWindowPos(m_btnAbout,0,0,0,11,11,SWP_NOMOVE);
  249. m_btnLocal.LoadBitmaps(IDB_VIDEO_LOCAL1,IDB_VIDEO_LOCAL2,IDB_VIDEO_LOCAL3);
  250. m_btnLocal.Associate(m_hWnd,IDC_VIDEO_LOCAL);
  251. SetWindowPos(m_btnLocal,0,0,0,15,15,SWP_NOMOVE);
  252. m_btnOnoff.LoadBitmaps(IDB_VIDEO_ONOFF4,IDB_VIDEO_ONOFF5,IDB_VIDEO_ONOFF6);
  253. m_btnOnoff.Associate(m_hWnd,IDC_VIDEO_ONOFF);
  254. SetWindowPos(m_btnOnoff,0,0,0,15,15,SWP_NOMOVE);
  255. m_btnOutview.LoadBitmaps(IDB_VIDEO_OUTVIEW1,IDB_VIDEO_OUTVIEW2,IDB_VIDEO_OUTVIEW3);
  256. m_btnOutview.Associate(m_hWnd,IDC_VIDEO_OUTVIEW);
  257. SetWindowPos(m_btnOutview,0,0,0,15,15,SWP_NOMOVE);
  258. m_btnMsg.LoadBitmaps(IDB_MSG1,IDB_MSG2,IDB_MSG3);
  259. m_btnMsg.Associate(m_hWnd,IDC_MSG);
  260. SetWindowPos(m_btnMsg,0,0,0,15,15,SWP_NOMOVE);
  261. //initialize the slide bar
  262. RECT rc;
  263. SetRect(&rc,174,180,250,188);
  264. m_sldAudioOut.Create(rc,m_hWnd,0);
  265. SetRect(&rc,174,195,250,203);
  266. m_sldAudioIn.Create(rc,m_hWnd,0);
  267. SetRect(&rc,51,194,141,203);
  268. m_sldVideoQ.Create(rc,m_hWnd,0);
  269. //initialize the wave show
  270. SetRect(&rc,164,211,202,229);
  271. m_WaveShowOut.Create(rc,m_hWnd);
  272. SetRect(&rc,218,211,256,229);
  273. m_WaveShowIn.Create(rc,m_hWnd);
  274. //Create the video wnd
  275. m_LocalVideoWnd.Create(IDD_VIDEO,m_hWnd,TRUE);
  276. m_RemoteVideoWnd.Create(IDD_VIDEO,m_hWnd,FALSE);
  277. GetWindowRect(m_hWnd,&rc);
  278. SetWindowPos(m_LocalVideoWnd,0,rc.right+20,rc.top-100,0,0,SWP_NOSIZE);
  279. SetWindowPos(m_RemoteVideoWnd,0,rc.left-200,rc.top,0,0,SWP_NOSIZE);
  280. //Create the txt chat wnd
  281. m_MsgTalk.Create(m_hWnd);
  282. SetWindowPos(m_MsgTalk,0,rc.right+20,rc.top+100,0,0,SWP_NOSIZE);
  283. //add the tooltips for ctrls
  284. char szTip[30];
  285. TOOLINFO ti;
  286.     /* CREATE A TOOLTIP WINDOW */
  287.     m_hwndTT = CreateWindowEx(WS_EX_TOPMOST,
  288.         TOOLTIPS_CLASS,
  289.         NULL,
  290.         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
  291.         CW_USEDEFAULT,
  292.         CW_USEDEFAULT,
  293.         CW_USEDEFAULT,
  294.         CW_USEDEFAULT,
  295.         m_hWnd,
  296.         NULL,
  297.         hInstX,
  298.         NULL
  299.         );
  300.     SetWindowPos(m_hwndTT,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  301.   
  302.     /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
  303.     ti.cbSize = sizeof(TOOLINFO);
  304.     ti.uFlags = TTF_SUBCLASS;
  305.     
  306.     ti.hinst = hInstX;
  307.     ti.uId = 0;
  308. ti.lpszText = szTip;
  309.       //
  310.     ti.hwnd = m_btnClose;
  311. GetClientRect(m_btnClose,&ti.rect);
  312. strcpy(szTip,"关闭NetTalk");
  313.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  314. ti.hwnd = m_btnMin;
  315. GetClientRect(m_btnMin,&ti.rect);
  316. strcpy(szTip,"最小化");
  317.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  318. ti.hwnd = m_btnHelp;
  319. GetClientRect(m_btnHelp,&ti.rect);
  320. strcpy(szTip,"帮助");
  321.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  322. ti.hwnd = m_btnAbout;
  323. GetClientRect(m_btnAbout,&ti.rect);
  324. strcpy(szTip,"关于...");
  325.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  326. ti.hwnd = m_btnLocal;
  327. GetClientRect(m_btnLocal,&ti.rect);
  328. strcpy(szTip,"本地视频");
  329.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  330. ti.hwnd = m_btnOutview;
  331. GetClientRect(m_btnOutview,&ti.rect);
  332. strcpy(szTip,"对方视频");
  333.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  334. ti.hwnd = m_btnOnoff;
  335. GetClientRect(m_btnOnoff,&ti.rect);
  336. strcpy(szTip,"传送/不传送本地视频");
  337.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  338. ti.hwnd = m_btnMsg;
  339. GetClientRect(m_btnMsg,&ti.rect);
  340. strcpy(szTip,"文本对话");
  341.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  342. ti.hwnd = m_sldAudioIn;
  343. GetClientRect(m_sldAudioIn,&ti.rect);
  344. strcpy(szTip,"调节麦克风音量");
  345.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  346. ti.hwnd = m_sldAudioOut;
  347. GetClientRect(m_sldAudioOut,&ti.rect);
  348. strcpy(szTip,"调节输出音量");
  349.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  350. ti.hwnd = m_sldVideoQ;
  351. GetClientRect(m_sldVideoQ,&ti.rect);
  352. strcpy(szTip,"调节视频质量");
  353.     SendMessage(m_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  354. //volume control,
  355. m_VoOutCtrl.RegisterNotificationSink(OutVolumeChanged,(DWORD)this);
  356. m_VoInCtrl.RegisterNotificationSink(InVolumeChanged,(DWORD)this);
  357. if(m_VoOutCtrl.GetMaximalVolume()-m_VoOutCtrl.GetMinimalVolume())
  358. m_sldAudioOut.SetPos(100*m_VoOutCtrl.GetCurrentVolume()/
  359. (m_VoOutCtrl.GetMaximalVolume()-m_VoOutCtrl.GetMinimalVolume()));
  360. if(m_VoInCtrl.GetMaximalVolume()-m_VoInCtrl.GetMinimalVolume())
  361. m_sldAudioIn.SetPos(100*m_VoInCtrl.GetCurrentVolume()/
  362. (m_VoInCtrl.GetMaximalVolume()-m_VoInCtrl.GetMinimalVolume()));
  363. //get the video quality from the ini file
  364. m_VQ=GetPrivateProfileInt("Video","Q",50,"NetTalk.ini");
  365. if(m_VQ>100||m_VQ<0)
  366. m_VQ=100;
  367. AVIO.SetVideoQuality(m_VQ);
  368. m_sldVideoQ.SetPos(m_VQ);
  369. //create the video display wnd
  370. m_vs.Create(m_rcVideo,m_hWnd);
  371. //to get the data from AVIO,set some wnds related to AVIO
  372. AVIO.SetRemoteVideoRcvWnd(m_vs);
  373. AVIO.SetLocalVideoRcvWnd(m_LocalVideoWnd.m_vs);
  374. AVIO.SetLocalAudioRcvWnd(m_hWnd);
  375. AVIO.SetRemoteAudioRcvWnd(m_hWnd);
  376. MoveWindow(GetDlgItem(m_hWnd,IDC_DATARATE),m_rcDataRate.left,m_rcDataRate.top,m_rcDataRate.Width(),m_rcDataRate.Height(),false);
  377. MoveWindow(GetDlgItem(m_hWnd,IDC_FPS),m_rcFps.left,m_rcFps.top,m_rcFps.Width(),m_rcFps.Height(),false);
  378. //load the setup
  379. CSetupDlg::LoadSetup();
  380. OnSetup(&CSetupDlg::Setup);
  381. if(CSetupDlg::Setup.bInitShow)
  382. ShowWindow(m_hWnd,SW_SHOW);
  383. return FALSE ;
  384. }
  385. /*------------------------------------------------------------------------------*/
  386. //
  387. void CMainWnd::OnDestroy()
  388. {
  389. if(m_hbCtrlBg)
  390. DeleteObject(m_hbCtrlBg);
  391. if(m_hbFpsBg)
  392. DeleteObject(m_hbFpsBg);
  393. if(m_bmpVideo)
  394. DeleteObject(m_bmpVideo);
  395. char s[5];
  396. sprintf(s,"%d",m_VQ);
  397. WritePrivateProfileString("Video","Q",s,"NetTalk.ini");
  398. }
  399. /*------------------------------------------------------------------------------*/
  400. //when close ,warning
  401. void CMainWnd::OnClose()
  402. {
  403. if(AVIO.GetStatus()==STA_BUSY)
  404. {
  405. if(CMsgBox::MessageBox(m_hWnd,IDS_MSG_CLOSE_BUSY,IDS_WAR,MB_YESNO,IDI_INFO)==IDYES)
  406. {
  407. DestroyWindow(m_hWnd);
  408. PostQuitMessage(0);
  409. }
  410. }
  411. else
  412. if(CMsgBox::MessageBox(m_hWnd,IDS_MSG_CLOSE_FREE,IDS_WAR,MB_YESNO,IDI_INFO)==IDYES)
  413. {
  414. DestroyWindow(m_hWnd);
  415. PostQuitMessage(0);
  416. }
  417. }
  418. /*------------------------------------------------------------------------------*/
  419. void CMainWnd::OnLButtonDown(UINT nFlags, POINT &point)
  420. {
  421. if(PtInRegion(m_hrgnTitle,point.x,point.y))
  422. {
  423. SetCapture(m_hWnd);
  424. RECT rc;
  425. GetWindowRect(m_hWnd,&rc);
  426. MSG msg;
  427. while(GetMessage(&msg, NULL, 0, 0))
  428. {
  429. if (GetCapture()!=m_hWnd)
  430. {
  431. DispatchMessage(&msg);
  432. break;
  433. }
  434. switch(msg.message)
  435. {
  436. case WM_MOUSEMOVE:
  437. {
  438. POINT pt;
  439. pt.x=GET_X_LPARAM(msg.lParam);
  440. pt.y=GET_Y_LPARAM(msg.lParam);
  441. rc.left+=pt.x-point.x;
  442. rc.top+=pt.y-point.y;
  443. SetWindowPos(m_hWnd,0,rc.left,
  444. rc.top,0,0,SWP_NOSIZE);
  445. }
  446. break;
  447. case WM_LBUTTONUP:
  448. goto EXITLOOP;
  449. default:
  450. DispatchMessage(&msg);
  451. break;
  452. }
  453. }
  454. EXITLOOP:
  455. ReleaseCapture();
  456. }
  457. }
  458. /*------------------------------------------------------------------------------*/
  459. void CMainWnd::OnLButtonUp(UINT nFlags, POINT &point)
  460. {
  461. }
  462. /*------------------------------------------------------------------------------*/
  463. //hilight the title bar
  464. void CMainWnd::OnMouseMove(UINT nFlags, POINT point)
  465. {
  466. if(PtInRegion(m_hrgnTitle,point.x,point.y)&&!m_bHilightTitleBar)
  467. {
  468. RECT rc;
  469. SetRect(&rc,5,5,168,22);
  470. m_bHilightTitleBar=TRUE;
  471. HDC hdc=GetDC(m_hWnd);
  472. HBITMAP hb=LoadBitmap(hInstX,LPCTSTR(IDB_TITLE2));
  473. DrawTransBmpX(hdc,rc,hb,0,0,0);
  474. DeleteObject(hb);
  475. ReleaseDC(m_hWnd,hdc);
  476. SetTimer(m_hWnd,1,50,0);
  477. }
  478. }
  479. /*------------------------------------------------------------------------------*/
  480. BOOL CMainWnd::OnCommand(WPARAM wParam, LPARAM lParam)
  481. {
  482. switch(LOWORD(wParam))
  483. {
  484. case IDC_CLOSE:
  485. OnClose();
  486. break;
  487. case IDC_MIN:
  488. ShowWindow(m_hWnd,SW_MINIMIZE);
  489. if(CSetupDlg::Setup.bMiniHide)
  490. ShowWindow(m_hWnd,SW_HIDE);
  491. break;
  492. case IDC_HP:
  493. {
  494. //打开帮助文件
  495. char szPath[256];
  496. GetModuleFileName(0,szPath,255);
  497. int i;
  498. for(i=strlen(szPath);i>0;i--)
  499. {
  500. if(szPath[i]=='\')
  501. {
  502. szPath[i+1]=0;
  503. break;
  504. }
  505. }
  506. strcpy(szPath+strlen(szPath),"help\help.htm");
  507. ShellExecute(0,"open",szPath,0,0,SW_SHOWNORMAL);
  508. }
  509. break;
  510. case IDC_ABOUT:
  511. {
  512. CAboutDlg abt;
  513. abt.DoModal(LPCTSTR(IDD_ABOUT_DLG),m_hWnd);
  514. }
  515. break;
  516. case IDC_ADDR:
  517. {
  518. CAddrBook ab;
  519. ab.DoModal(LPCTSTR(IDD_ADDR),m_hWnd);
  520. }
  521. break;
  522. case 0:
  523. {
  524. //呼叫
  525. if(!AVIO.Call((char*)lParam,PORT))
  526. CMsgBox::MessageBox(m_hWnd,IDS_MSG_CALL_BUSY,IDS_ERR,MB_OK,IDI_INFO);
  527. else
  528. {
  529. if(!m_CallDlg.DoModal(m_hWnd,(char*)lParam))
  530. {
  531. if(AVIO.GetStatus()==STA_BUSY)
  532. {
  533. ShowWindow(m_vs,SW_HIDE);
  534. ShowWindow(m_LocalVideoWnd.m_vs,SW_HIDE);
  535. ShowWindow(m_RemoteVideoWnd.m_vs,SW_HIDE);
  536. KillTimer(m_hWnd,2);
  537. DrawFps("");
  538. DrawDataRate("");
  539. }
  540. AVIO.EndTalk();
  541. }
  542. }
  543. }
  544. break;
  545. case IDC_CALL:
  546. {
  547. CIPInput ip;
  548. if(ip.DoModal(LPCTSTR(IDD_IPINPUT),m_hWnd))
  549. {
  550. SendMessage(m_hWnd,WM_COMMAND,0,(LPARAM)ip.m_szIP);
  551. }
  552. }
  553. break;
  554. case IDC_HANG:
  555. {
  556. //挂断
  557. if(AVIO.GetStatus()==STA_BUSY)
  558. {
  559. if(CMsgBox::MessageBox(m_hWnd,IDS_MSG_IFENDTALK,IDS_WAR,MB_YESNO,IDI_INFO)==IDYES)
  560. {
  561. AVIO.EndTalk();
  562. KillTimer(m_hWnd,2);
  563. DrawFps("");
  564. DrawDataRate("");
  565. ShowWindow(m_vs,SW_HIDE);
  566. ShowWindow(m_LocalVideoWnd.m_vs,SW_HIDE);
  567. ShowWindow(m_RemoteVideoWnd.m_vs,SW_HIDE);
  568. }
  569. }
  570. else
  571. AVIO.EndTalk();
  572. }
  573. break;
  574. case IDC_SETUP:
  575. {
  576. CSetupDlg sd;
  577. sd.DoModal(LPCTSTR(IDD_SETUP),m_hWnd);
  578. }
  579. break;
  580. case IDC_VIDEO_LOCAL:
  581. {
  582. if(IsWindowVisible(m_LocalVideoWnd))
  583. {
  584. AVIO.EnablePreview(FALSE);
  585. ShowWindow(m_LocalVideoWnd,SW_HIDE);
  586. }
  587. else
  588. {
  589. ShowWindow(m_LocalVideoWnd,SW_SHOW);
  590. AVIO.EnablePreview(TRUE);
  591. }
  592. }
  593. break;
  594. case IDC_VIDEO_OUTVIEW:
  595. {
  596. if(IsWindowVisible(m_RemoteVideoWnd))
  597. {
  598. ShowWindow(m_RemoteVideoWnd,SW_HIDE);
  599. AVIO.SetRemoteVideoRcvWnd(m_vs);
  600. ShowWindow(m_RemoteVideoWnd.m_vs,SW_HIDE);
  601. m_btnOutview.LoadBitmaps(IDB_VIDEO_OUTVIEW1,IDB_VIDEO_OUTVIEW2,IDB_VIDEO_OUTVIEW3);
  602. }
  603. else
  604. {
  605. ShowWindow(m_RemoteVideoWnd,SW_SHOW);
  606. AVIO.SetRemoteVideoRcvWnd(m_RemoteVideoWnd.m_vs);
  607. ShowWindow(m_vs,SW_HIDE);
  608. m_btnOutview.LoadBitmaps(IDB_VIDEO_OUTVIEW4,IDB_VIDEO_OUTVIEW5,IDB_VIDEO_OUTVIEW6);
  609. }
  610. InvalidateRect(m_btnOutview,0,FALSE);
  611. }
  612. break;
  613. case IDC_VIDEO_ONOFF:
  614. {//是否发送视频
  615. if(m_bSendVideo)
  616. {
  617. m_bSendVideo=FALSE;
  618. AVIO.VideoSend(FALSE);
  619. m_btnOnoff.LoadBitmaps(IDB_VIDEO_ONOFF1,IDB_VIDEO_ONOFF2,IDB_VIDEO_ONOFF3);
  620. }
  621. else
  622. {
  623. m_bSendVideo=TRUE;
  624. AVIO.VideoSend(TRUE);
  625. m_btnOnoff.LoadBitmaps(IDB_VIDEO_ONOFF4,IDB_VIDEO_ONOFF5,IDB_VIDEO_ONOFF6);
  626. }
  627. }break;
  628. case IDC_SEND:
  629. {
  630. //发送文字信息
  631. char ip[50];
  632. GetDlgItemText(m_MsgTalk,IDC_OBJ,ip,50);
  633. AVIO.SendTxt(ip,PORT,(char*)lParam);
  634. }break;
  635. case IDC_MSG:
  636. {
  637. if(IsWindowVisible(m_MsgTalk))
  638. ShowWindow(m_MsgTalk,SW_HIDE);
  639. else
  640. ShowWindow(m_MsgTalk,SW_SHOW);
  641. }break;
  642. }
  643. return TRUE;
  644. }
  645. /*------------------------------------------------------------------------------*/
  646. //画主窗口界面
  647. void CMainWnd::OnEraseBkgnd(HDC hdc)
  648. {
  649. RECT rc;
  650. GetClientRect(m_hWnd,&rc);
  651. HDC hMemDC=CreateCompatibleDC(hdc);
  652. HBITMAP hFace=LoadBitmap(hInstX,LPCTSTR(IDB_FACE));
  653. HBITMAP hob=(HBITMAP)SelectObject(hMemDC,hFace);
  654. //画标题条(如果被Hilight的话)
  655. if(m_bHilightTitleBar)
  656. {
  657. RECT rc;
  658. SetRect(&rc,5,5,168,22);
  659. m_bHilightTitleBar=TRUE;
  660. HBITMAP hb=LoadBitmap(hInstX,LPCTSTR(IDB_TITLE2));
  661. DrawTransBmpX(hMemDC,rc,hb,0,0,0);
  662. DeleteObject(hb);
  663. }
  664. BitBlt(hdc,0,0,rc.right-rc.left,
  665. rc.bottom-rc.top,hMemDC,0,0,SRCCOPY);
  666. SelectObject(hMemDC,hob);
  667. DeleteObject(hFace);
  668. DeleteDC(hMemDC);
  669. }
  670. /*------------------------------------------------------------------------------*/
  671. void CMainWnd::OnTimer(UINT nIDEvent)
  672. {
  673. switch(nIDEvent)
  674. {
  675. case 1:
  676. POINT pt;
  677. GetCursorPos(&pt);
  678. ScreenToClient(m_hWnd,&pt);
  679. if(m_bHilightTitleBar&&!PtInRegion(m_hrgnTitle,pt.x,pt.y))
  680. {
  681. m_bHilightTitleBar=FALSE;
  682. RECT rc;
  683. SetRect(&rc,5,5,168,22);
  684. HDC hdc=GetDC(m_hWnd);
  685. HBITMAP hb=LoadBitmap(hInstX,LPCTSTR(IDB_TITLE1));
  686. DrawTransBmpX(hdc,rc,hb,0,0,0);
  687. DeleteObject(hb);
  688. ReleaseDC(m_hWnd,hdc);
  689. KillTimer(m_hWnd,nIDEvent);
  690. }
  691. break;
  692. case 2://draw fps and datarate
  693. {
  694. //得到发送的数据和接收的数据量
  695. DWORD ds=AVIO.GetDataSend();
  696. DWORD dr=AVIO.GetDataRcv();
  697. DWORD t=GetTickCount();
  698. //画帧频率
  699. char sz[60];
  700. sprintf(sz,"%dfps",AVIO.GetFps());
  701. DrawFps(sz);
  702. //累计通话时间
  703. m_uTalkTime++;
  704. sprintf(sz,"%.1fkbps  %d%d:%d%d:%d%d",
  705. ((float)ds-m_nDataSend+(float)dr-m_nDataRcv)*8000.0/((float)t-m_nTimePass)/1024.0,
  706. m_uTalkTime/36000,
  707. (m_uTalkTime/3600)%10,
  708. ((m_uTalkTime/60)%60)/10,
  709. ((m_uTalkTime/60)%60)%10,
  710. (m_uTalkTime%60)/10,
  711. (m_uTalkTime%60)%10);
  712. //画比特率和通话时间
  713. DrawDataRate(sz);
  714. //如果连续5次接收到的数据为0的话,结束通话
  715. if(dr-m_nDataRcv==0)
  716. m_iZeroCount++;
  717. else
  718. m_iZeroCount=0;
  719. if(m_iZeroCount>5)
  720. {
  721. AVIO.EndTalk();
  722. KillTimer(m_hWnd,2);
  723. ShowWindow(m_vs,SW_HIDE);
  724. ShowWindow(m_LocalVideoWnd.m_vs,SW_HIDE);
  725. ShowWindow(m_RemoteVideoWnd.m_vs,SW_HIDE);
  726. KillTimer(m_hWnd,2);
  727. DrawFps("");
  728. DrawDataRate("");
  729. CMsgBox::MessageBox(m_hWnd,IDS_ERR_NET_BLOCK,IDS_ERR,MB_OK,IDI_CUT);
  730. }
  731. m_nDataSend=ds;
  732. m_nDataRcv=dr;
  733. m_nTimePass=t;
  734. }
  735. break;
  736. }
  737. }
  738. /*------------------------------------------------------------------------------*/
  739. BOOL CMainWnd::OnSetCursor(HWND hWnd, UINT nHitTest, UINT message)
  740. {
  741. return FALSE;
  742. }
  743. /*------------------------------------------------------------------------------*/
  744. HBRUSH CMainWnd::OnCtrlColorEdit(HDC hdc, HWND hwnd)
  745. {
  746.     SetTextColor(hdc,0x00ffffff);
  747. SetBkColor(hdc,0);
  748. return m_hbCtrlBg;
  749. }
  750. /*------------------------------------------------------------------------------*/
  751. void CMainWnd::DrawFps(char* pszFps)
  752. {
  753. SetDlgItemText(m_hWnd,IDC_FPS,pszFps);
  754. }
  755. /*------------------------------------------------------------------------------*/
  756. //
  757. void CMainWnd::OnAudioData(BOOL flag,CAVIOMgr* pMgr)
  758. {
  759. if(!flag)//local
  760. {
  761. HDC hdc=GetDC(m_WaveShowIn);
  762. UINT len;
  763. char* p=pMgr->GetLocalAudio(len);
  764. m_WaveShowIn.Paint(hdc,p,len);
  765. ReleaseDC(m_WaveShowIn,hdc);
  766. }
  767. else
  768. {
  769. HDC hdc=GetDC(m_WaveShowOut);
  770. UINT len;
  771. char* p=pMgr->GetRemoteAudio(len);
  772. m_WaveShowOut.Paint(hdc,p,len);
  773. ReleaseDC(m_WaveShowOut,hdc);
  774. }
  775. }
  776. /*------------------------------------------------------------------------------*/
  777. void CMainWnd::DrawDataRate(char* pszDataRate)
  778. {
  779. SetDlgItemText(m_hWnd,IDC_DATARATE,pszDataRate);
  780. }
  781. /*------------------------------------------------------------------------------*/
  782. HBRUSH CMainWnd::OnCtrlColorStatic(HDC hdc, HWND hwnd)
  783. {
  784. if(hwnd==GetDlgItem(m_hWnd,IDC_FPS))
  785. {
  786. SetBkColor(hdc,0x00b9b4b3);
  787. SetTextColor(hdc,0x00ffffff);
  788. return m_hbFpsBg;
  789. }
  790. SetBkColor(hdc,0);
  791. SetTextColor(hdc,0x00aaeeff);  
  792. return m_hbCtrlBg;
  793. }
  794. /*------------------------------------------------------------------------------*/
  795. //AVIOMgr的通知消息处理
  796. void CMainWnd::OnIOMNotify(WPARAM wParam, LPARAM lParam)
  797. {
  798. switch(LOWORD(wParam))
  799. {
  800. case IOMN_CALL://呼叫到来
  801. {
  802. sockaddr_in sc=AVIO.GetRemoteAddr();
  803. char sz[50];
  804. sprintf(sz,"%d.%d.%d.%d",
  805. sc.sin_addr.S_un.S_un_b.s_b1,
  806. sc.sin_addr.S_un.S_un_b.s_b2,
  807. sc.sin_addr.S_un.S_un_b.s_b3,
  808. sc.sin_addr.S_un.S_un_b.s_b4);
  809. SetActiveWindow(m_hWnd);
  810. if(m_RingDlg.DoModal(m_hWnd,sz))
  811. {
  812. ShowWindow(m_LocalVideoWnd,SW_SHOWNORMAL);
  813. ShowWindow(m_hWnd,SW_SHOWNORMAL);
  814. SetForegroundWindow(m_hWnd);
  815. SetActiveWindow(m_hWnd);
  816. m_uTalkTime=0;
  817. m_nTimePass=GetTickCount();
  818. m_nDataRcv=0;
  819. m_nDataSend=0;
  820. m_nFrameCount=0;
  821. m_iZeroCount=0;
  822. SetTimer(m_hWnd,2,1000,0);
  823. AVIO.Accept();
  824. //接受了呼叫,把该次事件记录到log文件中
  825. char szPath[256];
  826. GetModuleFileName(0,szPath,255);
  827. int i;
  828. for(i=strlen(szPath);i>0;i--)
  829. {
  830. if(szPath[i]=='\')
  831. {
  832. szPath[i+1]=0;
  833. break;
  834. }
  835. }
  836. strcpy(szPath+strlen(szPath),"log.txt");
  837. SYSTEMTIME st;
  838. GetLocalTime(&st);
  839. char szDate[20];
  840. char szTime[20];
  841. sprintf(szDate,"%d-%d-%d",st.wYear,st.wMonth,st.wDay);
  842. sprintf(szTime,"%d:%d:%d",st.wHour,st.wMinute,st.wSecond);
  843. char szLog[100];
  844. sprintf(szLog,"接受了%s的通话请求",sz);
  845. WritePrivateProfileString(szDate,szTime,szLog,szPath);
  846. }
  847. else
  848. AVIO.Refuse();
  849. }break;
  850. //the request is accepted,so begin to talk
  851. case IOMN_ACCEPT:
  852. {
  853. SendMessage(m_CallDlg,WM_COMMAND,IDC_OK,0);
  854. ShowWindow(m_LocalVideoWnd,SW_SHOWNORMAL);
  855. ShowWindow(m_hWnd,SW_SHOWNORMAL);
  856. AVIO.OnAccept();
  857. m_uTalkTime=0;
  858. m_nTimePass=GetTickCount();
  859. m_nDataRcv=0;
  860. m_nDataSend=0;
  861. m_nFrameCount=0;
  862. m_iZeroCount=0;
  863. SetTimer(m_hWnd,2,1000,0);
  864. //write the talking event into log file
  865. sockaddr_in sc=AVIO.GetRemoteAddr();
  866. char sz[50];
  867. sprintf(sz,"%d.%d.%d.%d",
  868. sc.sin_addr.S_un.S_un_b.s_b1,
  869. sc.sin_addr.S_un.S_un_b.s_b2,
  870. sc.sin_addr.S_un.S_un_b.s_b3,
  871. sc.sin_addr.S_un.S_un_b.s_b4);
  872. char szPath[256];
  873. GetModuleFileName(0,szPath,255);
  874. int i;
  875. for(i=strlen(szPath);i>0;i--)
  876. {
  877. if(szPath[i]=='\')
  878. {
  879. szPath[i+1]=0;
  880. break;
  881. }
  882. }
  883. strcpy(szPath+strlen(szPath),"log.txt");
  884. SYSTEMTIME st;
  885. GetLocalTime(&st);
  886. char szDate[20];
  887. char szTime[20];
  888. sprintf(szDate,"%d-%d-%d",st.wYear,st.wMonth,st.wDay);
  889. sprintf(szTime,"%d:%d:%d",st.wHour,st.wMinute,st.wSecond);
  890. char szLog[100];
  891. sprintf(szLog,"%s你接受了你的通话请求",sz);
  892. WritePrivateProfileString(szDate,szTime,szLog,szPath);
  893. }
  894. break;
  895. case IOMN_CONNECTED:
  896. {
  897. if(IsWindow(m_CallDlg))
  898. {
  899. m_CallDlg.Connected();
  900. }
  901. }
  902. break;
  903. case IOMN_END:
  904. {
  905. AVIO.EndTalk();
  906. KillTimer(m_hWnd,2);
  907. DrawFps("");
  908. DrawDataRate("");
  909. ShowWindow(m_vs,SW_HIDE);
  910. ShowWindow(m_LocalVideoWnd.m_vs,SW_HIDE);
  911. ShowWindow(m_RemoteVideoWnd.m_vs,SW_HIDE);
  912. if(IsWindow(m_RingDlg))
  913. EndDialog(m_RingDlg,FALSE);
  914. else
  915. {
  916. if(HIWORD(wParam)==E_USER)
  917. {
  918. CMsgBox::MessageBox(m_hWnd,IDS_MSG_ENDTALK,IDS_MSG,MB_OK,IDI_INFO);
  919. }
  920. }
  921. }
  922. break;
  923. case IOMN_REFUSE:
  924. {
  925. switch(HIWORD(wParam))
  926. {
  927. case R_TIMEOUT:
  928. {
  929. m_CallDlg.FailConnect();
  930. }
  931. break;
  932. case R_USER:
  933. {
  934. m_CallDlg.Refuse();
  935. }
  936. break;
  937. case R_BUSY:
  938. {
  939. m_CallDlg.Busy();
  940. }
  941. break;
  942. }
  943. }
  944. break;
  945. //the error of aviomgr
  946. case IOMN_ERR:
  947. {
  948. switch(HIWORD(wParam))
  949. {
  950. case IOME_SOCKET:
  951. CMsgBox::MessageBox(m_hWnd,IDS_ERR_NET_SOCKET,IDS_ERR,MB_OK,IDI_ERR);
  952. break;
  953. case IOME_AUDIO_IN:
  954. CMsgBox::MessageBox(m_hWnd,IDS_ERR_AUDIO_IN,IDS_ERR,MB_OK,IDI_ERR);
  955. break;
  956. case IOME_AUDIO_OUT:
  957. CMsgBox::MessageBox(m_hWnd,IDS_ERR_AUDIO_OUT,IDS_ERR,MB_OK,IDI_ERR);
  958. break;
  959. case IOME_VIDEO_IN:
  960. m_LocalVideoWnd.SetErrTxt("无法打开视频输入设备");
  961. break;
  962. case IOME_VIDEO_OUT:
  963. //always good
  964. break;
  965. case IOME_AUDIO_CODEC:
  966. CMsgBox::MessageBox(m_hWnd,IDS_ERR_AUDIO_CODEC,IDS_ERR,MB_OK,IDI_ERR);
  967. break;
  968. case IOME_VIDEO_CODEC:
  969. CMsgBox::MessageBox(m_hWnd,IDS_ERR_VIDEO_CODEC,IDS_ERR,MB_OK,IDI_ERR);
  970. break;
  971. }
  972. }break;
  973. //Txt msg come,or notify that the txt msg has been confermed received
  974. case IOMN_TXT:
  975. {
  976. if(HIWORD(wParam))
  977. {
  978. char sz[500];
  979. sprintf(sz,"%s:%s","我",(char*)lParam);
  980. m_MsgTalk.AddMsg(sz);
  981. }
  982. else
  983. {
  984. sockaddr_in sc=AVIO.GetCurrentAddr();
  985. char sz[500];
  986. sprintf(sz,"%d.%d.%d.%d:%s",
  987. sc.sin_addr.S_un.S_un_b.s_b1,
  988. sc.sin_addr.S_un.S_un_b.s_b2,
  989. sc.sin_addr.S_un.S_un_b.s_b3,
  990. sc.sin_addr.S_un.S_un_b.s_b4,(char*)lParam);
  991. m_MsgTalk.AddMsg(sz);
  992. if(CSetupDlg::Setup.bAutoMsg)
  993. {
  994. ShowWindow(m_MsgTalk,SW_SHOW);
  995. SetForegroundWindow(m_MsgTalk);
  996. SetActiveWindow(m_MsgTalk);
  997. }
  998. }
  999. }break;
  1000. //the video quality was set by aviomgr automatically
  1001. case IOMN_VQSET:
  1002. {
  1003. m_sldVideoQ.SetPos(HIWORD(wParam));
  1004. }break;
  1005. }
  1006. }
  1007. /*------------------------------------------------------------------------------*/
  1008. //when the output volume was changed,this would be invoked
  1009. void CALLBACK CMainWnd::OutVolumeChanged( DWORD dwCurrentVolume, DWORD dwUserValue )
  1010. {
  1011. CMainWnd* p=(CMainWnd*)dwUserValue;
  1012. p->m_sldAudioOut.SetPos(dwCurrentVolume*100/
  1013. (p->m_VoOutCtrl.GetMaximalVolume()-p->m_VoOutCtrl.GetMinimalVolume()));
  1014. }
  1015. /*------------------------------------------------------------------------------*/
  1016. void CALLBACK CMainWnd::InVolumeChanged( DWORD dwCurrentVolume, DWORD dwUserValue )
  1017. {
  1018. CMainWnd* p=(CMainWnd*)dwUserValue;
  1019. p->m_sldAudioIn.SetPos(dwCurrentVolume*100/
  1020. (p->m_VoInCtrl.GetMaximalVolume()-p->m_VoInCtrl.GetMinimalVolume()));
  1021. }
  1022. /*------------------------------------------------------------------------------*/
  1023. //when the setup was changed,this would be call
  1024. void CMainWnd::OnSetup(SETUP *Setup)
  1025. {
  1026. char sz[20];
  1027. sz[1]=0;
  1028. //autorun
  1029. if(Setup->bAutoRun)
  1030. {
  1031. sz[0]='1';
  1032. HKEY  hKey=NULL;
  1033. DWORD dwValueType=REG_SZ;
  1034. DWORD dwStrCb=128;
  1035. DWORD  dwDisposition;
  1036. char szPath[256];
  1037. GetModuleFileName(0,szPath,255);
  1038. if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Run"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKey)!=ERROR_SUCCESS)
  1039. {
  1040. RegCreateKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Run"),0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, 
  1041. NULL, &hKey, &dwDisposition);
  1042. }
  1043. if (RegSetValueEx(hKey,"NetTalk",0,REG_SZ,(const BYTE*)szPath,dwStrCb)!=ERROR_SUCCESS) 
  1044. {
  1045. RegCloseKey(hKey);
  1046. }
  1047. }
  1048. else
  1049. {
  1050. sz[0]='0';
  1051. HKEY  hKey=NULL;
  1052. if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\Microsoft\Windows\CurrentVersion\Run"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKey)==ERROR_SUCCESS)
  1053. {
  1054. RegDeleteValue(hKey,"NetTalk");
  1055. }
  1056. }
  1057. //
  1058. AVIO.EnableBandAdjust(Setup->bBandAdjust);
  1059. //
  1060. AVIO.Enable(!Setup->bRefuseCall);
  1061. //when refuse call,the avio was disable,change the notify-try icon
  1062. if(Setup->bRefuseCall)
  1063. {
  1064. m_TrayNotify.SetIcon(LoadIcon(hInstX,LPCTSTR(IDI_DISABLE)));
  1065. m_TrayNotify.Refresh();
  1066. }
  1067. else
  1068. {
  1069. m_TrayNotify.SetIcon(LoadIcon(hInstX,LPCTSTR(IDI_MAIN)));
  1070. m_TrayNotify.Refresh();
  1071. }
  1072. //unregister the old hotkey,and register the new hotkey
  1073. UnregisterHotKey(m_hWnd,1);
  1074. UINT Mod=0;
  1075. if(HOTKEYF_ALT&HIBYTE(Setup->wHotKey))
  1076. Mod|=MOD_ALT;
  1077. if(HOTKEYF_CONTROL&HIBYTE(Setup->wHotKey))
  1078. Mod|=MOD_CONTROL;
  1079. if(HOTKEYF_SHIFT&HIBYTE(Setup->wHotKey))
  1080. Mod|=MOD_SHIFT;
  1081. if(!RegisterHotKey(m_hWnd,1,Mod,LOBYTE(Setup->wHotKey)))
  1082. CMsgBox::MessageBox(m_hWnd,IDS_ERR_HOTKEY,IDS_ERR,MB_OK,IDI_INFO);
  1083. }
  1084. /*------------------------------------------------------------------------------*/
  1085. //
  1086. void CMainWnd::OnTrayNotify(WPARAM wParam, LPARAM lParam)
  1087. {
  1088. switch(lParam)
  1089. {
  1090. case WM_LBUTTONDBLCLK:
  1091. {
  1092. ShowWindow(m_hWnd,SW_SHOWNORMAL);
  1093. SetForegroundWindow(m_hWnd);
  1094. SetActiveWindow(m_hWnd);
  1095. }
  1096. break;
  1097. case WM_RBUTTONDOWN:
  1098. {
  1099. HMENU hMenu=LoadMenu(hInstX,LPCTSTR(IDR_POP));
  1100. HMENU hSub=GetSubMenu(hMenu,0);
  1101. SetForegroundWindow(m_hWnd);
  1102. POINT pt;
  1103. GetCursorPos(&pt);
  1104. DWORD dwID=TrackPopupMenu(hSub,TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_RETURNCMD,pt.x,pt.y,0,m_hWnd,0);
  1105. {
  1106. switch(dwID)
  1107. {
  1108. case ID_SHOWCHATER:
  1109. SendMessage(m_hWnd,WM_COMMAND,IDC_MSG,0);
  1110. break;
  1111. case ID_SHOW:
  1112. ShowWindow(m_hWnd,SW_SHOWNORMAL);
  1113. SetForegroundWindow(m_hWnd);
  1114. SetActiveWindow(m_hWnd);
  1115. break;
  1116. case ID_EXIT:
  1117. SendMessage(m_hWnd,WM_CLOSE,0,0);
  1118. break;
  1119. case ID_ABOUT:
  1120. if(IsWindowEnabled(m_hWnd))
  1121. SendMessage(m_hWnd,WM_COMMAND,IDC_ABOUT,0);
  1122. break;
  1123. case ID_CALL:
  1124. if(IsWindowEnabled(m_hWnd))
  1125. SendMessage(m_hWnd,WM_COMMAND,IDC_CALL,0);
  1126. break;
  1127. case ID_H:
  1128. SendMessage(m_hWnd,WM_COMMAND,IDC_HP,0);
  1129. break;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. }
  1135. /*------------------------------------------------------------------------------*/
  1136. //implementation of about dialog
  1137. CAboutDlg::CAboutDlg()
  1138. {
  1139. }
  1140. /*------------------------------------------------------------------------------*/
  1141. CAboutDlg::~CAboutDlg()
  1142. {
  1143. }
  1144. /*------------------------------------------------------------------------------*/
  1145. LRESULT CAboutDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1146. {
  1147. switch(uMsg)
  1148. {
  1149. case WM_COMMAND:
  1150. {
  1151. CGraphDlg::OnCommand(wParam,lParam);
  1152. switch(LOWORD(wParam))
  1153. {
  1154. case IDC_LOGO:
  1155. KillTimer(m_hWnd,1);
  1156. ShowWindow(m_cd1,SW_HIDE);
  1157. ShowWindow(m_cd2,SW_HIDE);
  1158. ShowWindow(m_rw,SW_SHOW);
  1159. break;
  1160. case IDC_CREDIT:
  1161. if(!IsWindowVisible(m_cd1))
  1162. SetTimer(m_hWnd,1,30,0);
  1163. SetTimer(m_hWnd,1,30,0);
  1164. ShowWindow(m_cd1,SW_SHOW);
  1165. ShowWindow(m_cd2,SW_SHOW);
  1166. ShowWindow(m_rw,SW_HIDE);
  1167. break;
  1168. }
  1169. }
  1170. break;
  1171. case WM_INITDIALOG:
  1172. {
  1173. CGraphDlg::OnInitDialog();
  1174. SetWindowText(m_hWnd,"关于NetTalk");
  1175. MoveWindow(GetDlgItem(m_hWnd,IDC_CONTAINER),7,50,286,182,FALSE);
  1176. m_rw.Create((CRectX&)CRectX(0,0,286,182),GetDlgItem(m_hWnd,IDC_CONTAINER),IDB_LOGO1,286,182);
  1177. m_cd1.Create(GetDlgItem(m_hWnd,IDC_CONTAINER));
  1178. m_cd2.Create(GetDlgItem(m_hWnd,IDC_CONTAINER));
  1179. SetWindowPos(m_cd1,0,0,0,0,0,SWP_NOSIZE);
  1180. CRectX rc;
  1181. GetWindowRect(m_cd1,&rc);
  1182. SetWindowPos(m_cd2,0,0,rc.Height(),0,0,SWP_NOSIZE);
  1183. SendDlgItemMessage(m_hWnd,IDC_LOGO,BM_SETCHECK,BST_CHECKED,0);
  1184. return FALSE;
  1185. }
  1186. break;
  1187. case WM_TIMER:
  1188. {
  1189. CGraphDlg::OnTimer(wParam);
  1190. CRectX rc1,rc2,rc3;
  1191. GetWindowRect(m_cd1,&rc1);
  1192. GetWindowRect(m_cd2,&rc2);
  1193. GetWindowRect(GetDlgItem(m_hWnd,IDC_CONTAINER),&rc3);
  1194. OffsetRect(&rc1,-rc3.left,-rc3.top);
  1195. OffsetRect(&rc2,-rc3.left,-rc3.top);
  1196. SetWindowPos(m_cd1,0,0,rc1.top-1,0,0,SWP_NOSIZE);
  1197. SetWindowPos(m_cd2,0,0,rc2.top-1,0,0,SWP_NOSIZE);
  1198. if(rc1.bottom<0)
  1199. {
  1200. SetWindowPos(m_cd1,0,0,rc2.bottom-1,0,0,SWP_NOSIZE);
  1201. }
  1202. if(rc2.bottom<0)
  1203. {
  1204. SetWindowPos(m_cd2,0,0,rc1.bottom-1,0,0,SWP_NOSIZE);
  1205. }
  1206. }break;
  1207. default:
  1208. return CGraphDlg::WndProc(uMsg,wParam,lParam);
  1209. }
  1210. return TRUE;
  1211. }
  1212. /*------------------------------------------------------------------------------*/
  1213. //implementation of IP input dialog
  1214. CIPInput::CIPInput()
  1215. {
  1216. m_szIP[0]=0;
  1217. m_uPort=0;
  1218. }
  1219. /*------------------------------------------------------------------------------*/
  1220. CIPInput::~CIPInput()
  1221. {
  1222. }
  1223. /*------------------------------------------------------------------------------*/
  1224. LRESULT CIPInput::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1225. {
  1226. switch(uMsg)
  1227. {
  1228. case WM_COMMAND:
  1229. {
  1230. switch(LOWORD(wParam))
  1231. {
  1232. case IDC_OK:
  1233. {
  1234. GetDlgItemText(m_hWnd,IDC_IP,m_szIP,29);
  1235. if(strlen(m_szIP)>0)
  1236. {
  1237. //set the result to variables
  1238. char sz[20];
  1239. GetDlgItemText(m_hWnd,IDC_PORT,sz,19);
  1240. m_uPort=(unsigned short)strtoul(sz,0,10);
  1241. //update the recent call address
  1242. HWND hcb=GetDlgItem(m_hWnd,IDC_IP);
  1243. int iItem=SendMessage(hcb,CB_FINDSTRING,-1,(LPARAM)m_szIP);
  1244. if(iItem<0)
  1245. SendMessage(hcb,CB_INSERTSTRING,0,(LPARAM)m_szIP);
  1246. else
  1247. {
  1248. SendMessage(hcb,CB_DELETESTRING,iItem,0);
  1249. SendMessage(hcb,CB_INSERTSTRING,0,(LPARAM)m_szIP);
  1250. }
  1251. int iCount=SendMessage(hcb,CB_GETCOUNT,0,0);
  1252. if(iCount>20)
  1253. iCount=20;
  1254. char szI[4];
  1255. for(int i=0;i<iCount;i++)
  1256. {
  1257. sprintf(szI,"%d",i);
  1258. SendMessage(hcb,CB_SETCURSEL,iCount-i-1,0);
  1259. GetWindowText(hcb,m_szIP,256);
  1260. WritePrivateProfileString("recent",szI,m_szIP,"NetTalk.ini");
  1261. }
  1262. sprintf(szI,"%d",iCount);
  1263. WritePrivateProfileString("recent","count",szI,"NetTalk.ini");
  1264. //
  1265. EndDialog(m_hWnd,TRUE);
  1266. }
  1267. }
  1268. break;
  1269. case IDC_CANCEL:
  1270. EndDialog(m_hWnd,FALSE);
  1271. break;
  1272. case IDC_ADDR:
  1273. {
  1274. HWND h=GetParent(m_hWnd);
  1275. EndDialog(m_hWnd,FALSE);
  1276. CAddrBook ab;
  1277. ab.DoModal(LPCTSTR(IDD_ADDR),h);
  1278. }
  1279. break;
  1280. }
  1281. CGraphDlg::OnCommand(wParam,lParam);
  1282. }
  1283. break;
  1284. case WM_INITDIALOG:
  1285. {
  1286. SetWindowText(m_hWnd,"请输入对方IP或计算机名");
  1287. CGraphDlg::OnInitDialog();
  1288. char sz[10];
  1289. sprintf(sz,"%d",PORT);
  1290. SetDlgItemText(m_hWnd,IDC_PORT,sz);
  1291. //载入最近呼叫
  1292. int c=GetPrivateProfileInt("recent","count",0,"NetTalk.ini");
  1293. if(c>=20)
  1294. {
  1295. c=20;
  1296. }
  1297. char szStr[256];
  1298. for(int i=0;i<c;i++)
  1299. {
  1300. char szI[4];
  1301. sprintf(szI,"%d",i);
  1302. if(GetPrivateProfileString("recent",szI,"",szStr,256,"NetTalk.ini"))
  1303. {
  1304. SendMessage(GetDlgItem(m_hWnd,IDC_IP),CB_INSERTSTRING,0,(LPARAM)szStr);
  1305. }
  1306. }
  1307. SendMessage(GetDlgItem(m_hWnd,IDC_IP),CB_SETCURSEL,0,0);
  1308. }
  1309. break;
  1310. case WM_ERASEBKGND:
  1311. {
  1312. CGraphDlg::OnEraseBkgnd((HDC)wParam);
  1313. DrawIcon((HDC)wParam,10,28,LoadIcon(hInstX,LPCTSTR(IDI_PHONE)));
  1314. }
  1315. break;
  1316. case WM_CLOSE:
  1317. {
  1318. EndDialog(m_hWnd,FALSE);
  1319. }
  1320. break;
  1321. default:
  1322. return CGraphDlg::WndProc(uMsg,wParam,lParam);
  1323. }
  1324. return TRUE;
  1325. }
  1326. /*------------------------------------------------------------------------------*/
  1327. //implementation of setup dlg
  1328. CSetupDlg::CSetupDlg()
  1329. {
  1330. }
  1331. /*------------------------------------------------------------------------------*/
  1332. CSetupDlg::~CSetupDlg()
  1333. {
  1334. }
  1335. /*------------------------------------------------------------------------------*/
  1336. LRESULT CSetupDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1337. {
  1338. switch(uMsg)
  1339. {
  1340. case WM_DESTROY:
  1341. CGraphDlg::OnDestroy();
  1342. PlaySound(0,0,0);
  1343. break;
  1344. case WM_INITDIALOG:
  1345. return OnInitDialog();
  1346. break;
  1347. case WM_COMMAND:
  1348. return OnCommand(wParam,lParam);
  1349. break;
  1350. default:
  1351. return CGraphDlg::WndProc(uMsg,wParam,lParam);
  1352. }
  1353. return TRUE;
  1354. }
  1355. /*------------------------------------------------------------------------------*/
  1356. void CSetupDlg::LoadSetup()
  1357. {
  1358. Setup.bAutoRun=(BOOL)GetPrivateProfileInt("setup","auto",0,"NetTalk.ini");
  1359. Setup.bInitShow=(BOOL)GetPrivateProfileInt("setup","initshow",0,"NetTalk.ini");
  1360. Setup.bMiniHide=(BOOL)GetPrivateProfileInt("setup","minihide",1,"NetTalk.ini");
  1361. Setup.bRing=(BOOL)GetPrivateProfileInt("setup","playring",1,"NetTalk.ini");
  1362. Setup.bRingUser=(BOOL)GetPrivateProfileInt("setup","ringuser",0,"NetTalk.ini");
  1363. Setup.bAutoMsg=(BOOL)GetPrivateProfileInt("setup","automsg",1,"NetTalk.ini");
  1364. Setup.bRefuseCall=(BOOL)GetPrivateProfileInt("setup","refusecall",0,"NetTalk.ini");
  1365. Setup.bBandAdjust=(BOOL)GetPrivateProfileInt("setup","bandadjust",1,"NetTalk.ini");
  1366. Setup.wHotKey=0xffff&GetPrivateProfileInt("setup","hotkey",MAKEWORD('A',HOTKEYF_ALT|HOTKEYF_CONTROL),"NetTalk.ini");
  1367. GetPrivateProfileString("setup","ringpath","",Setup.szRingPath,sizeof(Setup.szRingPath),"NetTalk.ini");
  1368. }
  1369. /*------------------------------------------------------------------------------*/
  1370. void CSetupDlg::SaveSetup()
  1371. {
  1372. char sz[20];
  1373. sz[1]=0;
  1374. if(Setup.bAutoRun)
  1375. sz[0]='1';
  1376. else
  1377. sz[0]='0';
  1378. WritePrivateProfileString("setup","auto",sz,"NetTalk.ini");
  1379. if(Setup.bInitShow)
  1380. sz[0]='1';
  1381. else
  1382. sz[0]='0';
  1383. WritePrivateProfileString("setup","initshow",sz,"NetTalk.ini");
  1384. if(Setup.bMiniHide)
  1385. sz[0]='1';
  1386. else
  1387. sz[0]='0';
  1388. WritePrivateProfileString("setup","minihide",sz,"NetTalk.ini");
  1389. if(Setup.bRing)
  1390. sz[0]='1';
  1391. else
  1392. sz[0]='0';
  1393. WritePrivateProfileString("setup","playring",sz,"NetTalk.ini");
  1394. if(Setup.bRingUser)
  1395. sz[0]='1';
  1396. else
  1397. sz[0]='0';
  1398. WritePrivateProfileString("setup","ringuser",sz,"NetTalk.ini");
  1399. if(Setup.bAutoMsg)
  1400. sz[0]='1';
  1401. else
  1402. sz[0]='0';
  1403. WritePrivateProfileString("setup","automsg",sz,"NetTalk.ini");
  1404. if(Setup.bRefuseCall)
  1405. sz[0]='1';
  1406. else
  1407. sz[0]='0';
  1408. WritePrivateProfileString("setup","refusecall",sz,"NetTalk.ini");
  1409. if(Setup.bBandAdjust)
  1410. sz[0]='1';
  1411. else
  1412. sz[0]='0';
  1413. WritePrivateProfileString("setup","bandadjust",sz,"NetTalk.ini");
  1414. sprintf(sz,"%d",Setup.wHotKey);
  1415. WritePrivateProfileString("setup","hotkey",sz,"NetTalk.ini");
  1416. WritePrivateProfileString("setup","ringpath",Setup.szRingPath,"NetTalk.ini");
  1417. }
  1418. /*------------------------------------------------------------------------------*/
  1419. BOOL CSetupDlg::OnInitDialog()
  1420. {
  1421. CGraphDlg::OnInitDialog();
  1422. SetWindowText(m_hWnd,"NetTalk设置");
  1423. if(Setup.bAutoRun)
  1424. SendMessage(GetDlgItem(m_hWnd,IDC_AUTORUN),BM_SETCHECK,BST_CHECKED,0);
  1425. if(Setup.bInitShow)
  1426. SendMessage(GetDlgItem(m_hWnd,IDC_INITSHOW),BM_SETCHECK,BST_CHECKED,0);
  1427. if(Setup.bMiniHide)
  1428. SendMessage(GetDlgItem(m_hWnd,IDC_MINIHIDE),BM_SETCHECK,BST_CHECKED,0);
  1429. if(Setup.bRing)
  1430. SendMessage(GetDlgItem(m_hWnd,IDC_PLAYRING),BM_SETCHECK,BST_CHECKED,0);
  1431. if(Setup.bRingUser)
  1432. SendMessage(GetDlgItem(m_hWnd,IDC_USERRING),BM_SETCHECK,BST_CHECKED,0);
  1433. if(Setup.bAutoMsg)
  1434. SendMessage(GetDlgItem(m_hWnd,IDC_AUTOMSG),BM_SETCHECK,BST_CHECKED,0);
  1435. if(Setup.bRefuseCall)
  1436. SendMessage(GetDlgItem(m_hWnd,IDC_REFUSECALL),BM_SETCHECK,BST_CHECKED,0);
  1437. if(Setup.bBandAdjust)
  1438. SendMessage(GetDlgItem(m_hWnd,IDC_BANDADJUST),BM_SETCHECK,BST_CHECKED,0);
  1439. EnableWindow(GetDlgItem(m_hWnd,IDC_PLAY),Setup.bRingUser);
  1440. EnableWindow(GetDlgItem(m_hWnd,IDC_BROWSE),Setup.bRingUser);
  1441. SendDlgItemMessage(m_hWnd,IDC_HOTKEY,HKM_SETHOTKEY,Setup.wHotKey,0);
  1442. return FALSE;
  1443. }
  1444. /*------------------------------------------------------------------------------*/
  1445. BOOL CSetupDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  1446. {
  1447. CGraphDlg::OnCommand(wParam,lParam);
  1448. switch(LOWORD(wParam))
  1449. {
  1450. case IDC_OK:
  1451. {
  1452. Setup.wHotKey=(WORD)SendDlgItemMessage(m_hWnd,IDC_HOTKEY,HKM_GETHOTKEY,0,0);
  1453. SaveSetup();
  1454. OnOK();
  1455. SendMessage(GetParent(m_hWnd),WM_USER_SETUP,0,(LPARAM)&Setup);
  1456. }
  1457. break;
  1458. case IDC_AUTORUN:
  1459. Setup.bAutoRun^=1;
  1460. break;
  1461. case IDC_INITSHOW:
  1462. Setup.bInitShow^=1;
  1463. break;
  1464. case IDC_MINIHIDE:
  1465. Setup.bMiniHide^=1;
  1466. break;
  1467. case IDC_PLAYRING:
  1468. Setup.bRing^=1;
  1469. break;
  1470. case IDC_USERRING:
  1471. Setup.bRingUser^=1;
  1472. EnableWindow(GetDlgItem(m_hWnd,IDC_PLAY),Setup.bRingUser);
  1473. EnableWindow(GetDlgItem(m_hWnd,IDC_BROWSE),Setup.bRingUser);
  1474. break;
  1475. case IDC_AUTOMSG:
  1476. Setup.bAutoMsg^=1;
  1477. break;
  1478. case IDC_REFUSECALL:
  1479. Setup.bRefuseCall^=1;
  1480. break;
  1481. case IDC_BANDADJUST:
  1482. Setup.bBandAdjust^=1;
  1483. break;
  1484. case IDC_CANCEL:
  1485. OnCancel();
  1486. break;
  1487. case IDC_BROWSE:
  1488. {
  1489. OPENFILENAME ofn;
  1490. ZeroMemory(&ofn,sizeof(ofn));
  1491. ofn.lStructSize=sizeof(ofn);
  1492. ofn.hInstance=GetModuleHandle(0);
  1493. ofn.hwndOwner=m_hWnd;
  1494. char szFilter[100];
  1495. char* p=szFilter;
  1496. strcpy(p,"波形文件(*.wav)");
  1497. p+=strlen(p)+1;
  1498. strcpy(p,"*.wav");
  1499. p+=strlen(p)+1;
  1500. *p=0;
  1501. ofn.lpstrFilter=szFilter;
  1502. char szFile[256]="";
  1503. ofn.lpstrFile=szFile;
  1504. ofn.nMaxFile=256;
  1505. ofn.lpstrTitle="请选择";
  1506. ofn.Flags=OFN_FILEMUSTEXIST;
  1507. if(GetOpenFileName(&ofn))
  1508. {
  1509. strcpy(Setup.szRingPath,szFile);
  1510. }
  1511. }
  1512. break;
  1513. case IDC_PLAY:
  1514. PlaySound(Setup.szRingPath,0,SND_FILENAME|SND_ASYNC);
  1515. break;
  1516. }
  1517. return TRUE;
  1518. }
  1519. /*------------------------------------------------------------------------------*/
  1520. //implementation of ring dlg
  1521. CRingDlg::CRingDlg()
  1522. {
  1523. }
  1524. /*------------------------------------------------------------------------------*/
  1525. CRingDlg::~CRingDlg()
  1526. {
  1527. }
  1528. /*------------------------------------------------------------------------------*/
  1529. LRESULT CRingDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1530. {
  1531. switch(uMsg)
  1532. {
  1533. case WM_INITDIALOG:
  1534. return OnInitDialog();
  1535. break;
  1536. case WM_DESTROY:
  1537. CGraphDlg::OnDestroy();
  1538. KillTimer(m_hWnd,1);
  1539. PlaySound(0,0,0);
  1540. break;
  1541. case WM_COMMAND:
  1542. return OnCommand(wParam,lParam);
  1543. case WM_ERASEBKGND:
  1544. OnEraseBkgnd((HDC)wParam);
  1545. return TRUE;
  1546. case WM_TIMER:
  1547. CGraphDlg::OnTimer(wParam);
  1548. if(wParam==1&&CSetupDlg::Setup.bRing)
  1549. {
  1550. if(CSetupDlg::Setup.bRingUser)
  1551. PlaySound(CSetupDlg::Setup.szRingPath,0,SND_FILENAME|SND_ASYNC);
  1552. else
  1553. PlaySound(LPCTSTR(IDR_CALL),hInstX,SND_RESOURCE|SND_ASYNC);
  1554. }
  1555. break;
  1556. default:
  1557. return CGraphDlg::WndProc(uMsg,wParam,lParam);
  1558. }
  1559. return TRUE;
  1560. }
  1561. /*------------------------------------------------------------------------------*/
  1562. BOOL CRingDlg::OnInitDialog()
  1563. {
  1564. CGraphDlg::OnInitDialog();
  1565. SetWindowText(m_hWnd,m_szCaller);
  1566. char szTxt[256];
  1567. sprintf(szTxt,"%s发来呼叫请求rrn要接受请求吗?",m_szCaller);
  1568. SetDlgItemText(m_hWnd,IDC_TXT,szTxt);
  1569. SetDlgItemText(m_hWnd,IDC_OK,"是(&Y)");
  1570. SetDlgItemText(m_hWnd,IDC_CANCEL,"否(&N)");
  1571. SetTimer(m_hWnd,1,3000,0);
  1572. if(CSetupDlg::Setup.bRing)
  1573. {
  1574. if(CSetupDlg::Setup.bRingUser)
  1575. PlaySound(CSetupDlg::Setup.szRingPath,0,SND_FILENAME|SND_ASYNC);
  1576. else
  1577. PlaySound(LPCTSTR(IDR_CALL),hInstX,SND_RESOURCE|SND_ASYNC);
  1578. }
  1579. SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
  1580. return FALSE;
  1581. }
  1582. /*------------------------------------------------------------------------------*/
  1583. BOOL CRingDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  1584. {
  1585. CGraphDlg::OnCommand(wParam,lParam);
  1586. switch(LOWORD(wParam))
  1587. {
  1588. case IDC_OK:
  1589. EndDialog(m_hWnd,TRUE);
  1590. break;
  1591. case IDC_CANCEL:
  1592. EndDialog(m_hWnd,FALSE);
  1593. break;
  1594. }
  1595. return TRUE;
  1596. }
  1597. /*------------------------------------------------------------------------------*/
  1598. BOOL CRingDlg::DoModal(HWND hParent, char *szCaller)
  1599. {
  1600. m_szCaller=szCaller;
  1601. return CGraphDlg::DoModal(LPCTSTR(IDD_MSGBOX),hParent);
  1602. }
  1603. /*------------------------------------------------------------------------------*/
  1604. void CRingDlg::OnEraseBkgnd(HDC hdc)
  1605. {
  1606. CGraphDlg::OnEraseBkgnd(hdc);
  1607. DrawIcon(hdc,25,45,LoadIcon(hInstX,LPCTSTR(IDI_GLOBAL)));
  1608. }
  1609. /*------------------------------------------------------------------------------*/
  1610. //implementation of call dlg
  1611. CCallDlg::CCallDlg()
  1612. {
  1613. }
  1614. /*------------------------------------------------------------------------------*/
  1615. CCallDlg::~CCallDlg()
  1616. {
  1617. }
  1618. /*------------------------------------------------------------------------------*/
  1619. LRESULT CCallDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1620. {
  1621. switch(uMsg)
  1622. {
  1623. case WM_INITDIALOG:
  1624. return OnInitDialog();
  1625. break;
  1626. case WM_COMMAND:
  1627. return OnCommand(wParam,lParam);
  1628. case WM_ERASEBKGND:
  1629. OnEraseBkgnd((HDC)wParam);
  1630. return TRUE;
  1631. case WM_CLOSE:
  1632. break;
  1633. default:
  1634. return CGraphDlg::WndProc(uMsg,wParam,lParam);
  1635. }
  1636. return TRUE;
  1637. }
  1638. /*------------------------------------------------------------------------------*/
  1639. BOOL CCallDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  1640. {
  1641. CGraphDlg::OnCommand(wParam,lParam);
  1642. switch(LOWORD(wParam))
  1643. {
  1644. case IDC_CANCEL:
  1645. EndDialog(m_hWnd,FALSE);
  1646. break;
  1647. case IDC_OK:
  1648. EndDialog(m_hWnd,TRUE);
  1649. break;
  1650. }
  1651. return TRUE;
  1652. }
  1653. /*------------------------------------------------------------------------------*/
  1654. void CCallDlg::OnEraseBkgnd(HDC hdc)
  1655. {
  1656. CGraphDlg::OnEraseBkgnd(hdc);
  1657. DrawIcon(hdc,25,45,LoadIcon(hInstX,LPCTSTR(IDI_GLOBAL)));
  1658. }
  1659. /*------------------------------------------------------------------------------*/
  1660. BOOL CCallDlg::OnInitDialog()
  1661. {
  1662. CGraphDlg::OnInitDialog();
  1663. ShowWindow(m_btnClose,SW_HIDE);
  1664. SetWindowText(m_hWnd,"请稍候");
  1665. char szTxt[128];
  1666. sprintf(szTxt,"正在连接计算机  %s...",m_szDst);
  1667. SetDlgItemText(m_hWnd,IDC_TXT,szTxt);
  1668. ShowWindow(GetDlgItem(m_hWnd,IDC_OK),SW_HIDE);
  1669. ShowWindow(GetDlgItem(m_hWnd,IDC_CANCEL),SW_HIDE);
  1670. SetDlgItemText(m_hWnd,IDC_CANCEL,"取消");
  1671. SetDlgItemText(m_hWnd,IDC_OK,"确定");
  1672. return TRUE;
  1673. }
  1674. /*------------------------------------------------------------------------------*/
  1675. BOOL CCallDlg::DoModal(HWND hParent, char *szDst)
  1676. {
  1677. m_szDst=szDst;
  1678. return CGraphDlg::DoModal(LPCTSTR(IDD_MSGBOX),hParent);
  1679. }
  1680. /*------------------------------------------------------------------------------*/
  1681. //when connected,
  1682. void CCallDlg::Connected()
  1683. {
  1684. if(IsWindow(m_hWnd))
  1685. {
  1686. char szTxt[]="已经连接到目标计算机rrn请等待对方回应...";
  1687. SetDlgItemText(m_hWnd,IDC_TXT,szTxt);
  1688. ShowWindow(GetDlgItem(m_hWnd,IDC_CANCEL),SW_SHOW);
  1689. EnableWindow(GetDlgItem(m_hWnd,IDC_OK),FALSE);
  1690. }
  1691. }
  1692. /*------------------------------------------------------------------------------*/
  1693. //fail to connect
  1694. void CCallDlg::FailConnect()
  1695. {
  1696. if(IsWindow(m_hWnd))
  1697. {
  1698. char szTxt[]="无法连接到目标计算机";
  1699. SetDlgItemText(m_hWnd,IDC_TXT,szTxt);
  1700. ShowWindow(GetDlgItem(m_hWnd,IDC_OK),SW_SHOW);
  1701. }
  1702. }
  1703. /*------------------------------------------------------------------------------*/
  1704. //the request is refused by user
  1705. void CCallDlg::Refuse()
  1706. {
  1707. if(IsWindow(m_hWnd))
  1708. {
  1709. char szTxt[]="对方拒绝了您的通话请求";
  1710. SetDlgItemText(m_hWnd,IDC_TXT,szTxt);
  1711. ShowWindow(GetDlgItem(m_hWnd,IDC_OK),SW_SHOW);
  1712. ShowWindow(GetDlgItem(m_hWnd,IDC_CANCEL),SW_HIDE);
  1713. }
  1714. }
  1715. /*------------------------------------------------------------------------------*/
  1716. //the request is refuse for NetTalk is busy
  1717. void CCallDlg::Busy()
  1718. {
  1719. if(IsWindow(m_hWnd))
  1720. {
  1721. char szTxt[]="对方NetTalk繁忙,您的通话被拒绝";
  1722. SetDlgItemText(m_hWnd,IDC_TXT,szTxt);
  1723. ShowWindow(GetDlgItem(m_hWnd,IDC_OK),SW_SHOW);
  1724. }
  1725. }
  1726. /*------------------------------------------------------------------------------*/
  1727. //the implementation of credit dlg
  1728. LRESULT CCreditDlg::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1729. {
  1730. switch(uMsg)
  1731. {
  1732. case WM_CTLCOLORDLG :
  1733. return (LRESULT)GetStockObject(BLACK_BRUSH);
  1734. break;
  1735. //set the color the static ctrl
  1736. case WM_CTLCOLORSTATIC:
  1737. SetTextColor((HDC)wParam,0x00ffb093);
  1738. SetBkMode((HDC)wParam,TRANSPARENT);
  1739. return (LRESULT)GetStockObject(BLACK_BRUSH);
  1740. break;
  1741. default:
  1742. return CDialogX::WndProc(uMsg,wParam,lParam);
  1743. }
  1744. return TRUE;
  1745. }
  1746. /*------------------------------------------------------------------------------*/
  1747. BOOL CCreditDlg::Create(HWND hParent)
  1748. {
  1749. return CDialogX::Create((LPCTSTR)IDD_CREDITDLG,hParent);
  1750. }