• <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>

            C++ Programmer's Cookbook

            {C++ 基礎(chǔ)} {C++ 高級} {C#界面,C++核心算法} {設(shè)計模式} {C#基礎(chǔ)}

            微軟C++標(biāo)準(zhǔn)(事件實例)

            一 微軟C++標(biāo)準(zhǔn)關(guān)鍵字(包括標(biāo)準(zhǔn)C++,托管C++,微軟擴(kuò)展C++,C++/CLI)

            __abstract?2

            abstract

            __alignof Operator

            array

            __asm

            __assume

            __based

            bool

            __box?2

            break

            case

            catch

            __cdecl

            char

            class

            const

            const_cast

            continue

            __declspec

            default

            __delegate 2

            delegate

            delete

            deprecated 1

            dllexport 1

            dllimport 1

            do

            double

            dynamic_cast

            else

            enum

            enum class

            enum struct

            event

            __event

            __except

            explicit

            extern

            false

            __fastcall

            __finally

            finally

            float

            for

            for each, in

            __forceinline

            friend

            friend_as

            __gc?2

            gcnew

            generic

            goto

            __hook?3

            __identifier

            if

            __if_exists

            __if_not_exists

            initonly

            __inline

            inline

            int

            __int8

            __int16

            __int32

            __int64

            __interface

            interface class

            interface struct

            interior_ptr

            __leave

            literal

            long

            __m64

            __m128

            __m128d

            __m128i

            __multiple_inheritance

            mutable

            naked 1

            namespace

            new

            new

            __nogc?2

            noinline 1

            __noop

            noreturn 1

            nothrow 1

            novtable 1

            nullptr

            operator

            __pin?2

            private

            __property?2

            property

            property 1

            protected

            public

            __raise

            ref struct

            ref class

            register

            reinterpret_cast

            return

            safecast

            __sealed?2

            sealed

            selectany 1

            short

            signed

            __single_inheritance

            sizeof

            static

            static_cast

            __stdcall

            struct

            __super

            switch

            template

            this

            thread 1

            throw

            true

            try

            __try/__except, __try/__finally

            __try_cast?2

            typedef

            typeid

            typeid

            typename

            __unaligned

            __unhook?3

            union

            unsigned

            using declaration, using directive

            uuid 1

            __uuidof

            value struct

            value class

            __value?2

            virtual

            __virtual_inheritance

            void

            volatile

            __w64

            __wchar_t, wchar_t

            ?while


            注釋:
            0)??? 一般關(guān)鍵字前面加雙下劃線的表示微軟的擴(kuò)展,也有沒有加的啊
            1)? 關(guān)鍵字后面有1的表示:__declspec 關(guān)鍵字的擴(kuò)展屬性
            2) 關(guān)鍵字后面有2的表示:是以前的托管C++的擴(kuò)展
            3) 關(guān)鍵字后面有3的表示:是事件處理中使用的屬性,在非托管C++中也可以使用

            4)VS6.0只支持非托管C++,VS2002,VS2003還支持托管C++,最新的VS2005中還增加了對C++/CLI的支持。
            5)VS IDE中通過 /Za 可以控制使用微軟擴(kuò)展或只使用標(biāo)準(zhǔn)C++.

            二 幾個常用的微軟擴(kuò)展關(guān)鍵字實例

            1)在非托管C++中使用__raise__event
            //?EventHandlingRef_raise.cpp
            struct?E?{
            ???__event?
            void?func1();
            ???
            void?func1(int)?{}

            ???
            void?func2()?{}

            ???
            void?b()?{
            ??????__raise?func1();
            ??????__raise?func1(
            1);??//?C3745:?'int?Event::bar(int)':?
            ?????????????????????????
            //?only?an?event?can?be?'raised'
            ??????__raise?func2();???//?C3745
            ???}

            }
            ;

            int?main()?{
            ???E?e;
            ???__raise?e.func1();
            ???__raise?e.func1(
            1);??//?C3745
            ???__raise?e.func2();???//?C3745
            }


            2)在非托管C++中使用__hook__unhook?
            //?evh_native.cpp
            #include?<stdio.h>

            [event_source(native)]
            class?CSource?{
            public:
            ???__event?
            void?MyEvent(int?nValue);
            }
            ;

            [event_receiver(native)]
            class?CReceiver?{
            public:
            ???
            void?MyHandler1(int?nValue)?{
            ??????printf_s(
            "MyHandler1?was?called?with?value?%d.\n",?nValue);
            ???}


            ???
            void?MyHandler2(int?nValue)?{
            ??????printf_s(
            "MyHandler2?was?called?with?value?%d.\n",?nValue);
            ???}


            ???
            void?hookEvent(CSource*?pSource)?{
            ??????__hook(
            &CSource::MyEvent,?pSource,?&CReceiver::MyHandler1);
            ??????__hook(
            &CSource::MyEvent,?pSource,?&CReceiver::MyHandler2);
            ???}


            ???
            void?unhookEvent(CSource*?pSource)?{
            ??????__unhook(
            &CSource::MyEvent,?pSource,?&CReceiver::MyHandler1);
            ??????__unhook(
            &CSource::MyEvent,?pSource,?&CReceiver::MyHandler2);
            ???}

            }
            ;

            int?main()?{
            ???CSource?source;
            ???CReceiver?receiver;

            ???receiver.hookEvent(
            &source);
            ???__raise?source.MyEvent(
            123);
            ???receiver.unhookEvent(
            &source);
            }


            3)在托管C++中使用__Delegate(VS2005中使用/CLR:: oldsytax)

            //?keyword__delegate.cpp
            //?compile?with:?/clr
            #using?<mscorlib.dll>
            using?namespace?System;

            __delegate?
            int?GetDayOfWeek();
            __gc?
            class?MyCalendar
            {
            public:
            ???MyCalendar()?:?m_nDayOfWeek(
            4)?{}
            ???
            int?MyGetDayOfWeek()?{?Console::WriteLine("handler");?return?m_nDayOfWeek;?}
            ???
            static?int?MyStaticGetDayOfWeek()?{?Console::WriteLine("static?handler");?return?6;?}
            private:
            ???
            int?m_nDayOfWeek;
            }
            ;

            int?main?()
            {
            ???GetDayOfWeek?
            *?pGetDayOfWeek;??//?declare?delegate?type
            ???int?nDayOfWeek;
            ???
            ???
            //?bind?delegate?to?static?method
            ???pGetDayOfWeek?=?new?GetDayOfWeek(0,?&MyCalendar::MyStaticGetDayOfWeek);
            ???nDayOfWeek?
            =?pGetDayOfWeek->Invoke();
            ???Console::WriteLine(nDayOfWeek);

            ???
            //?bind?delegate?to?instance?method
            ???MyCalendar?*?pcal?=?new?MyCalendar();
            ???pGetDayOfWeek?
            =?static_cast<GetDayOfWeek*>(Delegate::Combine(pGetDayOfWeek,
            ??????
            new?GetDayOfWeek(pcal,?&MyCalendar::MyGetDayOfWeek)));
            ???nDayOfWeek?
            =?pGetDayOfWeek->Invoke();
            ???Console::WriteLine(nDayOfWeek);

            ???
            //?delegate?now?bound?to?two?methods;?remove?instance?method
            ???pGetDayOfWeek?=?static_cast<GetDayOfWeek*>(Delegate::Remove(pGetDayOfWeek,
            ??????
            new?GetDayOfWeek(pcal,?&MyCalendar::MyGetDayOfWeek)));
            ???
            return?0;
            }


            4)在C++/CLI中使用Event,Delegate (VS2005 IDE 中使用/CLR)

            //?mcppv2_events.cpp
            //?compile?with:?/clr
            using?namespace?System;

            //?declare?delegates
            delegate?void?ClickEventHandler(int,?double);
            delegate?void?DblClickEventHandler(String^);

            //?class?that?defines?events
            ref?class?EventSource?{
            public:
            ???
            event?ClickEventHandler^?OnClick;???//?declare?the?event?OnClick
            ???event?DblClickEventHandler^?OnDblClick;???//?declare?OnDblClick

            ???
            void?FireEvents()?{
            ??????
            //?raises?events
            ??????OnClick(7,?3.14159);
            ??????OnDblClick(
            "Hello");
            ???}

            }
            ;

            //?class?that?defines?methods?that?will?called?when?event?occurs
            ref?class?EventReceiver?{
            public:
            ???
            void?OnMyClick(int?i,?double?d)?{
            ??????Console::WriteLine(
            "OnClick:?{0},?{1}",?i,?d);
            ???}


            ???
            void?OnMyDblClick(String^?str)?{
            ??????Console::WriteLine(
            "OnDblClick:?{0}",?str);
            ???}

            }
            ;

            int?main()?{
            ???EventSource?
            ^?MyEventSource?=?gcnew?EventSource();
            ???EventReceiver
            ^?MyEventReceiver?=?gcnew?EventReceiver();

            ???
            //?hook?handler?to?event
            ???MyEventSource->OnClick?+=?gcnew?ClickEventHandler(MyEventReceiver,?&EventReceiver::OnMyClick);
            ???MyEventSource
            ->OnDblClick?+=?gcnew?DblClickEventHandler(MyEventReceiver,?&EventReceiver::OnMyDblClick);

            ???
            //?invoke?events
            ???MyEventSource->FireEvents();

            ???
            //?unhook?handler?to?event
            ???MyEventSource->OnClick?-=?gcnew?ClickEventHandler(MyEventReceiver,?&EventReceiver::OnMyClick);
            ???MyEventSource
            ->OnDblClick?-=?gcnew?DblClickEventHandler(MyEventReceiver,?&EventReceiver::OnMyDblClick);
            }


            三 在VS2002,VS2003中我們可以使用托管C++(Managed C++),但是最新的VS2005中,我們可以直接在C++中使用.NET FrameWork ,這個就是最新的C++標(biāo)準(zhǔn)C++/CLI,已經(jīng)通過了相關(guān)組織的標(biāo)準(zhǔn)化。

            posted on 2006-11-25 17:38 夢在天涯 閱讀(5621) 評論(3)  編輯 收藏 引用 所屬分類: CPlusPlusMFC/QT

            評論

            # re: 微軟C++標(biāo)準(zhǔn)(事件實例) 2006-11-28 08:50 erran

            托管C++怎么看怎么不順眼.....  回復(fù)  更多評論   

            # re: 微軟C++標(biāo)準(zhǔn)(事件實例) 2006-11-30 17:10 yimudi

            這是一畝地網(wǎng)站(yimudi.cn)給您的留言!
            祝賀您榮登一畝地中文Blog排行榜。在我們收錄的700多萬博客中目前您的排名是330名。您可以訪問一畝地網(wǎng)站查看有關(guān)您博客的詳細(xì)信息,通過搜索博客(輸入您的博客名稱、用戶名或者直接輸入您博客的網(wǎng)址URL)就可以快速找到您自己的博客信息主頁。
            一畝地中文Blog排行榜是目前中文博客中最權(quán)威的博客綜合排行指標(biāo),注冊一畝地,您將得到更多貼心服務(wù),一畝地隨時歡迎您的光臨。
            博客中間只有一畝地!
              回復(fù)  更多評論   

            # re: 微軟C++標(biāo)準(zhǔn)(事件實例) 2006-12-07 14:52 gql

            我對微軟唯一的微詞是他企圖另立C++標(biāo)準(zhǔn)~  回復(fù)  更多評論   

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804159
            • 排名 - 5

            最新評論

            閱讀排行榜

            久久丫忘忧草产品| 亚洲精品乱码久久久久久久久久久久 | 色青青草原桃花久久综合| 99精品国产在热久久| 久久99国内精品自在现线| 亚洲成色WWW久久网站| 77777亚洲午夜久久多喷| 伊人久久大香线蕉AV一区二区| 久久无码一区二区三区少妇| 精品久久久久久久久久中文字幕| 精品久久久无码中文字幕| 久久精品无码一区二区日韩AV| 国产成人精品久久| 色婷婷久久综合中文久久一本| 久久久精品久久久久久| 久久久这里有精品中文字幕| 久久综合鬼色88久久精品综合自在自线噜噜| 久久无码AV中文出轨人妻| 一本色道久久88综合日韩精品| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 伊人色综合久久天天网| 久久久久高潮综合影院| 久久综合狠狠综合久久综合88| 国产综合久久久久| 国产精品嫩草影院久久| 中文成人无码精品久久久不卡| 亚洲欧美日韩久久精品第一区| 日韩人妻无码精品久久免费一| 久久se精品一区二区| 久久精品中文字幕第23页| 国产精品乱码久久久久久软件| 婷婷久久久亚洲欧洲日产国码AV| 精品无码久久久久久午夜| 久久综合九色综合欧美狠狠| 无码人妻久久一区二区三区蜜桃 | 久久人人爽人人爽人人爽 | 亚洲国产成人久久精品影视| 久久久久久国产a免费观看不卡 | 久久婷婷五月综合色高清| 26uuu久久五月天| 久久久久波多野结衣高潮|