<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      MFCPropertyGridCtrl控件使用詳解

      MFCPropertyGridCtrl是VC2008引入的控件,是MFC中功能比較搶到的控件之一。這篇博客將詳細(xì)介紹空間的使用,包括空間的屬性、方法、類的繼承、點擊、編輯、事件等,希望能有幫助。

      –官方手冊–

       

      • 1. MFCPropertyGridCtrl簡介
      • 2. MFCPropertyGridCtrl的屬性
      • 3. 更改表頭寬度
      • 4. 添加屬性和分組
        • 4.1 添加屬性
        • 4.2 添加下拉菜單
        • 4.3 添加顏色、文件、字體
        • 4.4 添加分組
      • 5. MFCPropertyGridCtrl控件的內(nèi)建函數(shù)
        • 5.1 控件的創(chuàng)建
        • 5.2 清除所有屬性
        • 5.3 刪除指定屬性
        • 5.4 依次刪除屬性
        • 5.5 數(shù)據(jù)讀寫
        • 5.6 設(shè)置為初始值
        • 5.7 讀取值、初值、名字、ID
        • 5.8 選擇設(shè)置值
      • 6. MFCPropertyGridPropery子類
      • 7. MFCPropertyGridCtrl獲取用戶輸入值
      • 8. MFCPropertyGridCtrl屬性改變事件

      1. MFCPropertyGridCtrl簡介

      MFCPropertyGridCtrl的外觀如下圖所示,主要由三部分組成:表頭、屬性、描述。對于屬性,可以進(jìn)行分組,每一組可以由多個不同屬性組成,可以接受(不局限于)一下幾項:顏色、字體、文件、選項等。

      2. MFCPropertyGridCtrl的屬性

      選中控件,F(xiàn)4插卡屬性,會彈出左邊的屬性窗口,可以簡單控制控件的一些外觀和行為:

      Description Rows Count 描述部分的行數(shù)
      Enable Description Area 是否啟用描述功能
      Enable Header 是否啟用表頭
      Notify 是否允許編輯
      Mark Modified Properties 是否著重顯示修改
      Use Alphabetic mode 啟用該模式將按字母排列,不分組

       

      3. 更改表頭寬度

      剛創(chuàng)建的空間,Property模式只有5pixel,我們需要添加一段代碼來改變Property的寬度,讓屬性能夠顯示正常。

      	HDITEM item;
      	item.cxy = 120;
      	item.mask = HDI_WIDTH;
      	m_properaty.GetHeaderCtrl().SetItem(0, new HDITEM(item));

      4. 添加屬性和分組

      4.1 添加屬性

      CMFCPropertyGridProperty pProp1 = new CMFCPropertyGridProperty(  
              _T("天朝適合生存嗎?"),    
              _T("51CTO不談?wù)?),    
              _T("這是描述部分"));     
         
      m_propertyGrid.AddProperty(pProp1);   

      4.2 添加下拉菜單

      CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(  
          _T("我是不是帥哥?"),    
          _T("看選項"),   
          _T(""));   
        
      pProp2->AddOption(_T("是"));   
      pProp2->AddOption(_T("肯定是"));   
      pProp2->AddOption(_T("絕對是"));   
      pProp2->AllowEdit(FALSE);  //不允許對選項進(jìn)行編輯  
        
      m_propertyGrid.AddProperty(pProp2);

      4.3 添加顏色、文件、字體

      CMFCPropertyGridColorProperty * pProp3 = new CMFCPropertyGridColorProperty(   
          _T("顏色"), RGB(0, 111, 200));   
      m_propertyGrid.AddProperty(pProp3);   
        
      CMFCPropertyGridFileProperty * pProp4 = new CMFCPropertyGridFileProperty(  
          _T("打開文件"), TRUE, _T("D://test.txt"));   
      m_propertyGrid.AddProperty(pProp4);   
        
      LOGFONT font = {NULL};   
        
      CMFCPropertyGridFontProperty * pProp5 = new CMFCPropertyGridFontProperty(  
          _T("選擇字體"), font);   
        
      m_propertyGrid.AddProperty(pProp5);

      4.4 添加分組

      CMFCPropertyGridProperty * group1 = new CMFCPropertyGridProperty(_T("分組1"));   
      CMFCPropertyGridProperty * group2 = new CMFCPropertyGridProperty(_T("分組2"));   
        
      group1->AddSubItem(pProp1);   
      group1->AddSubItem(pProp2);   
      group2->AddSubItem(pProp3);   
      group2->AddSubItem(pProp4);   
      group2->AddSubItem(pProp5);   
        
      m_propertyGrid.AddProperty(group1);   
      m_propertyGrid.AddProperty(group2);  

      5. MFCPropertyGridCtrl控件的內(nèi)建函數(shù)

      5.1 控件的創(chuàng)建

      CMFCPropertyGridCtrl * propertyGrid = new CMFCPropertyGridCtrl;   
      propertyGrid->Create(WS_CHILD | WS_BORDER | WS_VISIBLE, CRect(400, 100, 600, 200), this, WM_USER + 100);   
      propertyGrid->EnableHeaderCtrl(TRUE);  //使用表頭   
      propertyGrid->SetVSDotNetLook();  //使用樣式   
      propertyGrid->MarkModifiedProperties(); //著重顯示更改過的部分

      5.2 清除所有屬性

      相當(dāng)與控件復(fù)位

      m_properaty.RemoveAll();

      5.3 刪除指定屬性

      CMFCPropertyGridProperty *pDelete;
      int iCount=m_propertyGrid.GetPropertyCount();
      if (iCount>0)
      {
          pDelete=m_propertyGrid.GetProperty(0);
          m_propertyGrid.DeleteProperty(pDelete);
      }

      5.4 依次刪除屬性

      int iCount=m_propertyGrid.GetPropertyCount();
      CMFCPropertyGridProperty *pDelete;
      for (int i=iCount-1;i>=0;i--)
      {
          pDelete=m_propertyGrid.GetProperty(i);
          m_propertyGrid.DeleteProperty(pDelete);
      }

      5.5 數(shù)據(jù)讀寫

      //讀:         
                      CMFCPropertyGridProperty *pSelected;
      		pSelected=m_propertyGrid.GetProperty(2)->GetSubItem(0);
      		COleVariant var=pSelected->GetValue();
                      float f1=var.fltVal;
      //寫:         
                      pSelected->SetValue(var);

      5.6 設(shè)置為初始值

      pProp->ResetOriginalValue();

      5.7 讀取值、初值、名字、ID

      GetData得到的值常常作為屬性編號,用來區(qū)分控件

      	CMFCPropertyGridProperty* pProp = (CMFCPropertyGridProperty*)lParam;
      	int i = (int)pProp->GetData();
      	CString s = pProp->GetName();
      	COleVariant t = pProp->GetValue();
      	t = pProp->GetOriginalValue();
      	CString d;
      	d = t.bstrVal;

      5.8 選擇設(shè)置值

      調(diào)用對應(yīng)的Sel和Set方法

      6. MFCPropertyGridPropery子類

      • CCheckBoxProp
      • CPasswordProp
      • CSliderProp
      • CBoundedNumberPairProp
      • CBoundedNumberSubProp
      • CIconListProp
      • CComboBoxExProp
      • COwnerDrawDescrProp
      • CTwoButtonsProp
      • CCustomDlgProp

      7. MFCPropertyGridCtrl獲取用戶輸入值

      CMFCPropertyGridProperty *pProperty;//定義一個指向子項的指針
      //輸入重定向   
      pProperty=pGroup11->GetSubItem(0) ;//獲得子項的指針
      // pGroup11在對話框頭文件中定義(公有成員變量)
      const COleVariant &strValue=pProperty->GetValue();//獲得子項值
      CString strTmp =(CString)strValue;
      MessageBox( strTmp);

      8. MFCPropertyGridCtrl屬性改變事件

      .h中加入

      afx_msg LRESULT OnPropertyChanged(WPARAM, LPARAM);

      .cpp中加入ON_REGISTERED_MESSAGE

      //注冊消息, AFX_WM_PROPERTY_CHANGED:發(fā)送ctrl消息到父窗口
      BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
       ON_WM_PAINT()
       ON_WM_CREATE()
       ON_REGISTERED_MESSAGE(AFX_WM_PROPERTY_CHANGED, OnPropertyChanged)
      END_MESSAGE_MAP()

      然后添加函數(shù) OnPropertyChanged

      如果使用GetData的值作為空間ID來進(jìn)行判斷,則必須要在創(chuàng)建控件時手動SetData來設(shè)置ID,否則默認(rèn)都是0

      //用于區(qū)分Prop, 使用SetData, GetData方法
      //CMFCPropertyGridProperty* pProp1 = new CMFCPropertyGridProperty(strTitle, (_variant_t)bVal, strDesc);
      //pProp1->SetData(100);
      //int nPropId = pProp1->GetData();
      
      //消息處理, lParam是Property屬性項, wParam是ctrl的id
      LRESULT CWorkspaceBar::OnPropertyChanged (WPARAM,LPARAM lParam)
      {
      CMFCPropertyGridProperty* pProp = (CMFCPropertyGridProperty*) lParam;
      BOOL bResetMDIChild = FALSE;
      switch ((int) pProp->GetData ())
      {
         case :pProp->GetValue(); break ;
         }
      
      }

      這里根據(jù)情況,還可以這樣寫:

      LRESULT CCMFCPGCtrlDlg::OnPropertyChanged (WPARAM,LPARAM lParam) {   
          CMFCPropertyGridProperty* pProp = (CMFCPropertyGridProperty*) lParam; 
          int id = (int) pProp->GetData ();     
          CString s = pProp->GetName();  //被改變的參數(shù)名  
          COleVariant t = pProp->GetValue(); //改變之后的值  
          t = pProp->GetOriginalValue();  //改變之前的值  
          CString d;     
          d = t.bstrVal;      //從COleVariant到CString  
          return 0; 
      }

      還有就是可能需要做類型檢查的情況

      LRESULT CMyWnd::OnPropertyChanged( WPARAM wParam,LPARAM lParam )
      {
       CMFCPropertyGridProperty* pProp = (CMFCPropertyGridProperty*) lParam;
       //is the property ctrl
       if ( (long)wParam == 2 )
       { 
       }
       pProp->SetValue((_variant_t)false);
       pProp->Redraw();
       int pID = pProp->GetData();
       CString str = pProp->GetName();
       if ( str == _T("abc") )
       {
        COleVariant var = pProp->GetValue();
        if ( var.boolVal == VARIANT_TRUE )
        {
         //AfxMessageBox(L"failed!");
      
         //pProp->SetValue(VARIANT_FALSE);
        }
       }
       if  (pID == 1)
       {
       }
       if  (pID > 1)
       {
       }
       return 0;
      }

      所有詳細(xì)都會匯總到這個函數(shù)里,所以需要做手工判斷

      最后再貼一遍官方手冊:–官方手冊– 

      posted on 2021-08-24 15:52  七星落地  閱讀(975)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 一区二区三区不卡国产| 乱老年女人伦免费视频| 日韩国产亚洲欧美成人图片| 凤凰县| 日本xxxx色视频在线播放| 亚洲熟妇熟女久久精品综合| 国产亚洲精品2021自在线| 小污女小欲女导航| 一区二区三区日本久久九| 精品少妇av蜜臀av| 久久免费精品国自产拍网站| 色综合色狠狠天天综合网| 亚洲人成人日韩中文字幕| 精品人妻少妇一区二区三区| 国产成人亚洲无码淙合青草| 亚洲天堂av在线免费看| 少妇愉情理伦片高潮日本| 午夜免费福利小电影| 四房播色综合久久婷婷| A级毛片免费完整视频| 4hu亚洲人成人无码网www电影首页| 亚洲精品中文字幕一区二| 亚洲av永久无码精品天堂久久| 人人综合亚洲无线码另类| 国产精品老熟女乱一区二区| 日韩国产成人精品视频| 亚洲成av人片天堂网无码| 女同另类激情在线三区| 亚洲中文字幕成人综合网| 中文字幕无码av激情不卡| 亚洲国产欧美日韩另类| 无码精品人妻一区二区三区中| 国产免费丝袜调教视频| 精品一区二区三区四区色| 亚洲偷自拍国综合| 亚洲精品中文字幕无码蜜桃| 亚洲欧美自偷自拍视频图片| 亚洲国产美女精品久久久| 新版天堂资源中文8在线| 国产gaysexchina男外卖| 免费吃奶摸下激烈视频|