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

📄 mydraw.cpp

📁 wince42 开发的IE, 640X480, xscale平台,没有实现flash插件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//File Name: MyDraw.cpp
//Project Name: 中央控制系统
//Author: lijunfeng
//Date: 2004-12-1
//Last mod:
//Description:  
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MyDraw.h"
#include "resrc1.h"

const int ICON_WIDTH = 25;
const int ICON_LEFT_POS = 10;
const int ICON_LEFT_POS2 = 360;
const int ICON_SEP = 2;


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
HINSTANCE g_hinst;

CMyDraw::CMyDraw()
{
	m_hdc = NULL;
	m_dt = OTHER_TOOLBAR;
	memset(m_title,0,sizeof(m_title));
	wsprintf(m_title,_T("就绪"));
	m_trct.left = 0;
	m_trct.top = 0;
	m_trct.right = 0;	
//	m_status = 0;
	m_hwnd = NULL;
	m_pos = 0;
	m_nTempValue = 10000;
	memset(states,0,sizeof(states));

	memset(m_szRunUpText,0,sizeof(m_szRunUpText));
	m_nRunUpTextId = 0;
	m_nRunUpTextCount = 0;
}

CMyDraw::~CMyDraw()
{	
	for(int i=0;i<MAX_RUNUP_TEXT_COUNT;i++)
	{
		if( m_szRunUpText[i] )
		{
			char* pp = (char*)m_szRunUpText[i];
			delete[] pp;
		}
	}
}
bool CMyDraw::SetDT(short dt)
{
	if( dt != m_dt)
	{		
		m_dt = dt;
		if( dt == MAIN_STATUSBAR )
		{
//			wsprintf(m_title,_T("欢迎使用智能家居系统"));
			//m_trct.left = 48;
			//m_trct.top = 8;
			ReadRunUpText();
			RefreshTitleText();
		}
		return true;
	}
	return false;
}
#define CTLPNL_CLASS			TEXT("CTLPNL_Class") // class name of our hidden window
void CMyDraw::SetWindowTopMost()
{

	Sleep(500);
	POINT pt;
	pt.x = 320;
	pt.y = 240;
	HWND hwnd = WindowFromPoint(pt);
	HWND hwndParent = ::GetParent(hwnd);
	int nMaxLevel = 0;
	while( hwndParent )
	{
		hwnd = hwndParent;
		hwndParent = ::GetParent(hwnd);
		if( nMaxLevel++ > 10 )
			break;
	}
/*	
	Sleep(500);
	HWND hwnd = ::FindWindow(CTLPNL_CLASS, NULL);
			int cc = 0;
		   while( NULL == hwnd )
		   {
			   Sleep(50);
			   printf("cc=%d\n",cc++);
			   if( cc++ > 100 ) break;
			   hwnd = ::FindWindow(CTLPNL_CLASS, NULL);
		   }
	HWND hwndParent = ::GetParent(hwnd);
	int nMaxLevel = 0;
	while( hwndParent )
	{
		printf("cc=%d\n",cc++);
		hwnd = hwndParent;
		hwndParent = ::GetParent(hwnd);
		if( nMaxLevel++ > 10 )
			break;
	}*/
	if( hwnd )
	{
		RECT rct;
		::GetWindowRect(hwnd,&rct);
		//printf("rct=%d,%d\n",rct.left,rct.right);
		::SetWindowPos(hwnd,HWND_TOPMOST,
			rct.left,rct.top,rct.right-rct.left,rct.bottom-rct.top,SWP_SHOWWINDOW);
	}
}
void CMyDraw::RunVolumeSet(short nShow)
{	
}
void CMyDraw::RunNetWorkSet()
{
		   SHELLEXECUTEINFO sei;
           sei.cbSize = sizeof(sei);
           sei.fMask = SEE_MASK_FLAG_NO_UI;
           sei.hwnd = m_hwnd;
           sei.lpVerb = NULL;
           sei.lpFile = GetExeFilePathW(L"adsldial.exe");		   
           //sei.lpParameters = L"cplmain.cpl,10";
           sei.lpDirectory = NULL;
			sei.nShow = SW_SHOWNORMAL;
       	   ShellExecuteEx(&sei); 
}
#include <pwinuser.h>
void CMyDraw::RunMouseAdjust()
{
	TouchCalibrate();
	/*
		   SHELLEXECUTEINFO sei;
           sei.cbSize = sizeof(sei);
           sei.fMask = SEE_MASK_FLAG_NO_UI;
           sei.hwnd = m_hwnd;
           sei.lpVerb = NULL;
           sei.lpFile = L"ctlpnl";		   
           sei.lpParameters = L"cplmain.cpl,9";
           sei.lpDirectory = NULL;
  		   sei.nShow = SW_SHOWNORMAL;
       	   ShellExecuteEx(&sei); 
		   SetWindowTopMost();*/

}
/*
void CMyDraw::RunSystemTimeSet()
{
		   SHELLEXECUTEINFO sei;
           sei.cbSize = sizeof(sei);
           sei.fMask = SEE_MASK_FLAG_NO_UI;
           sei.hwnd = m_hwnd;
           sei.lpVerb = NULL;
           sei.lpFile = L"ctlpnl";		   
           sei.lpParameters = L"cplmain.cpl,13";
           sei.lpDirectory = NULL;
           sei.nShow = SW_SHOWNORMAL;
       	   ShellExecuteEx(&sei); 
}*/
long CMyDraw::SetHintStatus(long hStatus)
{	
	//m_status |= hStatus;
	int nSign = 1;
	if( hStatus < 0 )
	{
		nSign = -1;
		hStatus = -hStatus;
//		printf("nValue=%d\n",hStatus);
	}
	byte bt;
	bt = hStatus & 0x0ff;
	int index = GetNoByMsgType(bt);
	hStatus = hStatus/256;	
//	printf("bt=%d,hs=%d,index=%d",bt,hStatus,index);
	if( bt == _mtTemperature )
	{
		m_nTempValue = (short)hStatus;
		m_nTempValue *= nSign;		
		return 1;
	}
	if( hStatus >= 4 )
		hStatus = 3;
	if( index >= 0 )
	{
		if( _mtDeviceErr == bt )
		{
			if( 1 == hStatus )
			{
				states[index]++;
				if( states[index] > 6000 )
					states[index] = 6000;
			}else
			{
				states[index]--;
				if( states[index] < 0 )
					states[index] = 0;
			}
		}
		else
		{
			states[index] = (byte)hStatus;
		}
	}
	if( (bt == _mtWarnNotify) && states[index] )
		RunExe(index);
	else if( (bt == _mtNewVedio) && states[index] == 1 )
		RunKsdj();
	else if( (bt == _mtNewVedioCall) && states[index] == 1 )
		RunKsdh();
	else if( _mtVolumeSet == bt )
		RunVolumeSet(states[index]);
	else if( _mtMouseAdjustSet == bt )
		RunMouseAdjust();
	return bt;		
}
void CMyDraw::ResetHintStatus(long hStatus)
{
	int index = GetNoByMsgType(hStatus);
	if( index >= 0 )
		states[index] = 0;
	//m_status &= hStatus;
}
int CMyDraw::GetNoByMsgType(long ty)
{
	int index = -1;
	for( int i= 0;i<ICONDATA_COUNT;i++)
	{
		if( iconData1[i] == ty )
		{
			index = i;
			break;
		}
	}
	return index;
}
void CMyDraw::DrawTimeString()
{
	if( m_hwnd == NULL )
		return;
	HDC hdc = GetDC(m_hwnd);
	RECT rct;
	GetTimeRect(rct);
	ImgDrawItem(hdc,IDB_BKGROUND,rct);
	DrawTimeString(hdc);
	ReleaseDC(m_hwnd,hdc);
}
void CMyDraw::DrawTimeString(HDC hdc)
{	
	HFONT hfont,oldfont;
	LOGFONT lf; 
    lf.lfHeight = 20; 
    lf.lfWidth = 0; 
    lf.lfEscapement = 0; 
    lf.lfOrientation = 0; 
    lf.lfWeight = FW_BOLD; 
    lf.lfItalic = 0; 
    lf.lfUnderline = 0; 
    lf.lfStrikeOut = 0; 
    lf.lfCharSet = ANSI_CHARSET; 
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS; 
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 
    lf.lfQuality = DEFAULT_QUALITY; 
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; 
	memset(lf.lfFaceName,0,sizeof(lf.lfFaceName));
    //lstrcpy(lf.lfFaceName, fontStyle.lfFaceName); 
    hfont = CreateFontIndirect(&lf); 
    
	oldfont = (HFONT)SelectObject(hdc,hfont);
	SetTextColor(hdc,RGB(255,255,255));
	SetBkMode(hdc,TRANSPARENT);

	SYSTEMTIME now;
	GetLocalTime(&now);		
	TCHAR buf[20]={0};
	wsprintf(buf,_T("%02d:%02d"),now.wHour,now.wMinute);
	int len = _tcslen(buf);
	RECT rct;
	GetTimeRect(rct);
	DrawText(hdc,buf,len,&rct,DT_LEFT);
	SelectObject(hdc,oldfont);
	DeleteObject(hfont);
}
void CMyDraw::GetTimeRect(RECT& rc)
{
	rc.left = 586;
	rc.top = 5;
	rc.bottom = 30;
	rc.right = 640;	
}
void CMyDraw::GetTempRect(RECT& rc)
{
	rc.left = 520;
	rc.top = 5;
	rc.bottom = 30;
	rc.right = 586;	
}
void CMyDraw::OnMyDraw(HDC hdc,RECT rc)
{
//	if( m_hdc == NULL )
	{
//		RECT& rc = *(RECT*)di.prcBounds;
		m_rct.left = rc.left;
		m_rct.right = rc.right;
		m_rct.top = rc.top;
		m_rct.bottom = rc.bottom;
		m_hdc = hdc;//di.hdcDraw;		
		//m_trct.top = m_rct.top;		
		m_trct.right = m_rct.right;
		m_trct.bottom = m_rct.bottom;
	}
	ImgDrawItem(IDB_BKGROUND);
	if( (m_dt == OTHER_TOOLBAR)||(m_dt == MAIN_STATUSBAR) )
	{
		if( m_title[0] != 0 )
		{			
			TextOut();
		}
		if( m_dt == OTHER_TOOLBAR )
		{
			//ImgDrawObject(IDB_CLOSE,ICON_LEFT_POS);
			//ImgDrawObject(IDB_HELP,ICON_LEFT_POS+ICON_SEP+ICON_WIDTH);
			ImgDrawItem(IDB_CLOSE,3,ICON_LEFT_POS);
			ImgDrawItem(IDB_HELP,3,ICON_LEFT_POS+ICON_SEP*4+ICON_WIDTH);
		}
	}
	else if( m_dt == MAIN_TOOLBAR )
	{
		ImgDrawHintObject();
		int posx = 400;//250;
		ImgDrawItem(IDB_PMHDA,3,posx);
		//ImgDrawItem(IDB_HINT10,3);
		//ImgDrawObject(IDB_FACE);
		//ImgDrawObject(IDB_FACE,30);
	}
}
LRESULT CMyDraw::IconDrawItem(int ResourceID) 
{ 
	if( m_hdc == NULL )
		return (FALSE);
	HICON hIcon;	
	hIcon = (HICON)LoadImage(g_hinst, MAKEINTRESOURCE(ResourceID), 
					IMAGE_ICON, 16, 16, 0); 
	if (!hIcon) 
	{ 
		return(FALSE); 
	}	
	DrawIconEx(m_hdc, m_rct.left,m_rct.top, hIcon, 
		16, 16, 0, NULL, DI_NORMAL); 
	return(TRUE); 
}
LRESULT CMyDraw::ImgDrawItem(HDC hdc,int ResourceID,RECT rc)
{
	HBITMAP hBmp, hOldBmp;
    hBmp = LoadBitmap(g_hinst, MAKEINTRESOURCE(ResourceID));
	if (!hBmp) 
	{ 		
		return(FALSE); 
	}	
	HDC hdcMemory;
	BITMAP  bmp;
	hdcMemory = CreateCompatibleDC( hdc );
    hOldBmp = (HBITMAP)SelectObject( hdcMemory, hBmp );
    GetObject( hBmp, sizeof(BITMAP), &bmp );
	StretchBlt(hdc,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,
					hdcMemory,0, 0,bmp.bmWidth, bmp.bmHeight,SRCCOPY );
	DeleteObject( SelectObject( hdcMemory, hOldBmp ) );
	DeleteDC( hdcMemory );
	return(TRUE);
}
LRESULT CMyDraw::ImgDrawItem(HDC hdc,int ResourceID,int xpos,int ypos)
{
	HBITMAP hBmp, hOldBmp;
    hBmp = LoadBitmap(g_hinst, MAKEINTRESOURCE(ResourceID));
	if (!hBmp) 
	{ 		
		return(FALSE); 
	}	
	HDC hdcMemory;
	BITMAP  bmp;
	hdcMemory = CreateCompatibleDC( hdc );
    hOldBmp = (HBITMAP)SelectObject( hdcMemory, hBmp );
    GetObject( hBmp, sizeof(BITMAP), &bmp );
	//printf("%d-%d\n",bmp.bmWidth, bmp.bmHeight);
	StretchBlt(hdc,xpos,ypos,bmp.bmWidth, bmp.bmHeight,
					hdcMemory,0, 0,bmp.bmWidth, bmp.bmHeight,SRCCOPY );
	DeleteObject( SelectObject( hdcMemory, hOldBmp ) );
	DeleteDC( hdcMemory );
	return 0;
}
LRESULT CMyDraw::ImgDrawItem(int ResourceID,short type,int posx)
{
	if( m_hdc == NULL )
		return (FALSE);
	HBITMAP hBmp, hOldBmp;
    hBmp = LoadBitmap(g_hinst, MAKEINTRESOURCE(ResourceID));
	if (!hBmp) 
	{ 
		return(FALSE); 
	}	
	HDC hdcMemory;
	BITMAP  bmp;
	hdcMemory = CreateCompatibleDC( m_hdc );
    hOldBmp = (HBITMAP)SelectObject( hdcMemory, hBmp );
    GetObject( hBmp, sizeof(BITMAP), &bmp );
	int posy = (m_rct.bottom-m_rct.top-bmp.bmWidth)/2+m_rct.top;
	if( posy < m_rct.top ) posy = m_rct.top;
	if( type == 0 )
		StretchBlt(m_hdc,m_rct.left,m_rct.top,m_rct.right-m_rct.left, m_rct.bottom-m_rct.top,
					hdcMemory,0, 0,bmp.bmWidth, bmp.bmHeight,SRCCOPY );
	else if( type == 1 )
		BitBlt(m_hdc,posx,posy,bmp.bmWidth, bmp.bmHeight,
                       hdcMemory,0, 0, SRCAND);
	else if( type == 2 )
		BitBlt(m_hdc,posx,posy,bmp.bmWidth, bmp.bmHeight,
                       hdcMemory,0, 0, SRCPAINT );
	else if( type == 3 )
	{
		//printf("posx,posy,bmp.bmWidth, bmp.bmHeight=%d,%d,%d,%d\n",ResourceID,posy,bmp.bmWidth, bmp.bmHeight);
//		StretchBlt(m_hdc,posx,posy,bmp.bmWidth, bmp.bmHeight,
//					hdcMemory,0, 0,bmp.bmWidth, bmp.bmHeight,SRCCOPY );
		BitBlt(m_hdc,posx,posy,bmp.bmWidth, bmp.bmHeight,
                       hdcMemory,0, 0, SRCCOPY );
	}
	DeleteObject( SelectObject( hdcMemory, hOldBmp ) );
	DeleteDC( hdcMemory );
	return(TRUE);
}
LRESULT CMyDraw::ImgDrawObject(int ResourceID,int posx)
{
	ImgDrawItem(ResourceID+1,1,posx);
	ImgDrawItem(ResourceID,2,posx);
	return(TRUE);
}
LRESULT CMyDraw::ImgDrawHintObject(int id)
{	
	return TRUE;
}
void CMyDraw::DrawStatusIcon(HDC hdc)
{	
}
void CMyDraw::RefreshTemperature(HDC hdc)
{
//	if( m_hwnd == NULL )
//		return;
//	HDC hdc = GetDC(m_hwnd);

	HFONT hfont,oldfont;
	LOGFONT lf; 
    lf.lfHeight = 20; 
    lf.lfWidth = 0; 
    lf.lfEscapement = 0; 
    lf.lfOrientation = 0; 
    lf.lfWeight = FW_BOLD; 
    lf.lfItalic = 0; 
    lf.lfUnderline = 0; 
    lf.lfStrikeOut = 0; 
    lf.lfCharSet = ANSI_CHARSET; 
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS; 
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 
    lf.lfQuality = DEFAULT_QUALITY; 
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; 
	memset(lf.lfFaceName,0,sizeof(lf.lfFaceName));
    //lstrcpy(lf.lfFaceName, fontStyle.lfFaceName); 
    hfont = CreateFontIndirect(&lf); 
    
	oldfont = (HFONT)SelectObject(hdc,hfont);
	SetTextColor(hdc,RGB(255,255,255));
	SetBkMode(hdc,TRANSPARENT);

	double dd = (double)m_nTempValue;
	TCHAR buf[20]={0};
	if( 10000 == m_nTempValue )
		wsprintf(buf,_T("温度"));
	else
		wsprintf(buf,_T("%.1f℃"),dd/10);
	int len = _tcslen(buf);
	RECT rct;
	GetTempRect(rct);
	DrawText(hdc,buf,len,&rct,DT_LEFT);
	SelectObject(hdc,oldfont);
	DeleteObject(hfont);
}
LRESULT CMyDraw::ImgDrawHintObject()
{
	for(int i=0;i<TITILE_ICON_COUNT;i++)
		ImgDrawHintObject(i);
/*
//最新来电/可视电话来电1
	int posx = ICON_LEFT_POS;
	if( (m_status & HM_PHONE_ST1) != 0 )
		ImgDrawItem(IDB_HINT11,ty,posx);
	else if( (m_status & HM_PHONE_ST2) != 0 )
		ImgDrawItem(IDB_HINT12,ty,posx);
	else if( (m_status & HM_PHONE_ST3) != 0 )
		ImgDrawItem(IDB_HINT13,ty,posx);
	else
		ImgDrawItem(IDB_HINT10,ty,posx);
//最新邮件/未读的文字便笺2
	posx += (ICON_SEP+ICON_WIDTH);
	if( (m_status & HM_MAIL_ST1) != 0 )
		ImgDrawItem(IDB_HINT21,ty,posx);
	else if( (m_status & HM_MAIL_ST2) != 0 )
		ImgDrawItem(IDB_HINT22,ty,posx);
	else if( (m_status & HM_MAIL_ST3) != 0 )
		ImgDrawItem(IDB_HINT23,ty,posx);
	else
		ImgDrawItem(IDB_HINT20,ty,posx);
//最新社区公告/未读社区预约回复3
	posx += (ICON_SEP+ICON_WIDTH);
	if( (m_status & HM_BULLET_ST1) != 0 )
		ImgDrawItem(IDB_HINT31,ty,posx);
	else if( (m_status & HM_BULLET_ST2) != 0 )
		ImgDrawItem(IDB_HINT32,ty,posx);
	else if( (m_status & HM_BULLET_ST3) != 0 )
		ImgDrawItem(IDB_HINT33,ty,posx);
	else
		ImgDrawItem(IDB_HINT30,ty,posx);
//最新语音留言/未接的对讲4

⌨️ 快捷键说明

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