热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->vc 
站内搜索:
VC++删除浮动工具条中关闭按钮(2)
作者:刘涛 来源:天极网 整理日期:2007-10-18

  三、程序代码

/////////////////////////////////////////////////////////////////////////////
// ToolBarEx.h : header file
#ifndef __TOOLBAREX_H__
#define __TOOLBAREX_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

class CToolBarEx : public CToolBar
{
 DECLARE_DYNAMIC(CToolBarEx)
 // Construction
 public:
  CToolBarEx();
  // Attributes
 protected:
  BOOL m_bMenuRemoved;
  // Operations
 public:
  // Overrides
  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(CToolBarEx)
  //}}AFX_VIRTUAL
  // Implementation
 public:
  virtual ~CToolBarEx();
  // Generated message map functions
 protected:
  //{{AFX_MSG(CToolBarEx)
   afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
};
#endif // __TOOLBAREX_H__

//////////////////////////////////////////////////////////////////////// ToolBarEx.cpp : implementation file
#include "StdAfx.h"
#include "ToolBarEx.h"
#include <afxpriv.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CToolBarEx::CToolBarEx()
{
 // TODO: add construction code here.
 m_bMenuRemoved = FALSE;
}

CToolBarEx::~CToolBarEx()
{
 // TODO: add destruction code here.
}

IMPLEMENT_DYNAMIC(CToolBarEx, CToolBar)
BEGIN_MESSAGE_MAP(CToolBarEx, CToolBar)
//{{AFX_MSG_MAP(CToolBarEx)
ON_WM_WINDOWPOSCHANGED()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// CToolBarEx message handlers

void CToolBarEx::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
 CToolBar::OnWindowPosChanged(lpwndpos);

 // should only be called once, when floated.
 if( IsFloating() )
 {
  if( m_pDockBar && !m_bMenuRemoved )
  {
   CWnd* pParent = m_pDockBar->GetParent();
   if( pParent->IsKindOf(RUNTIME_CLASS(CMiniFrameWnd)))
   {
    pParent->ModifyStyle( WS_SYSMENU, 0, 0 );
    m_bMenuRemoved = TRUE;
   }
  }
 }
 else if( m_bMenuRemoved ) {
  m_bMenuRemoved = FALSE;
 }
}

  四、小结

  本实例通过一个自定义类,处理Windows中窗口位置变化消息,实现了删除浮动工具条上"关闭"按钮的目的,在上述过程中,最主要的工作还是判断当前窗口的父窗口是否为浮动工具条的框架窗口类-CMiniFrameWnd类。
[1]  [2]  
相关文章