WinSocket楂樼骇瀹炵幇锛堣亰澶╁鐨勫疄鐜帮級锛堜竴锛
鍙戝竷: 2008-6-26 12:24 | 浣滆: admin | 鏌ョ湅: 166娆
銆銆涓婃鐨勬枃绔犳垜缁欏ぇ瀹剁畝鍗曠殑浠嬬粛浜嗕竴涓媁inSocket鐨勪娇鐢ㄦ柟娉曪紝鐩镐俊澶у宸茬粡瀵瑰畠浜х敓浜嗕竴瀹氱殑鍏磋叮锛屾帴涓嬫潵鎴戜細甯﹂澶у杩涘叆缃戠粶缂栫▼鐨勪笘鐣岋紝浠婂ぉ鎴戜細閫愭鐨勭粰澶у璁茶В濡備綍鍒╃敤WinSocket瀹炵幇涓涓綉缁滆亰澶╁銆傛濡傚ぇ澶氭暟鑱婂ぉ瀹や竴鏍凤紝鎴戜滑闇瑕佷竴涓亰澶╂湇鍔″櫒瀹冨彲浠ュ拰寰堝瀹㈡埛绔繘琛岄氫俊锛屼粠鑰屽疄鐜版妸鏉ヨ嚜涓嶅悓鐨勫鎴风殑鑱婂ぉ淇℃伅杞氦鍒版墍鏈夊叾浠栫殑瀹㈡埛绔傝繖鏍峰氨褰㈡垚涓涓噰鐢–/S缁撴瀯鐨勫彲浠ュ浜哄悓鏃跺湪绾跨殑鑱婂ぉ瀹ゃ備粖澶╂垜浠氨鍒╃敤涓婃鏂囩珷涓殑鐭ヨ瘑鏉ュ疄鐜板畠銆傦紙杩欓噷鎴戜滑闇瑕佷綘鏈変竴浜沄C鐨凪FC鐭ヨ瘑锛屾渶濂藉彲浠ヤ細缂栦竴浜涚畝鍗曠殑绐楀彛绋嬪簭锛屽綋鐒舵垜涔熶細灏藉彲鑳界殑璁茬殑鍏蜂綋涓浜涖傦級
鎴戜滑鍏堟潵鍋氫竴涓鎴风銆
棣栧厛鍚姩VC锛屽埄鐢∕FC AppWizard[EXE]寤虹珛涓涓柊鐨凪FC绋嬪簭锛屽彇鍚嶄负ChatRoom锛屽湪MFC AppWizard Step 1鐨勬椂鍊欐垜浠夋嫨Dialog based锛屽湪Step 2鏃舵垜浠竴瀹氳閫夋嫨涓奧indows Sockets閫夐」锛屽垏璁帮紒鍒囪锛佷箣鍚庣殑鍑犳鎴戜滑灏卞彲浠ヤ娇鐢ㄩ粯璁ゅ间簡銆

鎴戜滑瑕佸仛鐨勫鎴风鍒嗕负涓や釜绐楀彛锛屼竴涓槸鐧婚檰绐楀彛锛岄渶瑕佷綘杈撳叆涓浜涚櫥闄嗕俊鎭紝鍙﹀灏辨槸鑱婂ぉ涓荤獥鍙c傚涓嬪浘锛


鐩镐俊杩欎袱涓獥鍙d笉闅惧缓绔嬪惂锛熷叾涓偅涓亰澶╀富绐楀彛鏄▼搴忕敓鎴愮殑鏃跺欒嚜宸卞缓绔嬬殑锛岃岄偅涓櫥闄嗙獥鍙f槸鍚庢坊杩涘幓鐨勶紝涓轰簡鍙互鍦ㄤ富绐楀彛鍑虹幇涔嬪墠鍚姩鍏堝惎鍔ㄧ櫥闄嗙獥鍙o紝鎴戜滑闇瑕佸湪CChatRoomApp::InitInstance涓洿鏀逛唬鐮併傦紙鍏朵腑鎴戜滑涓虹櫥闄嗙獥鍙e缓绔嬬殑绫诲彨ConnectDlg锛
BOOL CChatRoomApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_IN99v_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CClientSocket *tmpSocket;
CConnectDlg *cdlg;
CChatRoomDlg *dlg;
int nResponse,cnResponse=IDOK,endFlage=1;
tmpSocket=new CClientSocket;
cdlg=new CConnectDlg(tmpSocket);
cnResponse=cdlg->DoModal();
if (cnResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
delete tmpSocket;
delete cdlg;
return FALSE;
}
else
{
delete cdlg;
}
dlg=new CChatRoomDlg(tmpSocket);
tmpSocket->SetDlg(dlg);
nResponse = dlg->DoModal();
m_pMainWnd = dlg;
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
if (tmpSocket) tmpSocket->Close();
tmpSocket->myDlg=NULL;
delete tmpSocket;
tmpSocket=NULL;
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
if (tmpSocket) tmpSocket->Close();
delete tmpSocket;
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}




发表于 2009-1-5 19:48
| 











