• <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>
            隨筆 - 25  文章 - 29  trackbacks - 0
            <2006年7月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            常用鏈接

            留言簿(4)

            隨筆分類(22)

            隨筆檔案(25)

            文章分類(2)

            文章檔案(2)

            相冊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 57006
            • 排名 - 405

            最新評論

            閱讀排行榜

            評論排行榜

            The Problem

            Windows objects are normally represented by HANDLEs. The MFC classes wrap Windows object handles with C++ objects. The handle wrapping functions of the MFC class library provide a way to find the C++ object that is wrapping the Windows object with a particular handle. There are times when a Windows object does not have a C++ wrapper object, however, and at these times a temporary object is created to act as the C++ wrapper.

            mfc 映射的 windows object ---->c++ wrapper
            以下使用 mfc 的函數 如:fromhandle, getdlgitem,都會返回temporary 和 pemanent? c++ wrapper object
            ?注意:
            ???? 零時的 對象 會被在空閑時(OnIdle()函數)被刪除,不能存下在下次消息處理中 使用
            The default OnIdle processing in CWinThread automatically calls DeleteTempMap for each class that supports temporary handle maps
            ////////////////////////////////////////////////////////////
            The Windows objects that use handle maps are:

            • HWND (CWnd and CWnd-derived classes)
            • HDC (CDC and CDC-derived classes)
            • HMENU (CMenu)
            • HPEN (CGdiObject)
            • HBRUSH (CGdiObject)
            • HFONT (CGdiObject)
            • HBITMAP (CGdiObject)
            • HPALETTE (CGdiObject)
            • HRGN (CGdiObject)
            • HIMAGELIST (CImageList)
            • SOCKET (CSocket)

            ///////////////////////////////////////////////

            Given a handle to any of these objects, you can find the MFC object that wraps the handle by calling the static member function FromHandle. For example, given an HWND called hWnd:

            CWnd::FromHandle(hWnd)

            will return a pointer to the CWnd that wraps the hWnd. If that hWnd does not have a specific wrapper object, then a temporary CWnd is created to wrap the hWnd. This makes it possible to get a valid C++ object from any handle.

            Once you have a wrapper object, you can get to its handle through a public member variable. In the case of a CWnd, m_hWnd contains the HWND for that object.

            Attaching Handles to MFC Objects

            Given a newly created handle-wrapper object and a handle to a Windows object, you can associate the two by calling Attach. For example:

            CWnd myWnd;
            myWnd.Attach(hWnd);
            ////mywnd 析構時會調用 destroywindow ,連同 hwnd 一起銷毀




            This makes an entry in the permanent map associating myWnd and hWnd.
            Calling CWnd::FromHandle(hWnd) will now return a pointer to myWnd.
            When myWnd is deleted, the destructor will automatically destroy the hWnd by calling the Windows DestroyWindow function. If this is not desired, the hWnd must be detached from myWnd before the myWnd object is destroyed (normally when leaving the scope at which myWnd was defined). The Detach member function does this.

            myWnd.Detach();

            More About Temporary Objects

            Temporary objects are created whenever FromHandle is given a handle that does not already have a wrapper object. These temporary objects are detached from their handle and deleted by the DeleteTempMap functions. The default OnIdle processing in CWinThread automatically calls DeleteTempMap for each class that supports temporary handle maps. This means that you cannot assume a pointer to a temporary object will be valid past the point of exit from the function where the pointer was obtained, as the temporary object will be deleted during the Windows message-loop idle time.

            很重要:
            在多線程中傳遞 c++ wrapper object 是無效的(無論是 temporary 還是 permanent)
            只能傳遞 windows handle, 換句話就是說, 線程 只能 訪問 自己創建的c++ wrapper object

            Wrapper Objects and Multiple Threads

            Both temporary and permanent objects are maintained on a per-thread basis. That is, one thread cannot access another threads C++ wrapper objects, regardless of whether it is temporary or permanent. As stated above, temporary objects are deleted when the thread which that temporary object belongs enters OnIdle.

            To pass these objects from one thread to another, always send them as their native HANDLE type. Passing a C++ wrapper object from one thread to another will often result in unexpected results.

            ????

            posted on 2006-06-30 11:33 黃大仙 閱讀(1724) 評論(1)  編輯 收藏 引用 所屬分類: c++

            FeedBack:
            # re: MFC中 windows object 和 C++ object 2006-07-08 00:49 flyingxu
            精品无码久久久久国产动漫3d| 色偷偷偷久久伊人大杳蕉| 丰满少妇人妻久久久久久| 久久亚洲私人国产精品| 久久精品一区二区国产| 久久九九久精品国产免费直播| 久久久久亚洲?V成人无码| 一本一本久久a久久综合精品蜜桃| 亚洲va久久久噜噜噜久久男同| 精品多毛少妇人妻AV免费久久| 区久久AAA片69亚洲| 国产精品久久亚洲不卡动漫| 人妻无码久久精品| 久久综合狠狠综合久久激情 | 久久久久久国产精品无码下载| 中文精品99久久国产| 91精品观看91久久久久久| 麻豆精品久久久久久久99蜜桃| 国产精品久久久久影视不卡| 波多野结衣久久一区二区| 狠狠人妻久久久久久综合| 国产精品视频久久久| 精品国产乱码久久久久软件| 亚洲精品NV久久久久久久久久| 精品国产福利久久久| 狠狠88综合久久久久综合网| 99久久综合国产精品免费| 亚洲国产成人精品女人久久久| 一级做a爰片久久毛片16| 精品国产乱码久久久久久1区2区| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 国产午夜电影久久| 国产精品欧美久久久天天影视| 久久久久亚洲精品无码蜜桃| 久久久久久久精品成人热色戒| 久久综合九色欧美综合狠狠| 国产高潮国产高潮久久久91 | 99999久久久久久亚洲| 精品久久久久香蕉网| 99麻豆久久久国产精品免费| 久久国产高潮流白浆免费观看|