mainfrm.cpp

来自「ucOS 模拟环境」· C++ 代码 · 共 845 行 · 第 1/2 页

CPP
845
字号
			InVaild = true;
	}

	if(!InVaild)
	{
		AddPCKey(key);
		ResumeThread( m_pTheThread->m_hThread );
	}
}


void CMainFrame::OnDraw(CDC *pDC, int PowerOn)
{
	CDC bmpDC;
	CBitmap	*pOldBmp, *pNewBmp;
	uchar *pDispBuf, *pBuf, *pMap;
	int bmpw;
	pNewBmp = new CBitmap;
	VERIFY( pNewBmp );
	uint x = 0, y = 0,  width = SCR_WIDTH, height = SCR_HEIGHT;
	
	struct : public BITMAPINFO
	{
		RGBQUAD	bmiOthColors[1];
	}	bmpInfo;
	
	bmpInfo.bmiHeader.biSize				= sizeof( BITMAPINFOHEADER );
	bmpInfo.bmiHeader.biWidth			= XDOTS;
	//bmpInfo.bmiHeader.biWidth			= 480;
	bmpInfo.bmiHeader.biHeight			= -YDOTS;
	bmpInfo.bmiHeader.biPlanes			= 1;
	bmpInfo.bmiHeader.biBitCount		= 1;
	bmpInfo.bmiHeader.biCompression		= BI_RGB;
	bmpInfo.bmiHeader.biSizeImage		= 0;
	bmpInfo.bmiHeader.biXPelsPerMeter	= 0;
	bmpInfo.bmiHeader.biYPelsPerMeter	= 0;
	bmpInfo.bmiHeader.biClrUsed			= 2;
	bmpInfo.bmiHeader.biClrImportant	= 2;
	
	bmpInfo.bmiColors[0].rgbBlue		= 224;//192;
	bmpInfo.bmiColors[0].rgbGreen		= 224;//192;
	bmpInfo.bmiColors[0].rgbRed		= 224;//192;
	bmpInfo.bmiColors[0].rgbReserved	= 0;
	
	bmpInfo.bmiOthColors[0].rgbBlue		= 0;
	bmpInfo.bmiOthColors[0].rgbGreen	= 0;
	bmpInfo.bmiOthColors[0].rgbRed		= 0;
	bmpInfo.bmiOthColors[0].rgbReserved	= 0;
	
	bmpw = SCRW;
	if(bmpw%4)
		bmpw += (4 - (bmpw%4));
	
	pDispBuf =(uchar*)malloc(bmpw * YDOTS);
	VERIFY(pDispBuf);
	
	pBuf = pDispBuf;
	pMap = DispMap;
	for(int i=0; i<YDOTS; i++)
	{
		for(int j=0;j<SCRW;j++)
		{
			uchar ch;
			
			ch = pMap[j];
			
			if(0)//LCDNibFlag)
				ch = (uchar)(((ch>>4) & 0x0f) | ((ch<<4) & 0xf0));
			
			pBuf[j] = ch;
		}
		
		pBuf += bmpw;
		pMap += SCRW;
	}
	
	pNewBmp->CreateCompatibleBitmap(pDC, XDOTS, YDOTS);
	SetDIBits(	pDC->m_hDC, 
		(HBITMAP)pNewBmp->m_hObject, 
		0,
		YDOTS,
		pDispBuf, 
		&bmpInfo,
		DIB_RGB_COLORS);
	
	bmpDC.CreateCompatibleDC( pDC );
	pOldBmp = bmpDC.SelectObject( pNewBmp );

	pDC->StretchBlt(keyboard.m_ScrLeft + x*m_nZoomNum + 2, keyboard.m_ScrTop + y*m_nZoomNum + 2,
		width*m_nZoomNum, height*m_nZoomNum,
		&bmpDC,
		x, y, width, height,
		SRCCOPY);
	
	bmpDC.SelectObject( pOldBmp );
	delete pNewBmp;
	free(pDispBuf);
	
}

void CMainFrame::OnPaint()
{
	CPaintDC Dc(this); // device context for painting
	keyboard.ArrangeScreen(m_nZoomNum);
	OnDraw(&Dc,TRUE);

//	keyboard.DispMark();
}


void CMainFrame::OnTimer(UINT nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
/*
	if( nIDEvent == IDT_1_S && IS_FM_NORMAL)
	{
		if(DelayTimeCounter)
		{
			DelayTimeCounter--;
			if(!DelayTimeCounter)
			{
//				::g_GetSeqKey.AddKey(TIMER);
				ResumeThread( m_pTheThread->m_hThread );
			}
		}
	}

	if(nIDEvent == IDT_BLINK && IS_FM_NORMAL)
	{
		extern uint BlinkTimeCounter;

		if(BlinkTimeCounter)
		{
			BlinkTimeCounter=0;
//			::g_GetSeqKey.AddKey(TIMER);
			ResumeThread( m_pTheThread->m_hThread );
		}
	}

*/	CFrameWnd::OnTimer(nIDEvent);
}

void CMainFrame::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	UCHAR	key=-1;
	if(0)//g_Args.m_bReadKeyFromSeq)
	{
		CFrameWnd::OnSysKeyDown(nChar, nRepCnt, nFlags);
		return;
	}
	switch( nChar )
	{
		case VK_F10:
			OnKeyDown(nChar, nRepCnt, nFlags);
			ResumeThread( m_pTheThread->m_hThread );
			break;
		default	:
			CFrameWnd::OnSysKeyDown(nChar, nRepCnt, nFlags);
	}
}


void CMainFrame::OnZoom2() 
{
	m_nZoomNum=2;
	CalWinPos();
	
}
void CMainFrame::OnZoom1() 
{
	m_nZoomNum=1;
	CalWinPos();
}

void CMainFrame::CalWinPos()
{
	int width, heigth;

	width  = KEYBOARD_W + 40;
	heigth = SCR_HEIGHT*m_nZoomNum + KEYBOARD_H + 100;

	CRect desktopRect;
	GetDesktopWindow()->GetWindowRect( &desktopRect );
	SetWindowPos(	&wndTop,
						( desktopRect.Width() - width  )/2,
						( desktopRect.Height() - heigth)/2,
						width, heigth,	SWP_SHOWWINDOW );
}


void CMainFrame::BeginWaitMouse()
{
	SetCapture();
	hcArrow=GetCursor();
	hcWait=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
	SetCursor(hcWait);
}

void CMainFrame::EndWaitMouse()
{
	SetCursor(hcArrow);
	ReleaseCapture();
}

//------------------------------
//CMyView
CMyView::CMyView()
{
}

CMyView::~CMyView()
{}


BEGIN_MESSAGE_MAP(CMyView, CWnd)
	//{{AFX_MSG_MAP(CMyView)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_PAINT()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDOWN()
	ON_WM_MBUTTONDOWN()
	ON_WM_RBUTTONDBLCLK()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

BOOL CMyView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	BOOL ret;
	ret = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
	m_bmpKeyboard.LoadBitmap(IDB_KEYBOARD);
	return ret;
}

void CMyView::ArrangeScreen( int zoom)
{
   RECT rcView;
	
	GetWindowRect(&rcView);

	int width = rcView.right - rcView.left;
	
	m_ScrLeft	= (width - ED_XDOTS * zoom) / 2 + 6;
	m_ScrTop	= 10;
	m_ScrWidth	= ED_XDOTS * zoom;
	m_ScrHeight = ED_YDOTS * zoom;
	// 	
	CViewerApp		*app	= (CViewerApp *)AfxGetApp();
	app->m_setting.nLedLeft		= m_ScrLeft	;
	app->m_setting.nLedTop		= m_ScrTop	;		
	app->m_setting.nLedHeight	= m_ScrHeight	;	
	app->m_setting.nLedWidth	= m_ScrWidth	;
}


BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	return CWnd::PreCreateWindow(cs);
}

//----------------------------------------------------
void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(0)//!IS_FM_NORMAL)
		CWnd::OnLButtonDown(nFlags, point);
	else
	{
		CWnd::OnLButtonDown(nFlags, point);

		CPoint   pt = GetKeyboardStartPos();
		point.x -= pt.x;
		point.y -= pt.y;
		m_nCurKeyNo = -1;
		for(int i = 0; KeyMapRect[i].m_ulKey != 0xffffffff; i ++)
		{
			if(KeyMapRect[i].m_Rect.PtInRect(point))
			{
				CMainFrame *pMainWnd =	( CMainFrame* )AfxGetApp()->m_pMainWnd;
				ulong key = KeyMapRect[i].m_ulKey;
				GetParent()->SendMessage( WM_KEYDOWN, key, 0 );
				m_nCurKeyNo = i;
				InvertKeyState();
				break;
			}
		}
	}
}

void CMyView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(0)//!IS_FM_NORMAL)
		CWnd::OnLButtonUp(nFlags, point);
	else
	{
		CMainFrame *pMainWnd =	( CMainFrame* )AfxGetApp()->m_pMainWnd;
		InvertKeyState();
		m_nCurKeyNo = -1;
	}
	
}

void CMyView::InvertKeyState()
{
	if(m_nCurKeyNo >=0)
	{
		CRect rc;
		POINT pt;
		
		pt = GetKeyboardStartPos();
		
		rc = KeyMapRect[m_nCurKeyNo].m_Rect;
		rc.left  += pt.x + 1;
		rc.right += pt.x;
		rc.top   += pt.y + 1;
		rc.bottom+= pt.y;
		
		CDC *pDC = GetDC();
		if(pDC)
		{
			pDC->InvertRect(&rc);
			ReleaseDC(pDC);
		}
	}
}

CRect CMyView::GetLcdRect()
{
	CMainFrame *pMainWnd =	( CMainFrame* )AfxGetApp()->m_pMainWnd;
	int nZoomNum=pMainWnd->m_nZoomNum;
	CRect	rect;
	GetWindowRect( &rect );
	CRect rc;
	rc.left=(rect.Width()-SCR_WIDTH*nZoomNum)/2 + 3;
	rc.right=rc.left + SCR_WIDTH*nZoomNum;
	rc.top=10;
	rc.bottom=rc.top + SCR_HEIGHT*nZoomNum;
	return rc;
}
CRect CMyView::GetKeyboardBmpRect(void)
{
   POINT pt;
   BITMAP  bmpinfo;
   m_bmpKeyboard.GetBitmap(&bmpinfo);
   pt.x = (int)(m_ScrLeft + (m_ScrWidth - bmpinfo.bmWidth)/2); 
   pt.y = (int)(m_ScrTop + m_ScrHeight + 10);
   return CRect(pt.x, pt.y, pt.x + bmpinfo.bmWidth, pt.y + bmpinfo.bmWidth);
}
POINT CMyView::GetKeyboardStartPos(void)
{
   POINT pt;
   BITMAP  bmpinfo;
   m_bmpKeyboard.GetBitmap(&bmpinfo);
   pt.x = (int)(m_ScrLeft + (m_ScrWidth - bmpinfo.bmWidth)/2); 
   pt.y = (int)(m_ScrTop + m_ScrHeight + 10);
   return pt;
}
void CMyView::ShowKeyboard(CDC *pDC)
{
   POINT pt;

   pt = GetKeyboardStartPos();

   DrawBitmap(pt.x, pt.y, pDC, &m_bmpKeyboard);
}
void CMyView::DrawLCDBorder(CDC* pDC, int zoom)
{
	int x, y, w, h;
	x = m_ScrLeft - 3;
	y = m_ScrTop - 3;
	w = ED_XDOTS*zoom+6;
	h = ED_YDOTS*zoom+6;
	pDC->Draw3dRect( x, y, w, h, RGB(0, 0, 0), RGB(0, 0, 0));


	x = m_ScrLeft - 4;
	y = m_ScrTop - 4;
	w = ED_XDOTS*zoom+8;
	h = ED_YDOTS*zoom+8;
	pDC->Draw3dRect( x, y, w, h, RGB(128, 128, 128), RGB(255, 255, 255));


	x = m_ScrLeft - 5;
	y = m_ScrTop - 5;
	w = ED_XDOTS*zoom+10;
	h = ED_YDOTS*zoom+10;
	pDC->Draw3dRect( x, y, w, h, RGB(128, 128, 128), RGB(255, 255, 255));


	x = m_ScrLeft - 8;
	y = m_ScrTop - 8;
	w = ED_XDOTS*zoom+16;
	h = ED_YDOTS*zoom+16;
	pDC->Draw3dRect( x, y, w, h, RGB(255, 255, 255), RGB(128, 128, 128));
}


void CMyView::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	dc.SetBkColor(BACKGROUND_COLOR);
	CMainFrame *pMainWnd =	( CMainFrame* )AfxGetApp()->m_pMainWnd;
	int nZoomNum=pMainWnd->m_nZoomNum;
	ArrangeScreen( nZoomNum);
	ShowKeyboard(&dc);
	DrawLCDBorder(&dc,nZoomNum);
}



//------------------------------------------------------------------------------------------

⌨️ 快捷键说明

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