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

            Error

            C++博客 首頁 新隨筆 聯系 聚合 管理
              217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks
            最近被安排UI工作有點多,公司的控件用不順手,也有用DUILIB的,但是問了公司的幾個人說和MFC一起用的時候有這樣那樣的問題。
            今天手癢實驗了下直接在CDLG里邊用DUILIB(我不想直接用duilib了事,后期可能會做做大改動,所以沒有直接在duilib::CWindowWnd里邊想辦法)
            發現唯一需要注意的就是需要在OnPaint中屏蔽CDialog的paint,,,duilib還是很牛逼的
            同樣,把duilib整合成MFC的“插件”之后,那個CWindowWnd::Close會自動delete this的故障也沒了,額,應該說是特性,不是故障,,,不過這個特性給我帶來的麻煩比較多,,,
             

            // dui_mfcDlg.h : header file
            //

            #pragma once



            // Cdui_mfcDlg dialog
            class Cdui_mfcDlg : public CDialog
                , 
            public DuiLib::INotifyUI, public DuiLib::IMessageFilterUI
            {
            // Construction
            public:
                Cdui_mfcDlg(CWnd
            * pParent = NULL);    // standard constructor

            // Dialog Data
                enum { IDD = IDD_DUI_MFC_DIALOG };

                
            protected:
                
            virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


            // Implementation
            protected:
                HICON m_hIcon;

                
            // Generated message map functions
                virtual BOOL OnInitDialog();
                afx_msg 
            void OnSysCommand(UINT nID, LPARAM lParam);
                afx_msg 
            void OnPaint();
                afx_msg HCURSOR OnQueryDragIcon();
                DECLARE_MESSAGE_MAP()

            private:
                
            bool OnHChanged(void* param) {
                    DuiLib::TNotifyUI
            * pMsg = (DuiLib::TNotifyUI*)param;
                    
            if( pMsg->sType == _T("valuechanged") ) {
                        
            short H, S, L;
                        DuiLib::CPaintManagerUI::GetHSL(
            &H, &S, &L);
                        DuiLib::CPaintManagerUI::SetHSL(
            true, (static_cast<DuiLib::CSliderUI*>(pMsg->pSender))->GetValue(), S, L);
                    }

                    
            return true;
                }


                
            bool OnSChanged(void* param) {
                    DuiLib::TNotifyUI
            * pMsg = (DuiLib::TNotifyUI*)param;
                    
            if( pMsg->sType == _T("valuechanged") ) {
                        
            short H, S, L;
                        DuiLib::CPaintManagerUI::GetHSL(
            &H, &S, &L);
                        DuiLib::CPaintManagerUI::SetHSL(
            true, H, (static_cast<DuiLib::CSliderUI*>(pMsg->pSender))->GetValue(), L);
                    }

                    
            return true;
                }


                
            bool OnLChanged(void* param) {
                    DuiLib::TNotifyUI
            * pMsg = (DuiLib::TNotifyUI*)param;
                    
            if( pMsg->sType == _T("valuechanged") ) {
                        
            short H, S, L;
                        DuiLib::CPaintManagerUI::GetHSL(
            &H, &S, &L);
                        DuiLib::CPaintManagerUI::SetHSL(
            true, H, S, (static_cast<DuiLib::CSliderUI*>(pMsg->pSender))->GetValue());
                    }

                    
            return true;
                }


                
            bool OnAlphaChanged(void* param) {
                    DuiLib::TNotifyUI
            * pMsg = (DuiLib::TNotifyUI*)param;
                    
            if( pMsg->sType == _T("valuechanged") ) {
                        m_pm.SetTransparent((static_cast
            <DuiLib::CSliderUI*>(pMsg->pSender))->GetValue());
                    }

                    
            return true;
                }


                
            void OnPrepare() 
                
            {
                    DuiLib::CSliderUI
            * pSilder = static_cast<DuiLib::CSliderUI*>(m_pm.FindControl(_T("alpha_controlor")));
                    
            if( pSilder ) pSilder->OnNotify += MakeDelegate(this&Cdui_mfcDlg::OnAlphaChanged);
                    pSilder 
            = static_cast<DuiLib::CSliderUI*>(m_pm.FindControl(_T("h_controlor")));
                    
            if( pSilder ) pSilder->OnNotify += MakeDelegate(this&Cdui_mfcDlg::OnHChanged);
                    pSilder 
            = static_cast<DuiLib::CSliderUI*>(m_pm.FindControl(_T("s_controlor")));
                    
            if( pSilder ) pSilder->OnNotify += MakeDelegate(this&Cdui_mfcDlg::OnSChanged);
                    pSilder 
            = static_cast<DuiLib::CSliderUI*>(m_pm.FindControl(_T("l_controlor")));
                    
            if( pSilder ) pSilder->OnNotify += MakeDelegate(this&Cdui_mfcDlg::OnLChanged);
                }


            private:
                DuiLib::CPaintManagerUI m_pm;

                
            // INotifyUI
            public:
                
            virtual void Notify(DuiLib::TNotifyUI& msg);

                
            // IMessageFilterUI 
            public:
                
            virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
                
            virtual BOOL PreTranslateMessage(MSG* pMsg);
                afx_msg 
            int OnCreate(LPCREATESTRUCT lpCreateStruct);
            }
            ;



            // dui_mfcDlg.cpp : implementation file
            //

            #include "stdafx.h"
            #include "dui_mfc.h"
            #include "dui_mfcDlg.h"

            #ifdef _DEBUG
            #define new DEBUG_NEW
            #endif


            // CAboutDlg dialog used for App About

            class CAboutDlg : public CDialog
            {
            public:
             CAboutDlg();

            // Dialog Data
             enum { IDD = IDD_ABOUTBOX };

             protected:
             virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

            // Implementation
            protected:
             DECLARE_MESSAGE_MAP()
            };

            CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
            {
            }

            void CAboutDlg::DoDataExchange(CDataExchange* pDX)
            {
             CDialog::DoDataExchange(pDX);
            }

            BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
            END_MESSAGE_MAP()


            // Cdui_mfcDlg dialog

             


            Cdui_mfcDlg::Cdui_mfcDlg(CWnd* pParent /*=NULL*/)
             : CDialog(Cdui_mfcDlg::IDD, pParent)
            {
             m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
            }

            void Cdui_mfcDlg::DoDataExchange(CDataExchange* pDX)
            {
             CDialog::DoDataExchange(pDX);
            }

            BEGIN_MESSAGE_MAP(Cdui_mfcDlg, CDialog)
             ON_WM_SYSCOMMAND()
             ON_WM_PAINT()
             ON_WM_QUERYDRAGICON()
             //}}AFX_MSG_MAP
                ON_WM_CREATE()
            END_MESSAGE_MAP()


            // Cdui_mfcDlg message handlers

            BOOL Cdui_mfcDlg::OnInitDialog()
            {
             CDialog::OnInitDialog();

             // Add "About..." menu item to system menu.

             // IDM_ABOUTBOX must be in the system command range.
             ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
             ASSERT(IDM_ABOUTBOX < 0xF000);

             CMenu* pSysMenu = GetSystemMenu(FALSE);
             if (pSysMenu != NULL)
             {
              BOOL bNameValid;
              CString strAboutMenu;
              bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
              ASSERT(bNameValid);
              if (!strAboutMenu.IsEmpty())
              {
               pSysMenu->AppendMenu(MF_SEPARATOR);
               pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
              }
             }

             // Set the icon for this dialog.  The framework does this automatically
             //  when the application's main window is not a dialog
             SetIcon(m_hIcon, TRUE);   // Set big icon
             SetIcon(m_hIcon, FALSE);  // Set small icon

             // TODO: Add extra initialization here

             return TRUE;  // return TRUE  unless you set the focus to a control
            }

            void Cdui_mfcDlg::OnSysCommand(UINT nID, LPARAM lParam)
            {
             if ((nID & 0xFFF0) == IDM_ABOUTBOX)
             {
              CAboutDlg dlgAbout;
              dlgAbout.DoModal();
             }
             else
             {
              CDialog::OnSysCommand(nID, lParam);
             }
            }

            // If you add a minimize button to your dialog, you will need the code below
            //  to draw the icon.  For MFC applications using the document/view model,
            //  this is automatically done for you by the framework.

            void Cdui_mfcDlg::OnPaint()
            {
             if (IsIconic())
             {
              CPaintDC dc(this); // device context for painting

              SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

              // Center icon in client rectangle
              int cxIcon = GetSystemMetrics(SM_CXICON);
              int cyIcon = GetSystemMetrics(SM_CYICON);
              CRect rect;
              GetClientRect(&rect);
              int x = (rect.Width() - cxIcon + 1) / 2;
              int y = (rect.Height() - cyIcon + 1) / 2;

              // Draw the icon
              dc.DrawIcon(x, y, m_hIcon);
             }
             else
             {
              //CDialog::OnPaint();
             }
            }

            // The system calls this function to obtain the cursor to display while the user drags
            //  the minimized window.
            HCURSOR Cdui_mfcDlg::OnQueryDragIcon()
            {
             return static_cast<HCURSOR>(m_hIcon);
            }


            void Cdui_mfcDlg::Notify(DuiLib::TNotifyUI& msg)
            {
                if( msg.sType == _T("windowinit") ) OnPrepare();
                else if( msg.sType == _T("click") ) {
                    if( msg.pSender->GetName() == _T("insertimagebtn") ) {
                        DuiLib::CRichEditUI* pRich = static_cast<DuiLib::CRichEditUI*>(m_pm.FindControl(_T("testrichedit")));
                        if( pRich ) {
                            pRich->RemoveAll();
                        }
                    }
                    else if( msg.pSender->GetName() == _T("changeskinbtn") ) {
                        if( DuiLib::CPaintManagerUI::GetResourcePath() == DuiLib::CPaintManagerUI::GetInstancePath() )
                            DuiLib::CPaintManagerUI::SetResourcePath(DuiLib::CPaintManagerUI::GetInstancePath() + _T("skin\\FlashRes"));
                        else
                            DuiLib::CPaintManagerUI::SetResourcePath(DuiLib::CPaintManagerUI::GetInstancePath());
                        DuiLib::CPaintManagerUI::ReloadSkin();
                    }
                }
            }

            LRESULT Cdui_mfcDlg::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
            {
                if( uMsg == WM_ERASEBKGND )
                {
                    return true;
                }

                return false;
            }
            BOOL Cdui_mfcDlg::PreTranslateMessage(MSG* pMsg)
            {
                // TODO: Add your specialized code here and/or call the base class
                bool bHandled = false;
                MessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, bHandled);
                if (bHandled)
                {
                    return true;
                }
                else
                {
                    LRESULT lresult = 0;
                    if (m_pm.MessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lresult))
                    {
                        return lresult;
                    }
                }

                return __super::PreTranslateMessage(pMsg);
            }

            int Cdui_mfcDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
            {
                if (__super::OnCreate(lpCreateStruct) == -1)
                    return -1;

                // TODO:  Add your specialized creation code here
                m_pm.Init(m_hWnd);
                DuiLib::CDialogBuilder builder;
                DuiLib::CControlUI* pRoot = builder.Create(_T("test1.xml"), (UINT)0, NULL, &m_pm);
                ASSERT(pRoot && "Failed to parse XML");
                m_pm.AttachDialog(pRoot);
                m_pm.AddNotifier(this);

                return 0;
            }






            posted on 2013-05-28 23:42 Enic 閱讀(8272) 評論(1)  編輯 收藏 引用 所屬分類: Duilib

            評論

            # re: Duilib在MFC中使用[未登錄] 2013-11-19 00:05 王小亮
            學習了。。  回復  更多評論
              

            亚洲综合久久久| 国产韩国精品一区二区三区久久| 国产成人无码精品久久久久免费| 久久e热在这里只有国产中文精品99 | 四虎久久影院| 久久久久99精品成人片试看| 一本色道久久88加勒比—综合| 三级韩国一区久久二区综合| 久久精品人人做人人爽电影蜜月 | 久久久久久噜噜精品免费直播| 欧美精品丝袜久久久中文字幕| 亚洲午夜久久久影院伊人| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久综合久久综合九色| 伊人久久亚洲综合影院| 久久中文娱乐网| 久久一日本道色综合久久| 日韩欧美亚洲国产精品字幕久久久 | 久久99中文字幕久久| 久久99九九国产免费看小说| 国产成人无码精品久久久免费| 久久水蜜桃亚洲av无码精品麻豆| 久久精品综合一区二区三区| 国产精品久久网| 久久免费的精品国产V∧| 日本亚洲色大成网站WWW久久| 777米奇久久最新地址| 久久丫精品国产亚洲av不卡 | 久久国产精品无码一区二区三区| 一级女性全黄久久生活片免费 | 久久99热只有频精品8| 人妻无码中文久久久久专区 | 91精品国产91久久久久久青草| 亚洲综合日韩久久成人AV| 中文成人久久久久影院免费观看| 国产精品一区二区久久精品无码 | 香蕉久久永久视频| 欧美午夜A∨大片久久 | 国产成人无码精品久久久性色 | 久久久久免费视频| 久久本道综合久久伊人|