?? drawtoolbar.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 + -