windows 编程

Shell_NotifyIcon : 用来实现在任务栏中显示小图标。NOTIFYICONDATA.uCallbackMessage 指示出相关的消息。同时在接收消息时,LPARAM 只是 WM_LBUTTONDBLCLK, WM_RBUTTONDOWN.

多窗口的创建 , 在 主窗口 中建立 CCoolBar m_tabWindowTool; 成员变量。 /

/TODO:创建tab窗口
 if(!m_tabWindowTool.Create(_T("Tab窗口"),this, CSize(25,25),TRUE,1023))
 {
  TRACE0("创建Tab窗口失败");
  return -1;
 }

 //tab窗口的停靠控制
 m_tabWindowTool.SetBarStyle(m_tabWindowTool.GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
 m_tabWindowTool.EnableDocking(CBRS_ALIGN_ANY);
 DockControlBar(&m_tabWindowTool,AFX_IDW_DOCKBAR_TOP);

 long style = ::GetWindowLong(m_tabWindowTool.GetSafeHwnd(),GWL_STYLE);
 style &= ~(SC_CLOSE);
 SetWindowLong(m_tabWindowTool.GetSafeHwnd(),GWL_STYLE,style);

 /////////使浮动与停靠显示相同的头部////
 #ifdef _SCB_REPLACE_MINIFRAME
    m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd);
 #endif //_SCB_REPLACE_MINIFRAME

 if(!theTabWnd.Create(TCS_TABS|WS_CHILD|WS_VISIBLE,CRect(0,0,100,100),&m_tabWindowTool,AFX_IDW_PANE_FIRST))
 {
   TRACE0("创建TAB失败!");
   return -1 ;
 }

以上建立了一个容纳 class CTabWnd : public CTabCtrl 的容器。 CTabWnd用来实际的容纳标签。

实际的 建立一个新的标签 :

#include <vector>
#include <string>
#include <algorithm>
#pragma warning(disable:4786)

class CViewTabManager 
{
public:
 void RemoveView(CView * pView);
 void ActiveView(CView * pView, CView * pOldView);
 void AddView( CView * pView, char * name);
 CViewTabManager();
 virtual ~CViewTabManager();
private:
 std::vector<std::string> vViewNames;
 std::vector<CView *> vViews;

};
CViewTabManager theViewTabManager ;

extern CTabWnd theTabWnd ;

CViewTabManager::CViewTabManager()
{

}

CViewTabManager::~CViewTabManager()
{

}

void CViewTabManager::AddView(CView *pView, char *name)
{
 CString cs(name);

 vViews.push_back(pView);  //保存相关的视图指针和名字
 vViewNames.push_back(name);

 if (theTabWnd.GetSafeHwnd())
 {
  TC_ITEM ti;
  ti.mask = TCIF_TEXT|TCIF_PARAM|TCIF_IMAGE;
  ti.pszText = cs.LockBuffer();
  ti.lParam = (long) pView;
  ti.iImage = 0 ;
  theTabWnd.InsertItem(theTabWnd.GetItemCount(), &ti);
  cs.UnlockBuffer();
 }
}

void CViewTabManager::ActiveView(CView *pView, CView *pOldView)
{
 for (int t = 0; t < theTabWnd.GetItemCount(); t++)
 {
  TC_ITEM ti;
  ti.mask = TCIF_PARAM;
  theTabWnd.GetItem(t, &ti);
  if (ti.lParam == (long) pView)
  {
   theTabWnd.SetCurSel(t);
   theTabWnd.Invalidate();
   break;
  }
 }
}

void CViewTabManager::RemoveView(CView *pView)
{
 if(!theTabWnd.GetSafeHwnd())
 {
  if(vViewNames.size()>0)
  {
   vViewNames.erase(vViewNames.begin(),vViewNames.end());
   vViews.erase(vViews.begin(),vViews.end());
  }
  return ;
 }
 for (int t = 0; t < theTabWnd.GetItemCount(); t++)
 {
  TC_ITEM ti;
  ti.mask = TCIF_PARAM;
  theTabWnd.GetItem(t, &ti);
  if (ti.lParam == (long) pView)
  {
   theTabWnd.DeleteItem(t);
   theTabWnd.Invalidate();
   break;
  }
 }

 for( t = 0 ; t <vViews.size(); t++)
 {
  if( pView == vViews[t] )
  {
   vViewNames.erase(std::find(vViewNames.begin(),vViewNames.end(),vViewNames[t]));
   vViews.erase(std::find(vViews.begin(),vViews.end(),vViews[t]));
  }
 }
}


class CTabWnd : public CTabCtrl
{
// Construction
public:
 CTabWnd();

// Attributes
public:

// Operations
public:

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CTabWnd)
 protected:
 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
 //}}AFX_VIRTUAL

// Implementation
public:
 virtual ~CTabWnd();

 // Generated message map functions
protected:
 //{{AFX_MSG(CTabWnd)
 afx_msg void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
 afx_msg void OnClose();
 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
 //}}AFX_MSG

 DECLARE_MESSAGE_MAP()
};

 

CTabWnd theTabWnd ;

CTabWnd::CTabWnd()
{
}

CTabWnd::~CTabWnd()
{
}


BEGIN_MESSAGE_MAP(CTabWnd, CTabCtrl)
 //{{AFX_MSG_MAP(CTabWnd)
 ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
 ON_WM_CREATE()
 ON_WM_CLOSE()
 ON_WM_LBUTTONDBLCLK()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTabWnd message handlers

void CTabWnd::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
 int idx = GetCurSel();
 TC_ITEM ti;
 ti.mask = TCIF_PARAM;
 GetItem(idx, &ti);
 CView * pView = (CView *) ti.lParam;
 if(pView != NULL )((CMDIFrameWnd *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
 *pResult = 0; 
}

BOOL CTabWnd::PreCreateWindow(CREATESTRUCT& cs)
{
 cs.style &= ~(WS_SYSMENU); 
 return CTabCtrl::PreCreateWindow(cs);
}

int CTabWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CTabCtrl::OnCreate(lpCreateStruct) == -1)
  return -1;


 return 0;
}

void CTabWnd::OnClose()
{
 CTabCtrl::OnClose();
}

void CTabWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
{

  
 CTabCtrl::OnLButtonDblClk(nFlags, point);
}

CCoolBar 从网上下载的。

你可能感兴趣的:(windows 编程)