www.pudn.com > my2cadtest07261930.rar > StatusBar.cpp, change:2006-07-26,size:2387b


// StatusBar.cpp: implementation of the CStatusBar class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "StatusBar.h" 
#include "stdio.h" 
#include "commctrl.h" 
#pragma comment(lib, "comctl32.lib") 
 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
static char cOldmsg[3][40] = {"当前操作状态","画笔线型","画笔颜色和画笔粗细"}; 
 
void CStatusBar::CreateSB(HWND hWnd) 
{ 
	m_hWndStatusBar = ::CreateStatusWindow(WS_CHILD | WS_VISIBLE, 
											"Welcome to Team 4 !", 
											hWnd, 
											IDS_STATUSBAR); 
	 
	ReSize(hWnd); 
} 
 
HWND CStatusBar::GetHWnd() 
{ 
	return m_hWndStatusBar; 
} 
 
void CStatusBar::ShowMessage(POINT& pt, int nIndexPos) 
{ 
	char str[70]; 
	sprintf(str,"鼠标位置: X = %04d , Y = %04d",pt.x,pt.y); 
	SendMessage(m_hWndStatusBar,SB_SETTEXT,nIndexPos,(LPARAM)str);	 
} 
 
void CStatusBar::ShowMessage(char* cStatusTxt, int nIndexPos) 
{ 
	strcpy(cOldmsg[nIndexPos - 2], cStatusTxt); 
	SendMessage(m_hWndStatusBar, SB_SETTEXT, nIndexPos, (LPARAM)cStatusTxt);	 
} 
 
 
void CStatusBar::OnMouseMove( LPARAM lParam) 
{ 
	POINT curPt; 
	curPt.x = LOWORD(lParam); 
	curPt.y = HIWORD(lParam); 
 
	ShowMessage(curPt,1); 
} 
 
//空置状态栏句柄 
HWND CStatusBar::SetHWndNull() 
{ 
	return m_hWndStatusBar = NULL; 
} 
 
void CStatusBar::SetVisible(HWND hWnd ) 
{ 
	 
  if (GetHWnd() != NULL) 
	{ 
		::DestroyWindow(GetHWnd()); 
		SetHWndNull(); 
	} 
	else 
	{ 
		CreateSB(hWnd); 
	} 
	 
} 
 
 
void CStatusBar::ReSize(HWND hWnd) 
{ 
	RECT rectTB; 
	GetClientRect(hWnd,&rectTB); 
	 
	//确定每格的右边界,从左边开始,其余各格是前一格的右边界 
	int nPartsPos[5] = {rectTB.left + 150, 
		                rectTB.left + 350,//第二格放当前鼠标的坐标, 
						rectTB.left + 500,//第三格放当前使用的绘图工具或操作, 
						rectTB.left + 600,//第四格放当前的画笔线型(实线或虚线等), 
						rectTB.left + 800};//第五格放当前画笔颜色和画笔粗细。 
 
	SendMessage(m_hWndStatusBar,SB_SETPARTS,5,(LPARAM)nPartsPos);	//set statusbar's parts space 
	 
	//向状态栏发送信息 
	for (int nPart = 0; nPart < 3; nPart ++) 
	{ 
		SendMessage(m_hWndStatusBar, SB_SETTEXT, nPart + 2, (LPARAM)cOldmsg[nPart]);	 
	} 
} 
 
 
 
 
CStatusBar::CStatusBar() 
{ 
 
} 
 
CStatusBar::~CStatusBar() 
{ 
 
}