• <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>
            隨筆-341  評(píng)論-2670  文章-0  trackbacks-0
                今天我給GacUI添加了一個(gè)新Demo。我發(fā)現(xiàn)寫Demo也是一個(gè)測(cè)試的過程,可以用來檢驗(yàn)類庫(kù)提供的API是否夠完整。前面這兩個(gè)Demo都促使我往類庫(kù)里面加入了新的函數(shù)。這次的Demo是用Label控件來模仿超鏈接。下載最新代碼之后,可以在“Libraries\GacUI\GacUIDemo\GacUIDemo.sln”下面找到最新的Demo代碼。

                為了模仿超鏈接,我們要做兩件事情。第一件事情就是鼠標(biāo)懸浮在Label上的時(shí)候需要顯示出手的光標(biāo)圖,第二件事情就是在鼠標(biāo)進(jìn)入Label的時(shí)候顯示下劃線,離開的時(shí)候去掉下劃線。因此我們需要監(jiān)聽三個(gè)事件,分別是MouseEnter,MouseLeave和LeftButtonDown。下面是Demo的圖:

                上圖:鼠標(biāo)在Label外。下圖:鼠標(biāo)在Label內(nèi)。單擊Label的時(shí)候會(huì)打開瀏覽器。



                代碼如下:

            #include "..\..\Public\Source\GacUIIncludes.h"
            #include 
            <Windows.h>

            int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
            {
                
            return SetupWindowsDirect2DRenderer();
            }

            class HyperlinkWindow : public GuiWindow
            {
            private:
                GuiLabel
            *                labelHyperlink;

                
            void labelHyperlink_OnMouseEnter(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    FontProperties font
            =labelHyperlink->GetFont();
                    font.underline
            =true;
                    labelHyperlink
            ->SetFont(font);
                }

                
            void labelHyperlink_OnMouseLeave(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    FontProperties font
            =labelHyperlink->GetFont();
                    font.underline
            =false;
                    labelHyperlink
            ->SetFont(font);
                }

                
            void labelHyperlink_OnLeftButtonDown(GuiGraphicsComposition* sender, GuiMouseEventArgs& arguments)
                {
                    ShellExecute(NULL, L
            "OPEN", L"http://m.shnenglu.com/vczh", NULL, NULL, SW_SHOWNORMAL);
                }
            public:
                HyperlinkWindow()
                    :GuiWindow(GetCurrentTheme()
            ->CreateWindowStyle())
                {
                    SetText(L
            "Controls.Label.Hyperlink");
                    SetClientSize(Size(
            300200));
                    MoveToScreenCenter();

                    labelHyperlink
            =g::NewLabel();
                    labelHyperlink
            ->SetText(L"http://m.shnenglu.com/vczh");
                    labelHyperlink
            ->SetTextColor(Color(00255));
                    {
                        FontProperties font;
                        font.fontFamily
            =L"Segoe UI";
                        font.size
            =18;
                        font.antialias
            =true;
                        labelHyperlink
            ->SetFont(font);
                    }
                    {
                        INativeCursor
            * hand=GetCurrentController()->ResourceService()->GetSystemCursor(INativeCursor::Hand);
                        labelHyperlink
            ->GetBoundsComposition()->SetAssociatedCursor(hand);
                    }
                    labelHyperlink
            ->GetEventReceiver()->mouseEnter.AttachMethod(this&HyperlinkWindow::labelHyperlink_OnMouseEnter);
                    labelHyperlink
            ->GetEventReceiver()->mouseLeave.AttachMethod(this&HyperlinkWindow::labelHyperlink_OnMouseLeave);
                    labelHyperlink
            ->GetEventReceiver()->leftButtonDown.AttachMethod(this&HyperlinkWindow::labelHyperlink_OnLeftButtonDown);
                    AddChild(labelHyperlink);
                }

                
            ~HyperlinkWindow()
                {
                }
            };

            void GuiMain()
            {
                GuiWindow
            * window=new HyperlinkWindow();
                GetApplication()
            ->Run(window);
                delete window;
            }

                這里展示的主要是監(jiān)聽事件的方法。在使用control->GetEventReceiver()->event的時(shí)候,可以使用Attach、AttachMethod、AttachFunction和AttachLambda。AttachLambda傳入一個(gè)functor,在C++11里面可以直接使用lambda表達(dá)式。在這里使用AttachMethod給一個(gè)事件綁定類成員函數(shù)。C++運(yùn)行類成員函數(shù)的時(shí)候,不僅需要參數(shù),還需要一個(gè)this對(duì)象,所以AttachMethod有兩個(gè)參數(shù),使用方法在Demo里面已經(jīng)展現(xiàn)出來了。

                在這里還引入了GetCurrentController函數(shù)。GetCurrentController返回的INativeController對(duì)象抽象了所有需要的操作系統(tǒng)的功能,其中獲得一個(gè)光標(biāo)的對(duì)象就封裝在了ResourceService里面。INativeController還包含了很多其他的Service,這個(gè)留在以后的Demo展示。
            posted on 2012-04-24 02:37 陳梓瀚(vczh) 閱讀(2126) 評(píng)論(8)  編輯 收藏 引用 所屬分類: GacUI

            評(píng)論:
            # re: GacUI Demo:使用Label控件模仿超鏈接 2012-04-24 06:27 | Zblc(邱震鈺)
            # re: GacUI Demo:使用Label控件模仿超鏈接 2012-04-24 23:05 | 嵌入式培訓(xùn)
            嗯,確實(shí)是  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:使用Label控件模仿超鏈接 2012-04-24 23:18 | 陳梓瀚(vczh)
            @cymheart
            其實(shí)我的架構(gòu)正是這么干的,就是api還沒有做到那一步。而且對(duì)于簡(jiǎn)單的情況,也要有簡(jiǎn)單的api可以用。這樣用起來才舒服。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:使用Label控件模仿超鏈接 2012-04-25 23:41 | cymheart
            暈,LZ怎么把我的評(píng)論刪了??  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:使用Label控件模仿超鏈接[未登錄] 2012-04-26 01:50 | 陳梓瀚(vczh)
            @cymheart
            cppblog出了bug他自己沒掉的  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:使用Label控件模仿超鏈接 2012-04-26 08:16 | CY
            正想說,直接把開發(fā)時(shí)的測(cè)試代碼拿來當(dāng)demo就搞定了~  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:使用Label控件模仿超鏈接 2012-04-26 18:45 | 陳梓瀚(vczh)
            @CY
            demo的作用是教學(xué),怎可隨便寫。  回復(fù)  更多評(píng)論
              
            爱做久久久久久| 久久91综合国产91久久精品| 国产成人精品久久亚洲| 久久国产精品二国产精品| 伊人久久大香线蕉精品不卡| 久久精品国产日本波多野结衣| 囯产极品美女高潮无套久久久 | 人妻精品久久久久中文字幕| 影音先锋女人AV鲁色资源网久久| 久久综合香蕉国产蜜臀AV| 99久久国产主播综合精品| 97精品依人久久久大香线蕉97 | 色综合久久综合网观看| 久久综合日本熟妇| 精品国产福利久久久| 亚洲七七久久精品中文国产| 精品久久久久久久| 一本久道久久综合狠狠爱| 久久久免费观成人影院| 99麻豆久久久国产精品免费| 免费观看成人久久网免费观看| 亚洲午夜无码AV毛片久久| 免费观看久久精彩视频| 亚洲va中文字幕无码久久| 欧美一级久久久久久久大片| 欧美一区二区精品久久| 97久久久久人妻精品专区| 久久精品亚洲AV久久久无码| 欧美日韩精品久久久久| 中文精品久久久久国产网址| 99久久久国产精品免费无卡顿 | 久久精品卫校国产小美女| 久久久久国产一区二区| 国产999精品久久久久久| 91精品国产综合久久四虎久久无码一级| 亚洲综合日韩久久成人AV| 久久久国产视频| 久久久精品国产| 亚洲中文字幕久久精品无码APP | 国产欧美久久一区二区| 狠狠88综合久久久久综合网|