锘??xml version="1.0" encoding="utf-8" standalone="yes"?> http://www.shnenglu.com/Files/flyingxu/ThinkinginCppExercise.rar
http://www.codediscuss.com
]]>
鎴戣寰楄鐨勫緢娓呮錛屽懙鍛?img src ="http://www.shnenglu.com/flyingxu/aggbug/17275.html" width = "1" height = "1" />
]]>
(鏈獙璇侊紝鍙兘涓嶅叏錛屾垨鑰呮牴鏈氨涓嶆槸絳旀)
]]>
涓嬮潰鐨勪唬鐮侊紝褰撶敤AfxBeginThread寮濮嬩竴涓嚎紼嬫椂錛屽疄闄呬笂鏄湁鍐呭瓨娉勬紡鐨?/p>
Q : | MFC榪斿洖鐨勪復(fù)鏃跺璞℃寚閽堟垚鍥? | ||
涓昏瑙g瓟鑰? | QunKangLi | 鎻愪氦浜? | QunKangLi |
鎰熻阿: | oldforest銆亂u_hl銆丵unKangLi | ||
瀹℃牳鑰? | happyparrot | 紺懼尯瀵瑰簲璐村瓙: | 鏌ョ湅 |
聽聽聽聽 A : | |||
msdn鍦ㄤ粙緇岹etDlgItem鐨勬椂鍊欙紝鏄庣‘鎸囧嚭錛?聽 The 聽returned 聽pointer 聽may 聽be 聽temporary 聽and 聽should 聽not 聽be 聽stored 聽for 聽later 聽use. 聽 濡傛灉鐪熸槸榪欐牱閭f垜涓嶆儴浜嗭紒鍦ㄦ垜鐨勪竴涓蔣浠朵腑錛屽洜涓哄父甯歌浣垮垏鎹㈡寜閽殑鍙敤涓庝笉鍙敤浠ュ強鏀瑰彉鎸夐挳鏂囧瓧錛屾墍浠ユ垜鐢―etDlgItem鎶婂畠浠瓨浜嗚搗鏉ワ紝鐢ㄧ殑鏃跺欑洿鎺ュ埌鏁扮粍閲岄潰鍙栵紝榪欐牱鐨勮瘽榪欎釜杞歡涓嶆槸鐘簡涓涓噸澶х殑閿欒浜嗭紵鍙槸鐢ㄨ繖涔堜箙涔熸病鍑洪敊銆?聽 鍙﹀錛屽畠涔熸槸璇村彲鑳芥槸涓存椂鐨勶紝閭d竴瀹氬湪鏌愮鎯呭喌涓嬩笉鏄復(fù)鏃剁殑錛岄珮鎵嬭兘涓嶈兘瑙i噴涓涓嬭繖涓棶棰橈紵 聽 --------------------------------------------------------------- 聽 // 聽 聽Most 聽Windows 聽objects 聽are 聽represented 聽with 聽a 聽HANDLE, 聽including 聽 // 聽 聽 聽 聽 聽 聽the 聽most 聽important 聽ones, 聽HWND, 聽HDC, 聽HPEN, 聽HFONT 聽etc. 聽 // 聽 聽We 聽want 聽C++ 聽objects 聽to 聽wrap 聽these 聽handle 聽based 聽objects 聽whenever 聽we 聽can. 聽 // 聽 聽Since 聽Windows 聽objects 聽can 聽be 聽created 聽outside 聽of 聽C++ 聽(eg: 聽calling 聽 // 聽 聽 聽 聽 聽 聽::CreateWindow 聽will 聽return 聽an 聽HWND 聽with 聽no 聽C++ 聽wrapper) 聽we 聽must 聽 // 聽 聽 聽 聽 聽 聽support 聽a 聽reasonably 聽uniform 聽mapping 聽from 聽permanent 聽handles 聽 // 聽 聽 聽 聽 聽 聽(i.e. 聽the 聽ones 聽allocated 聽in 聽C++) 聽and 聽temporary 聽handles 聽(i.e. 聽 // 聽 聽 聽 聽 聽 聽the 聽ones 聽allocated 聽in 聽C, 聽but 聽passed 聽through 聽a 聽C++ 聽interface. 聽 // 聽 聽We 聽keep 聽two 聽dictionaries 聽for 聽this 聽purpose. 聽 聽The 聽permanent 聽dictionary 聽 // 聽 聽 聽 聽 聽 聽stores 聽those 聽C++ 聽objects 聽that 聽have 聽been 聽explicitly 聽created 聽by 聽 // 聽 聽 聽 聽 聽 聽the 聽developer. 聽 聽The 聽C++ 聽constructor 聽for 聽the 聽wrapper 聽class 聽will 聽 // 聽 聽 聽 聽 聽 聽insert 聽the 聽mapping 聽into 聽the 聽permanent 聽dictionary 聽and 聽the 聽C++ 聽 // 聽 聽 聽 聽 聽 聽destructor 聽will 聽remove 聽it 聽and 聽possibly 聽free 聽up 聽the 聽associated 聽 // 聽 聽 聽 聽 聽 聽Windows 聽object. 聽 // 聽 聽When 聽a 聽handle 聽passes 聽through 聽a 聽C++ 聽interface 聽that 聽doesn't 聽exist 聽in 聽 // 聽 聽 聽 聽 聽 聽the 聽permanent 聽dictionary, 聽we 聽allocate 聽a 聽temporary 聽wrapping 聽object 聽 // 聽 聽 聽 聽 聽 聽and 聽store 聽that 聽mapping 聽into 聽the 聽temporary 聽dictionary. 聽 // 聽 聽At 聽idle 聽time 聽the 聽temporary 聽wrapping 聽objects 聽are 聽flushed 聽(since 聽you 聽better 聽 // 聽 聽 聽 聽 聽 聽not 聽be 聽holding 聽onto 聽something 聽you 聽didn't 聽create). 聽 // 聽 聽 聽 鍦–WinThread::OnIdle閲岃皟鐢ˋfxUnlockTempMaps錛孉fxUnlockTempMaps浼?xì)閲婃斁temporary 聽maps. 聽 聽 鎵浠ヤ笉瑕佷繚鐣橤etDlgItem絳夎繑鍥炵殑涓存椂鎸囬拡錛屽彲浠ョ洿鎺ヤ繚瀛楬WND 聽objects錛岀劧鍚嶤Wnd::FromHandle鑾峰彇涓存椂鎸囬拡鏉ョ敤銆?聽 聽 --------------------------------------------------------------- 聽 聽 涓存椂鍖呰瀵硅薄浼?xì)鍦ńI洪棽鏃墮棿鍒犻櫎.鍦ㄥ悓涓鍑芥暟涓嬈′嬌鐢ㄦ槸娌$敤闂鐨?涓嶅悓鍑芥暟涓嬌鐢ㄥ厛鍓嶄繚瀛樹笅鏉ョ殑鎸囬拡灝辨湁鍙兘鍑洪敊,鐗瑰埆鏄璇濇鍒濅嬌鍖栨椂鍊欏瓨涓嬫潵鐨勬寚閽? 聽 聽 聽 聽 聽鍦∕FC灞傛涓婄殑鍑芥暟浣跨敤CWnd瀵硅薄,鑰屾湰鍦癢indows浠g爜(API)浣跨敤鍙ユ焺.濡?褰揥indows緋葷粺璋冪敤涓涓獥鍙h繃紼嬫椂灝嗕紶閫掍竴涓狧WND鍙傛暟,鑰孧FC鏈韓鐨勬秷鎭満鍒朵嬌鐢–Wnd綾?涓轟簡鏇村ソ鏇撮珮鏁堢殑瀹炵幇,MFC闇瑕佷笌Windows緋葷粺鍚堜綔,灝嗗彞鏌勪笌CWnd瀵硅薄榪涜鍏寵仈---瀹冪敤CHandleMap瀹屾垚鍏寵仈. 聽 CHandleMap鏈変袱涓狢MapPtrToPtr鐨勬垚鍛樺彉閲?m_permanentMap(姘鎬箙鏄犲皠琛?紼嬪簭榪愯榪囩▼涓璞?鍙ユ焺涔嬮棿鐨勫叧緋?,m_temporaryMap(涓存椂鏄犲皠琛?鍦ㄦ秷鎭瓨鍦ㄧ殑榪囩▼涓墠瀛樺湪).姘鎬箙琛ㄤ繚瀛樻樉寮忓垱寤虹殑CWnd瀵硅薄,褰撳璞″垱寤烘椂灝嗗湪姘鎬箙鐩綍涓嬫彃鍏ヤ竴涓潯鐩?鍦–Wnd::OnNcDestrory鏃跺垹闄ゅ搴旀潯鐩?浣嗘槸Windows鏈夋椂浼?xì)浼犲叆鏌愪簺涓嶆槸鐢卞紑鍙戜漢鍛樻樉寮忓垱寤虹殑紿楀彛鐨勫彞鏌?姝ゆ椂MFC浼?xì)鍒嗛厤涓涓復(fù)鏃跺璞℃潵鍖呰榪欎釜鍙ユ焺騫跺皢瀹冧滑鐨勬槧灝勪繚瀛樺埌涓存椂鏄犲皠琛ㄤ腑,榪欎簺涓存椂瀵硅薄浼?xì)鍦ńI洪棽鏃墮棿琚垹闄ゅ茍縐昏蛋鐩稿簲鐨勪復(fù)鏃舵槧灝勮〃鏉$洰.綾諱技鐨凪FC瀵硅薄涓嶹indows鍙ユ焺鐨勬槧灝勮〃鏈? 聽 m_pmapHWND: 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽紿楀彛鍙ユ焺涓嶤Wnd瀵硅薄 聽 m_pampHMENU: 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽鑿滃崟鍙ユ焺涓嶤Menu瀵硅薄 聽 m_pmapHDC: 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽璁懼鐜鍙ユ焺涓嶤DC瀵硅薄 聽 m_pmapHGDIOBJ: 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽GDI鍙ユ焺涓嶤GDI瀵硅薄 聽 m_mapHIMAGELIST: 聽聽 聽聽 聽聽 聽聽鍥懼儚閾捐〃鍙ユ焺鍒癈ImageList瀵硅薄 聽 聽 褰撶粰瀹氬彞鏌?濡侶WND鏃?MFC綆鍗曡皟鐢–Wnd* 聽PASCAL 聽CWnd::FromHandle(HWND 聽hWnd), 聽姝ゅ嚱鏁板唴閮ㄤ嬌鐢–HandleMap::FromHandle(hWnd)鑾峰彇鐩稿叧鑱旂殑CWnd瀵硅薄.鍦–HandleMap::FromHandle(h)鍐呴儴(婧愪唬鐮佸湪WinHand.cpp),鍏堜嬌鐢–Object* 聽pObject 聽= 聽LookupPermanent(h); 聽聽 聽聽 聽聽 聽聽if 聽(pObject 聽!= 聽NULL)return 聽pObject; 聽 聽媯鏌ユ案涔呰〃;濡傛案涔呰〃涓笉瀛樺湪,浣跨敤pObject 聽= 聽LookupTemporary(h)) 聽!= 聽NULL媯鏌ヤ復(fù)鏃惰〃,閮戒笉瀛樺湪鏃?浣跨敤pTemp 聽= 聽= 聽m_pClass->CreateObject();if 聽(pTemp 聽== 聽NULL)AfxThrowMemoryException();m_temporaryMap.SetAt((LPVOID)h, 聽pTemp);鍒涘緩涓存椂瀵硅薄騫跺皢鍏舵彃鍏ュ埌涓存椂琛ㄤ腑鍘?鍚屾椂榪斿洖璇ヤ復(fù)鏃跺璞? 聽 void 聽CHandleMap::RemoveHandle(HANDLE 聽h)鐨勬敞閲婅鏄庝復(fù)鏃跺璞″皢鍦ㄧ┖闂叉椂鐢監(jiān)nIdel閲婃斁: 聽 聽聽 聽聽 聽聽 聽聽// 聽remove 聽only 聽from 聽permanent 聽map 聽-- 聽temporary 聽objects 聽are 聽removed 聽 聽聽 聽聽 聽聽 聽聽// 聽 聽at 聽idle 聽in 聽CHandleMap::DeleteTemp, 聽always! 聽 濡傛灉鎯充笉鑷姩閲婃斁涓存椂瀵硅薄,浣跨敤void 聽AFXAPI 聽AfxLockTempMaps()/BOOL 聽AFXAPI 聽AfxUnlockTempMaps(BOOL 聽bDeleteTemps)榪涜閿佸畾. 聽 |