• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            love in C++, live on MFC

            to get ready...

            C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              47 Posts :: 0 Stories :: 97 Comments :: 0 Trackbacks

            置頂隨筆 #

            我的新博客在

            http://www.codediscuss.com
               文章指數(shù):0  CSDN Blog推出文章指數(shù)概念,文章指數(shù)是對(duì)Blog文章綜合評(píng)分后推算出的,綜合評(píng)分項(xiàng)分別是該文章的點(diǎn)擊量,回復(fù)次數(shù),被網(wǎng)摘收錄數(shù)量,文章長(zhǎng)度和文章類(lèi)型;滿(mǎn)分100,每月更新一次。
            http://www.codediscuss.com 是我的博客的新地址。還是以VC++編程為主,有mfc,英語(yǔ),還有點(diǎn)點(diǎn)shareware的內(nèi)容。
            posted @ 2007-10-02 14:23 flyingxu 閱讀(1379) | 評(píng)論 (2)編輯 收藏

            2007年10月2日 #

            我的新博客在

            http://www.codediscuss.com
               文章指數(shù):0  CSDN Blog推出文章指數(shù)概念,文章指數(shù)是對(duì)Blog文章綜合評(píng)分后推算出的,綜合評(píng)分項(xiàng)分別是該文章的點(diǎn)擊量,回復(fù)次數(shù),被網(wǎng)摘收錄數(shù)量,文章長(zhǎng)度和文章類(lèi)型;滿(mǎn)分100,每月更新一次。
            http://www.codediscuss.com 是我的博客的新地址。還是以VC++編程為主,有mfc,英語(yǔ),還有點(diǎn)點(diǎn)shareware的內(nèi)容。
            posted @ 2007-10-02 14:23 flyingxu 閱讀(1379) | 評(píng)論 (2)編輯 收藏

            2007年1月5日 #

            關(guān)于幾個(gè)HTML文檔接口的使用探討
            http://www.vckbase.com/vckbase/vckbase10/vc/nonctrls/atlcomocx_02/1002005.htm

            我覺(jué)得講的很清楚,呵呵
            posted @ 2007-01-05 00:14 flyingxu 閱讀(3798) | 評(píng)論 (0)編輯 收藏

            2006年8月9日 #

            這個(gè)答案本來(lái)是作者賣(mài)錢(qián)的,我忘了是從那個(gè)網(wǎng)站下載的了,估計(jì)不全。
            現(xiàn)在有人要,就放上來(lái)吧

            http://m.shnenglu.com/Files/flyingxu/ThinkinginCppExercise.rar

            (未驗(yàn)證,可能不全,或者根本就不是答案)

            posted @ 2006-08-09 00:19 flyingxu 閱讀(3699) | 評(píng)論 (1)編輯 收藏

            2006年7月26日 #

            類(lèi)似的問(wèn)題見(jiàn)http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20084406.html

            下面的代碼,當(dāng)用AfxBeginThread開(kāi)始一個(gè)線(xiàn)程時(shí),實(shí)際上是有內(nèi)存泄漏的

            for ?(ii? = ? 0 ;?ii? < ? 1000 ;?ii ++ )?
            {
            ??CWinThread?
            *
            pWinThread;?
            ??pWinThread?
            =
            ?AfxBeginThread(ThreadLBProc,?NULL);
            ??::Sleep(
            500
            );
            }

            UINT?ThreadLBProc(LPVOID?pParam)
            {
            ??
            return ? 0
            ;
            }

            VC輸出的典型提示為:
            Detected memory leaks!
            Dumping objects ->
            thrdcore.cpp(166) : {782} client block at 0x00425300, subtype 0, 112 bytes long.
            實(shí)際上,只要看到是thrdcore.cpp(166) 的內(nèi)存泄漏,基本就是同一個(gè)原因,和上面的代碼一樣。
            解決方法:
            step 1)
            在線(xiàn)程函數(shù)中,記得寫(xiě)AfxEndThread();(與AfxBeginThread對(duì)應(yīng),其他的開(kāi)始線(xiàn)程的函數(shù),有相應(yīng)的函數(shù))
            step 2)
            用::WaitForSingleObject()確保線(xiàn)程徹底退出

            step 2是比較容易忽略的,用sleep函數(shù)只能僥幸的保證線(xiàn)程退出,但不能確保。
            posted @ 2006-07-26 19:11 flyingxu 閱讀(3454) | 評(píng)論 (3)編輯 收藏

            2006年7月13日 #

            用VC調(diào)試程序,只要按下F12,程序就出錯(cuò)了,出錯(cuò)的代碼還很奇怪,再PeekMessage中,但是只出現(xiàn)在調(diào)試(按F5),不出現(xiàn)在全速運(yùn)行(Ctrl+F5),release版本也沒(méi)有問(wèn)題
            網(wǎng)上的解答:
            http://support.microsoft.com/kb/q130667/?F12居然就是這么定義的,ft

            所以,在定義程序功能的時(shí)候,就盡量不要用到F12 ,哈
            posted @ 2006-07-13 18:29 flyingxu 閱讀(2001) | 評(píng)論 (0)編輯 收藏

            2006年7月11日 #

            我在ms的group上問(wèn)了個(gè)問(wèn)題http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&tid=402a414c-a125-45bd-9cf4-c1819db7e3e4
            in?http://msdn2.microsoft.com/en-us/library/480b7kf7.aspx,?it?says?that?
            pGdiObject->DeleteTempMap()
            ;??//?Causes?compiler?error

            But?I'm?confused?for?a?static?member?can?be?called?by?the?object?or?a?pointer.
            Is?there?anything?wrong?of?my?understanding?

            回答的人到蠻多,討論的也很熱烈,但都沒(méi)有直接回答我的問(wèn)題,我的問(wèn)題是,對(duì)于靜態(tài)函數(shù),
            pGdiObject->DeleteTempMap();??//?Causes?compiler?error,
            到底對(duì)不對(duì)?如果不對(duì),就是msdn錯(cuò)了,不過(guò)總覺(jué)得比較奇怪,msdn不該出這樣的錯(cuò)的
            posted @ 2006-07-11 19:14 flyingxu 閱讀(1339) | 評(píng)論 (3)編輯 收藏

            2006年7月10日 #

            csdn上難得的好文章,怕不爭(zhēng)氣的csdn網(wǎng)站過(guò)幾天又找不到這篇文章了,我得先轉(zhuǎn)一下,保存一下:
            http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=193097

            Q : MFC返回的臨時(shí)對(duì)象指針成因?
            主要解答者: QunKangLi 提交人: QunKangLi
            感謝: oldforest、yu_hl、QunKangLi
            審核者: happyparrot 社區(qū)對(duì)應(yīng)貼子: 查看
            ???? A :

            msdn在介紹GetDlgItem的時(shí)候,明確指出: ?
            The ?returned ?pointer ?may ?be ?temporary ?and ?should ?not ?be ?stored ?for ?later ?use. ?
            如果真是這樣那我不慘了!在我的一個(gè)軟件中,因?yàn)槌3R骨袚Q按鈕的可用與不可用以及改變按鈕文字,所以我用DetDlgItem把它們存了起來(lái),用的時(shí)候直接到數(shù)組里面取,這樣的話(huà)這個(gè)軟件不是犯了一個(gè)重大的錯(cuò)誤了?可是用這么久也沒(méi)出錯(cuò)。 ?
            另外,它也是說(shuō)可能是臨時(shí)的,那一定在某種情況下不是臨時(shí)的,高手能不能解釋一下這個(gè)問(wèn)題? ?
            --------------------------------------------------------------- ?
            // ? ?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). ?
            // ?
            ?
            ?
            在CWinThread::OnIdle里調(diào)用AfxUnlockTempMaps,AfxUnlockTempMaps會(huì)釋放temporary ?maps. ?
            ?
            所以不要保留GetDlgItem等返回的臨時(shí)指針,可以直接保存HWND ?objects,然后CWnd::FromHandle獲取臨時(shí)指針來(lái)用。 ?
            ?
            --------------------------------------------------------------- ?
            ?
            臨時(shí)包裝對(duì)象會(huì)在空閑時(shí)間刪除.在同一函數(shù)中多次使用是沒(méi)用問(wèn)題的,不同函數(shù)中使用先前保存下來(lái)的指針就有可能出錯(cuò),特別是對(duì)話(huà)框初使化時(shí)候存下來(lái)的指針. ?
            ? ? ? ?在MFC層次上的函數(shù)使用CWnd對(duì)象,而本地Windows代碼(API)使用句柄.如:當(dāng)Windows系統(tǒng)調(diào)用一個(gè)窗口過(guò)程時(shí)將傳遞一個(gè)HWND參數(shù),而MFC本身的消息機(jī)制使用CWnd類(lèi);為了更好更高效的實(shí)現(xiàn),MFC需要與Windows系統(tǒng)合作,將句柄與CWnd對(duì)象進(jìn)行關(guān)聯(lián)---它用CHandleMap完成關(guān)聯(lián). ?
            CHandleMap有兩個(gè)CMapPtrToPtr的成員變量:m_permanentMap(永久映射表,程序運(yùn)行過(guò)程中對(duì)象/句柄之間的關(guān)系),m_temporaryMap(臨時(shí)映射表,在消息存在的過(guò)程中才存在).永久表保存顯式創(chuàng)建的CWnd對(duì)象,當(dāng)對(duì)象創(chuàng)建時(shí)將在永久目錄下插入一個(gè)條目,在CWnd::OnNcDestrory時(shí)刪除對(duì)應(yīng)條目.但是Windows有時(shí)會(huì)傳入某些不是由開(kāi)發(fā)人員顯式創(chuàng)建的窗口的句柄,此時(shí)MFC會(huì)分配一個(gè)臨時(shí)對(duì)象來(lái)包裝這個(gè)句柄并將它們的映射保存到臨時(shí)映射表中,這些臨時(shí)對(duì)象會(huì)在空閑時(shí)間被刪除并移走相應(yīng)的臨時(shí)映射表?xiàng)l目.類(lèi)似的MFC對(duì)象與Windows句柄的映射表有: ?
            m_pmapHWND: ?? ?? ?? ?? ?? ?? ?? ??窗口句柄與CWnd對(duì)象 ?
            m_pampHMENU: ?? ?? ?? ?? ?? ?? ?? ??菜單句柄與CMenu對(duì)象 ?
            m_pmapHDC: ?? ?? ?? ?? ?? ?? ?? ??設(shè)備環(huán)境句柄與CDC對(duì)象 ?
            m_pmapHGDIOBJ: ?? ?? ?? ?? ?? ?? ?? ??GDI句柄與CGDI對(duì)象 ?
            m_mapHIMAGELIST: ?? ?? ?? ??圖像鏈表句柄到CImageList對(duì)象 ?
            ?
            當(dāng)給定句柄,如HWND時(shí),MFC簡(jiǎn)單調(diào)用CWnd* ?PASCAL ?CWnd::FromHandle(HWND ?hWnd), ?此函數(shù)內(nèi)部使用CHandleMap::FromHandle(hWnd)獲取相關(guān)聯(lián)的CWnd對(duì)象.在CHandleMap::FromHandle(h)內(nèi)部(源代碼在WinHand.cpp),先使用CObject* ?pObject ?= ?LookupPermanent(h); ?? ?? ?? ??if ?(pObject ?!= ?NULL)return ?pObject; ? ?檢查永久表;如永久表中不存在,使用pObject ?= ?LookupTemporary(h)) ?!= ?NULL檢查臨時(shí)表,都不存在時(shí),使用pTemp ?= ?= ?m_pClass->CreateObject();if ?(pTemp ?== ?NULL)AfxThrowMemoryException();m_temporaryMap.SetAt((LPVOID)h, ?pTemp);創(chuàng)建臨時(shí)對(duì)象并將其插入到臨時(shí)表中去,同時(shí)返回該臨時(shí)對(duì)象. ?
            void ?CHandleMap::RemoveHandle(HANDLE ?h)的注釋說(shuō)明臨時(shí)對(duì)象將在空閑時(shí)由OnIdel釋放: ?
            ?? ?? ?? ??// ?remove ?only ?from ?permanent ?map ?-- ?temporary ?objects ?are ?removed ?
            ?? ?? ?? ??// ? ?at ?idle ?in ?CHandleMap::DeleteTemp, ?always! ?
            如果想不自動(dòng)釋放臨時(shí)對(duì)象,使用void ?AFXAPI ?AfxLockTempMaps()/BOOL ?AFXAPI ?AfxUnlockTempMaps(BOOL ?bDeleteTemps)進(jìn)行鎖定. ?



            posted @ 2006-07-10 23:18 flyingxu 閱讀(1734) | 評(píng)論 (1)編輯 收藏

            2006年7月9日 #

            在mfc的group上有這樣一個(gè)問(wèn)題:(http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&sloc=en-us
            I?need?to?update?one?class?data?and?the?view?during?the?idle,?I?used?this??
            method?
            in?the?Cdoc:
            void?CMyAppDoc::OnIdle(){

            ????theClass
            ->
            Update();
            ????POSITION?pos?
            =
            ?GetFirstViewPosition();
            ????CView
            *?pView?=
            ?GetNextView(pos);
            ????pView
            ->Invalidate(true
            );
            ????pView
            ->
            UpdateWindow();????
            }


            It?works?only?when?I?move?the?mouse,?what
            's?wrong??Z_Z
            這個(gè)問(wèn)題的確比較搞,要好好看mfc源碼的,下面是我的回答
            Nothing is wrong, I can explain it? is by design.
            Please take a look at the source code of int CWinThread::Run(), in that function, IsIdleMessage() is called, and in IsIdleMessage() WM_PAINT is ignored, which means WM_PAINT will not cause OnIdle to be called, for windows think it's just a WM_PAINT message and will not change the UI.
            Your UpdateWindow() only post a WM_PAINT message, the message queue is not empty but it's ignored by IsIdleMessage(), that's why.
            But when you move your mouse, the message queue is filled with some WM_MOUSEMOVE and it's not ignored for the position changes. So your OnIdle() is called again.
            -
            My suggestion is to move your Invalidate & UpdateWindow code to somewhere else.
            OnIdle()的確是個(gè)有點(diǎn)復(fù)雜的問(wèn)題,我可能還會(huì)寫(xiě)幾篇文章 :)
            這里(http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&q=AfxUnlockTempMaps&rnum=40&hl=zh-CN#66b6e5949a31bfa2)有篇文章講的很到位
            posted @ 2006-07-09 02:03 flyingxu 閱讀(1440) | 評(píng)論 (1)編輯 收藏

            2006年7月6日 #

            調(diào)試程序的時(shí)候,一般
            1)啟動(dòng)調(diào)試器,比如VC
            2)在VC中設(shè)斷點(diǎn)
            3)操作程序,使得程序運(yùn)行到斷點(diǎn),停下來(lái)
            但是現(xiàn)在我遇到一個(gè)情況,希望調(diào)試的情景是這樣的:雙擊某個(gè)文件,我的程序啟動(dòng)后,這個(gè)時(shí)候我想程序停下來(lái),讓我在VC中調(diào)試它。
            但是,雙擊文件后啟動(dòng)的程序,是個(gè)獨(dú)立的exe運(yùn)行程序,肯定不是在VC的運(yùn)行控制下的,VC中設(shè)置的斷點(diǎn)不起作用的。怎么辦呢?
            這個(gè)時(shí)候可以在想讓程序停下來(lái)的地方增加指令_asm int 3,debug下編譯好。雙擊文件后運(yùn)行這個(gè)exe,在exe運(yùn)行到_asm int 3時(shí),就會(huì)中斷,而把當(dāng)前的exe運(yùn)行與一個(gè)新的調(diào)試器(一個(gè)新的VC進(jìn)程)結(jié)合起來(lái)。接下來(lái)就像一般的調(diào)試了。
            這時(shí)的調(diào)試步驟類(lèi)似與:
            1)程序運(yùn)行
            2)遇到特定條件時(shí),_asm int 3把當(dāng)前exe與一個(gè)新的調(diào)試器,比如一個(gè)新的VC進(jìn)程,聯(lián)系起來(lái)
            3)在調(diào)試器中調(diào)試exe

            :)
            posted @ 2006-07-06 17:35 flyingxu 閱讀(5921) | 評(píng)論 (10)編輯 收藏

            2006年6月23日 #

            C++編程規(guī)范中第23條中說(shuō):
            If one header file won't work unless the file that includes it also includes another header, that's gauche and puts unnecessary burden on that header file's users.
            呵呵,英語(yǔ)有點(diǎn)拗口,后面舉的例子也都是模板的例子。我倒是遇到過(guò)一個(gè)實(shí)際的例子,簡(jiǎn)化后如下:
            //a.h
            class?A?
            {
            ?
            int
            ?a;
            };
            ?
            //b.h
            //注意:b.h并沒(méi)有include?a.h
            class?B?
            {
            ?A?a;
            };
            ?
            用的時(shí)候怎么用呢?比如在main.cpp中想用class B
            //main.cpp
            #include?"a.h"
            #include?
            "b.h"
            //
            B?b;
            //

            //do?something?on?b
            可以看到,main為了使用B,還得包含a.h,這就是上面一段英語(yǔ)說(shuō)的:
            如果一個(gè)頭文件(b.h)不能工作,除非包含它(b.h)的文件(也就是main.cpp)也包含另一個(gè)頭文件(a.h)...

            hehe,當(dāng)我第一次遇到這種情況時(shí),想了半天也想不明白為什么我明明包含了b.h還是不能用B啊

            那么,正確的寫(xiě)法應(yīng)該是什么呢?
            在類(lèi)B的作者在設(shè)計(jì)B的時(shí)候,就應(yīng)該想到用戶(hù)只需要#include "b.h"就可以使用這個(gè)class B。所以,在b.h文件中,應(yīng)該寫(xiě)明#include "a.h",而不是讓用戶(hù)在main.cpp中去include "a.h"

            :)
            posted @ 2006-06-23 20:56 flyingxu 閱讀(1790) | 評(píng)論 (5)編輯 收藏

            僅列出標(biāo)題  下一頁(yè)
            久久久网中文字幕| 久久中文娱乐网| 国内精品久久久久影院网站| 久久亚洲AV成人无码国产| 亚洲性久久久影院| 久久精品中文字幕第23页| 国产精品狼人久久久久影院| 亚洲狠狠综合久久| 久久精品国产半推半就| 久久免费高清视频| 国产999精品久久久久久| 久久99久久无码毛片一区二区| 国产成人香蕉久久久久| 久久久不卡国产精品一区二区| 精品久久久久久无码国产| 久久一区二区免费播放| 亚洲精品NV久久久久久久久久| 亚洲伊人久久综合中文成人网| 国产99久久久国产精品小说 | 久久久久久久久66精品片| 午夜精品久久久内射近拍高清| 亚洲精品高清一二区久久| 中文字幕久久久久人妻| 久久人人爽人人爽人人AV东京热 | 久久99精品国产99久久| 91精品国产91久久久久久蜜臀| 久久精品三级视频| 亚洲国产精品成人久久| 2021久久国自产拍精品| 久久国产福利免费| 丁香色欲久久久久久综合网| 精品久久久久久久久中文字幕| 国产精品美女久久久免费| 久久精品国产99国产精品亚洲| 99久久人妻无码精品系列蜜桃| 亚洲国产天堂久久综合| 精品久久一区二区| 77777亚洲午夜久久多喷| 9999国产精品欧美久久久久久| 国产aⅴ激情无码久久| 久久无码人妻精品一区二区三区 |