⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawtoolbar.cpp

📁 VC&Matlab混合编程实现无线电导航指示器
💻 CPP
字号:
// DrawToolBar.cpp: implementation of the CDrawToolBar class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "..\RADIO.h"
#include "DrawToolBar.h"
#include "..\resource.h"
#include "..\ommonStatic.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif





IMPLEMENT_DYNCREATE(CDrawToolBar, CToolBar)

BEGIN_MESSAGE_MAP(CDrawToolBar, CToolBar)
	//{{AFX_MSG_MAP(CDrawToolBar)
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_MOVE()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
	// Standard printing commands
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDrawToolBar::CDrawToolBar()
{
	m_pBackGroundBrush=new CBrush();
	m_pBackGroundBrush->CreateSolidBrush(RGB(0,0,0));
	m_IDfloatingTitle=0;
	
}

CDrawToolBar::CDrawToolBar(UINT IDbackGroundBitmap)
{
	CBitmap bitmap;
	bitmap.LoadBitmap(IDbackGroundBitmap);
	m_pBackGroundBrush=new CBrush(&bitmap);

}

void CDrawToolBar::SetBackGroundBitmap(UINT IDbackGroundBitmap){
	CBitmap bitmap;
	bitmap.LoadBitmap(IDbackGroundBitmap);
	delete(m_pBackGroundBrush);
	m_pBackGroundBrush=new CBrush(&bitmap);
}

CDrawToolBar::~CDrawToolBar()
{
delete m_pBackGroundBrush;
}

void CDrawToolBar::OnPaint() 
{
	//这句话千万不能少!
	CPaintDC dc(this); // device context for painting
	
    Paint();
	
	// Do not call CView::OnPaint() for painting messages
}




void CDrawToolBar::OnSize(UINT nType, int cx, int cy) 
{	
	CToolBar::OnSize(nType, cx, cy);
	
}


int CDrawToolBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CToolBar::OnCreate(lpCreateStruct) == -1)
		return -1;	
	// TODO: Add your specialized creation code here
	return 0;
}


void CDrawToolBar::OnMove(int x, int y) 
{
	CToolBar::OnMove(x, y);

    CWnd *pParentWnd=GetFloatingParentWnd();
	if (pParentWnd!=NULL)
	{  //此时ToolBar是浮动的,把它的父框架的WndProc存在CDrawToolBar::previousParentProc里面。
	   //当然只能在父框架建立时存一遍,当父框架完蛋时(WM_QUIT),把CDrawToolBar::previousParentProc
	   //再变成NULL.
		if(CommonStatic::previousParentProc==NULL ){
			CommonStatic::previousParentProc=(WNDPROC)::GetWindowLong(pParentWnd->GetSafeHwnd(),GWL_WNDPROC);
		}
		//给ToolBar的父框架放钩子。
		::SetWindowLong(pParentWnd->GetSafeHwnd(),GWL_WNDPROC,(LONG)(CommonStatic::ParentWndProc));
		LONG lExStyle=::GetWindowLong(pParentWnd->GetSafeHwnd(),GWL_EXSTYLE);
		LONG lStyle=::GetWindowLong(pParentWnd->GetSafeHwnd(),GWL_STYLE);
		//::SetWindowLong(pParentWnd->GetSafeHwnd(),GWL_EXSTYLE,lExStyle&(~WS_EX_TOOLWINDOW));
		
		//小叉叉不见了。
		::SetWindowLong(pParentWnd->GetSafeHwnd(),GWL_STYLE,lStyle&(~WS_OVERLAPPED)&(~WS_POPUPWINDOW)|WS_CAPTION);
		//只是给父框架发个WM_SETTEXT消息!
		SetFloatingTitle(m_IDfloatingTitle);
        //排除从Dock状态直接拖出去的Bug.
        CRect rect;
		pParentWnd->GetWindowRect(&rect);
		if(rect.top<0){
			pParentWnd->MoveWindow(rect.left,0,rect.right-rect.left,rect.bottom-rect.top);
		}
	}
	
}


void CDrawToolBar::DrawBackGround(CDC *pDC)
{
	CRect rect;
	GetClientRect(&rect);	
	pDC->FillRect(&rect,m_pBackGroundBrush);
}


void CDrawToolBar::SetPaintProc(PAINTPROC paintProc){
m_paintProc=paintProc;
}

void CDrawToolBar::SetPaintInfo(CString strInfo)
{
m_strPaintInfo=strInfo;
}

void CDrawToolBar::Paint()
{   
	CDC *pDC=GetDC();
	DrawBackGround(pDC);
	m_paintProc(pDC,m_strPaintInfo);
	ReleaseDC(pDC);//不调用会死的很惨!
}

void CDrawToolBar::SetFloatingTitle(UINT IDfloatingTitle)
{//设置浮动里父窗口的标题
 //标题ID放在窗口句柄的userdata里
	m_IDfloatingTitle=IDfloatingTitle;
	CWnd *pParentWnd;
    if((pParentWnd=GetFloatingParentWnd())!=NULL){
		::SetWindowLong(pParentWnd->GetSafeHwnd(),GWL_USERDATA,IDfloatingTitle);
		pParentWnd->SetWindowText("");
    }
}

CWnd* CDrawToolBar::GetFloatingParentWnd()
{
	//如果ToolBar在浮动返回父框架的Cwnd*
	//如果ToolBar不在浮动返回NULL
	CWnd *pParentWnd=GetParent()->GetParent();
	TCHAR pBuffer[40];
	::GetClassName(pParentWnd->GetSafeHwnd(),pBuffer,sizeof(pBuffer));
	
	//这是父框架
	CString strClassName("Afx:400000:8:10011:0:0");
	CString strRealClassName(pBuffer);
	if (strClassName==strRealClassName){
		return pParentWnd;		
	}else
	{
		return NULL;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -