123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- // SkinToolBar.cpp : implementation file
- //
- #include "stdafx.h"
- //#include "dialog.h"
- #include "SkinToolBar.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSkinToolBar
- CSkinToolBar::CSkinToolBar()
- {
- m_bShow=TRUE;
- }
- CSkinToolBar::~CSkinToolBar()
- {
- #if 0
- for (int i=0;i<m_ptButton.GetCount();i++ ){
- //delete m_ptButton.GetAt(m_ptButton.FindIndex(i));
- CSkinButton *pBtn = (CSkinButton*)m_ptButton.GetAt(m_ptButton.FindIndex(i));
- pBtn->DestroyWindow();
- delete pBtn;
- pBtn = NULL;
- }
- m_ptButton.RemoveAll();
- #else
- ClearMemory();
- #endif
- }
- void CSkinToolBar::ClearMemory()
- {
- int nCount = m_ptButton.GetCount();
- if ( nCount == -1) return;
- for (int i=0;i<nCount;i++ ){
- CSkinButton *pBtn = (CSkinButton*)m_ptButton.GetAt(m_ptButton.FindIndex(i));
- pBtn->DestroyWindow();
- delete pBtn;
- }
- m_ptButton.RemoveAll();
- }
- BEGIN_MESSAGE_MAP(CSkinToolBar, CSkinStatic)
- //{{AFX_MSG_MAP(CSkinToolBar)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSkinToolBar message handlers
- BOOL CSkinToolBar::LoadTBImage(UINT uIDRes,COLORREF crBack)
- {
- CBitmap bmp;
- if (m_bmpToolBar.m_hObject) {
- bmp.LoadBitmap(uIDRes);
- m_bmpToolBar.SetBitmap((HBITMAP)bmp.m_hObject );
- return TRUE;
- }
- else
- return m_bmpToolBar.LoadBitmap(uIDRes);
- }
- void CSkinToolBar::SetSizes( SIZE sizeButton, SIZE sizeImage )
- {
- int nButtonCount=m_bmpToolBar.GetWidth()/sizeImage.cx ;
- m_rcButton.RemoveAll();
- for (int j=0;j<m_ptButton.GetCount();j++ ) {
- //CRect rcButton;// Õâ¸ö¾Ö²¿±äÁ¿Ã»Óᣠ[7/22/2013 Zero.t]
- CSkinButton *pBtn=(CSkinButton *)m_ptButton.GetAt(m_ptButton.FindIndex(j));
- pBtn->DestroyWindow();
- delete pBtn;
- }
- m_ptButton.RemoveAll();
- for (int i=0;i<nButtonCount;i++) {
- CRect rcButton;
- rcButton.left =30+ i*sizeButton.cx ;
- rcButton.right =rcButton.left+sizeButton.cx;
- rcButton.top=2;
- rcButton.bottom =sizeButton.cy+2;
- CEnBitmap bmpButton;
- m_bmpToolBar.DrawImage(bmpButton,i+1,1,nButtonCount,1);
- UINT nId=m_ltCommands.GetAt(m_ltCommands.FindIndex(i));
- CSkinButton *pBtn=new CSkinButton();
- pBtn->Create("",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_NOTIFY,rcButton,this,nId);
- pBtn->SetBitmap((HBITMAP)bmpButton.m_hObject );
- pBtn->SetStyle(STYLE_TOOLBAR);
- pBtn->SetTextColor(m_crText);
- m_rcButton.Add(rcButton);
- m_ptButton.AddTail(pBtn);
- }
- RecalcLayout();
- }
- void CSkinToolBar::RecalcLayout()
- {
- CPaintDC dc(this);
- CSkinButton *pBtn;
- CRect rc(0,0,30,0);
- for (int i=0;i<m_ptButton.GetCount();i++ )
- {
- pBtn=(CSkinButton *)m_ptButton.GetAt(m_ptButton.FindIndex(i));
- CString strText;
- CRect &rcButton=m_rcButton.GetAt(i) ;
- UINT nId=m_ltCommands.GetAt(m_ltCommands.FindIndex(i));
- strText.LoadString(nId);
- TEXTMETRIC tm ;
- dc.GetTextMetrics( &tm );
- int nWidth=strText.GetLength()* tm.tmAveCharWidth;
- rcButton.right = rc.right+rcButton.Width()+nWidth;
- rcButton.left =rc.right ;
- pBtn->SetWindowPos(NULL, rcButton.left ,rcButton.top ,rcButton.Width() ,rcButton.Height() ,SWP_NOZORDER );
- rc=rcButton;
- }
- }
- void CSkinToolBar::SetBasicCommands(CList<UINT,UINT> <Conmmand)
- {
- m_ltCommands.RemoveAll ();
- m_ltCommands.AddTail (<Conmmand);
- }
|