IE開發心得

來源:互聯網
上載者:User

1,CToolBar、CComboBoxEx、CReBar

1.1CToolBar建立方法、位元影像設定方法、文字設定方法、訊息響應函數設定方法

 

static UINT btns[] = {ID_GO_BACK,ID_GO_FORWARD,ID_GO_DELETE,ID_GO_SEARCH};
 m_wndToolBar.Create(this);
 m_wndToolBar.SetButtons(btns,4);
 
 int i;
 CBitmap bmp;
 CImageList img;
 img.Create(32,32,ILC_COLOR,0,1);
 for(i = 0;i < 4;++i)
 {
  bmp.LoadBitmap(IDB_BACK+i);
  img.Add(&bmp,RGB(255,0,255));
  bmp.Detach();
 }

 m_wndToolBar.GetToolBarCtrl().SetImageList(&img);
 m_wndToolBar.SetSizes(CSize(55,55),CSize(32,32));

 m_wndToolBar.SetButtonText(0,"Back");
 m_wndToolBar.SetButtonText(1,"Forward");
 m_wndToolBar.SetButtonText(2,"Stop");
 m_wndToolBar.SetButtonText(3,"Home");

 

在.h檔案中聲明afx void On×× ();

在.cpp檔案中添加宏 ON_COMMAND(btns中的某個取值,OnXX)

在.cpp檔案中實現void On×× ();

 

1.2CComboBoxEx

m_wndAddress.Create(CBS_DROPDOWN |WS_CHILD,CRect(0,0,200,120),
  this,AFX_IDW_TOOLBAR+1)

最後一個參數是其ID,訊息處理時表明來源

處理ON_CBN_SELENDOK可以處理使用者選中某現存項的情況

void CMainFrame::OnNewAddressEnter()
{

//擷取選中項的方法
 CString str;
 m_wndAddress.GetEditCtrl()->GetWindowText(str);
 ((CIEView*)GetActiveView())->Navigate(str,0,NULL);

//插入新項的方法

 COMBOBOXEXITEM item;
 item.mask = CBEIF_TEXT;
 item.iItem = -1;
 item.pszText = (LPTSTR)(LPCTSTR)str;
 m_wndAddress.InsertItem(&item);
}

處理IDOK命令可以處理使用者輸入新項按斷行符號的情況

void CMainFrame::OnNewAddress()
{
 CString str;
 m_wndAddress.GetLBText(m_wndAddress.GetCurSel(),str);
 ((CIEView*)GetActiveView())->Navigate(str,0,NULL);
}

這兩個訊息的處理需手動加入一些宏

在.h檔案中加入afx void OnXX();

在.cpp檔案中加入ON_CBN_SELENDOK(AFX_IDW_TOOLBAR+1,OnNewAddressEnter),ON_COMMAND(IDOK,OnNewAddress)

在.cpp檔案中加入兩個函數的實現

 

1.3CReBar

相當於一個控制項容器,可以將CComboBoxEx、CToolBar通過AddBar加進去,這樣就可以統一規劃控制項的布局

 

2,單文檔應用程式中CFrameWnd、CDocument、CView的關係

CFrameWnd可以通過GetActiveView擷取CView的指標

CView可以通過GetParent擷取CFrameWnd的指標

CView可以通過GetDocument擷取CDocument指標

CDocument可以通過GetFirstViewPosition和GetNextView擷取CView指標

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.