;
帖子
3919 
精华
积分
11710 
鱼币
0 ¥ 
来自
大连 
在线时间
1858 小时 
注册时间
2007-6-11 
最后登录
2009-10-20 

贴图大师勋章新人进步勋章宣传大使勋章论坛元老勋章

3
发表于 2009-1-5 19:48 | 只看该作者
WinSocket楂樼骇瀹炵幇锛堣亰澶╁鐨勫疄鐜帮級锛堜竴锛 - 缂栫▼搴 - Powered by SupeSite

浣犵殑浣嶇疆锛缂栫▼搴 >> 璧勮 >> VC >> 閫氫俊缃戠粶 >> 璇︾粏鍐呭 鍦ㄧ嚎鎶曠ǹ

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;

}

鎵撳嵃 | 鏀惰棌姝ら〉 |  鎺ㄨ崘缁欏ソ鍙 | 涓炬姤
涓婁竴绡 涓嬩竴绡
 

璇勫垎锛0

鍙戣〃璇勮
鏌ョ湅鍏ㄩ儴鍥炲銆愬凡鏈0浣嶇綉鍙嬪彂琛ㄤ簡鐪嬫硶銆