www.pudn.com > GOS.rar > Vibration.cpp


// Vibration.cpp: implementation of the CVibration class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Vibration.h" 
#include "math.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
extern USHORT aHalAD[256]; 
 
CVibration::CVibration() 
{ 
	m_nStyle|=WS_MAXIMIZE; 
	m_rectWnd=MakeRect(0,0,GUI_CXSCREEN,GUI_CYSCREEN); 
} 
 
CVibration::~CVibration() 
{ 
 
} 
 
void CVibration::WndProc(int nMessage, int wParam, int lParam) 
{ 
	GWnd* pWnd; 
	switch(nMessage) 
	{ 
	case WM_PAINT: 
		if(wParam & ~ODA_CLIENT)OnNcPaint(); 
		if(wParam & ODA_CLIENT){OnPaint();DrawControls();} 
		break; 
	case WM_DRAWITEM: 
		pWnd=(GWnd*)wParam; 
		OnDrawItem(pWnd,lParam); 
		break; 
	case WM_KICKIDLE: 
		OnIdle(); 
		break; 
	case WM_COMMAND: 
		pWnd=(GWnd*)wParam; 
		if(pWnd==&m_btnWave)OnWave(); 
		break; 
	case WM_CREATE: 
		OnCreate(); 
		break; 
	default: 
		GDialog::WndProc(nMessage, wParam,lParam); 
		break; 
	} 
} 
 
void CVibration::OnCreate() 
{ 
	GDialog::OnCreate(); 
	m_strText="Vib - Õñ¶¯²âÊÔ"; 
 
	AddControl(&m_btnWave,"",BS_OWNERDRAW|WS_CLIENT); 
	m_btnWave.MoveWindow(8,8,305,153); 
	AddControl(&m_lblVol,"µçѹ",0); 
	m_lblVol.MoveWindow(8,184,32,16); 
	AddControl(&m_edtVol,"0.00V",WS_CLIENT|BS_FLAT); 
	m_edtVol.MoveWindow(48,176,73,33); 
	m_edtVol.m_nBackColor=RGB(255,255,255)|EdgeRGB(255,255,255); 
	AddControl(&m_lblSpeed,"תËÙ",0); 
	m_lblSpeed.MoveWindow(128,184,36,16); 
	AddControl(&m_edtSpeed,"0 RPS",WS_CLIENT|BS_FLAT); 
	m_edtSpeed.MoveWindow(168,176,73,33); 
	m_edtSpeed.m_nBackColor=RGB(255,255,255)|EdgeRGB(255,255,255); 
	AddControl(&m_btnConfig,"ÅäÖÃ",0); 
	m_btnConfig.MoveWindow(256,176,53,33); 
} 
 
 
void CVibration::OnConfig() 
{ 
 
} 
 
void CVibration::OnDrawItem(GWnd *pWnd, int nState) 
{ 
	int i,j,x0,x1,x2=0,y0,y1,y2=0; 
	RECT rect=pWnd->m_Rect; 
	SIZE size=pWnd->GetSize(TRUE); 
	int cx,cy; 
 
	if(nState & ODS_GRAYED) 
	{ 
		pWnd->FillRect(rect,RGB(255,255,255),RGB(192,192,192)); 
	} 
	else 
	{ 
		pWnd->FillRect(rect,RGB(255,255,255),RGB(255,255,192)); 
	} 
	pWnd->DrawText("Vib",rect,DT_TOP|DT_RIGHT); 
	x0=pWnd->m_Rect.left; 
	y0=pWnd->m_Rect.bottom; 
	cx=size.cx; 
	cy=size.cy; 
	for(i=0;i<256;i++) 
	{ 
		x1=x2;y1=y2; 
		j=aHalAD[i] & 0xfff; 
		x2=x0+((i*cx)>>8); 
		y2=y0-((j*cy)>>12); 
		if(i)pWnd->Line(x1,y1,x2,y2); 
	} 
} 
 
void CVibration::OnIdle() 
{ 
	if(GetTickCount()%40)return; 
	//if(~rPDATG & 0x10) 
	{ 
		OnWave(); 
		m_btnWave.PostMessage(WM_PAINT,ODA_CLIENT,-1); 
	} 
	 
} 
 
void CVibration::OnWave() 
{ 
	int i,j; 
	double dValue=0; 
	for(i=0;i<256;i++) 
	{ 
		 
		j=(aHalAD[i] & 0xfff)-2048; 
		dValue+=j; 
	} 
	dValue/=i*409.6; 
	m_edtVol.m_strText.Format("%5g",dValue); 
	m_edtVol.PostMessage(WM_PAINT,ODA_CLIENT,-1); 
}