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

📄 agvdlg.cpp

📁 windows ce 下启动代理程序
💻 CPP
字号:
// agvdlg.cpp : implementation file
//

#include "stdafx.h"
#include "agvdlg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

// Any points on the 4 buttons
CPoint CAgvDialog::m_ptButtons[4] = 
{
	CPoint(40, 186), CPoint(120, 186), CPoint(200, 186), CPoint(280, 186)
};

/////////////////////////////////////////////////////////////////////////////
// CAgvDialog dialog

CAgvDialog::CAgvDialog()
{
	m_nPressedButton = -1;
	m_nPressTicks = 0;
	m_bNotPainted = TRUE;
}

CAgvDialog::CAgvDialog(UINT nID, CWnd* pParent) : 
	CDialog(nID, pParent)
{
	m_nPressedButton = -1;
	m_nPressTicks = 0;
	m_bNotPainted = TRUE;
}

void CAgvDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAgvDialog)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAgvDialog, CDialog)
	//{{AFX_MSG_MAP(CAgvDialog)
	ON_MESSAGE(WM_USER_BUTTON, OnUserButton)
	ON_MESSAGE(WM_QUIT_APP, OnQuitApp)
	ON_WM_TIMER()
	ON_WM_CTLCOLOR()
	ON_WM_CREATE()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_WM_ACTIVATE()
	ON_WM_PAINT()
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CAgvDialog message handlers

BOOL CAgvDialog::OnInitDialog()
{
	m_wParam = 0;
	m_lParam = 0;
	m_brBkgrnd.CreateSolidBrush(m_clrDialog);
	m_brButton.CreateSolidBrush(m_clrButton);
	m_brListBox.CreateSolidBrush(m_clrListBox);
	m_brEdit.CreateSolidBrush(m_clrEdit);

	GetWindowText(m_strText);
	CDialog::OnInitDialog();
	
#if defined _STANDARDSDK
	MoveWindow(0, 0, 320, 282);
#else
	MoveWindow(0, 0, 320, 242);
#endif
	SetTimer(1, 50, NULL);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

BOOL CAgvDialog::Create(UINT nIDTemplate, CWnd* pParentWnd,	COLORREF clrDialog, 
								COLORREF clrButton,
								COLORREF clrListBox,
								COLORREF clrEdit)
{
	m_clrDialog = clrDialog;
	m_clrButton = clrButton;
	m_clrListBox = clrListBox;
	m_clrEdit = clrEdit;
	return CDialog::Create(nIDTemplate, pParentWnd);
}

BOOL CAgvDialog::PreTranslateMessage(MSG* pMsg)
{
	// Capture the button keys
	if (pMsg->message == WM_KEYDOWN)
	{
		switch(pMsg->wParam)
		{
		case VK_F1:
			PressButton(0);
			return TRUE;
			
		case VK_F2:
			PressButton(1);
			return TRUE;
			
		case VK_F3:
			PressButton(2);
			return TRUE;
			
		case VK_F4:
			PressButton(3);
			return TRUE;
			
		case VK_ESCAPE:
			OnEscape();
			return TRUE;

		case VK_INSERT:
			OnInsert();
			return TRUE;
			
		case VK_F9:
			OnF9();
			return TRUE;
		}
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

//
//   Show the specified button in pressed state.
//
void CAgvDialog::PressButton(int nButtonID)
{
	CPoint& pt = m_ptButtons[nButtonID];
	CButton* pButton = (CButton*)ChildWindowFromPoint(pt);
	ASSERT(pButton != NULL);

	if (pButton->IsWindowEnabled())
	{
		m_nPressedButton = nButtonID;
		pButton->SetState(TRUE);
	}
}

//
//   Show the specified button in released state, then send button message to 
//   the dialog.
//
void CAgvDialog::ReleaseButton(int nButtonID)
{
	CPoint& pt = m_ptButtons[nButtonID];
	CButton* pButton = (CButton*)ChildWindowFromPoint(pt);
	ASSERT(pButton != NULL);

	pButton->SetState(FALSE);
	
	// Post button key message when the button is "released"
	PostMessage(WM_USER_BUTTON, nButtonID, 0);
}

void CAgvDialog::OnTimer(UINT nIDEvent)
{
	if (nIDEvent == 1)
	{
		// If some button key has been pressed
		if (m_nPressedButton >= 0)
		{
			// Delay for 2 cycles (about 110ms)
			if (m_nPressTicks++ == 2)
			{
				// Show the button released
				ReleaseButton(m_nPressedButton);
				
				// Clear the button key
				m_nPressedButton = -1;
				m_nPressTicks = 0;
			}
		}
	//	if (GetActiveWindow() != this)
	//		KillTimer(1);
	}
	
	CDialog::OnTimer(nIDEvent);
}

LRESULT CAgvDialog::OnChildClosed(WPARAM wParam, LPARAM lParam)
{
	SetTimer(1, 50, NULL);
	return 0L;
}

BOOL CAgvDialog::OnNcActivate(BOOL bActive)
{
	return TRUE; 
}

void CAgvDialog::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);
}

void CAgvDialog::PostNcDestroy()
{
	CDialog::PostNcDestroy();
	delete this;
}

LRESULT CAgvDialog::OnUserButton(WPARAM wParam, LPARAM /*lParam*/)
{
	switch(wParam)
	{
	case 0:
		OnButton1();
		break;
		
	case 1:
		OnButton2();
		break;
		
	case 2:
		OnButton3();
		break;
		
	case 3:
		OnButton4();
		break;
	}
	                                                       
	return 0L;
}

HBRUSH CAgvDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	switch(nCtlColor)
	{
	case CTLCOLOR_DLG:
		hbr = (HBRUSH)m_brBkgrnd.GetSafeHandle();
		pDC->SetBkColor(CLR_GRAY);
		break;
	
	case CTLCOLOR_STATIC:
		hbr = (HBRUSH)m_brBkgrnd.GetSafeHandle();
		pDC->SetBkColor(m_clrDialog);
		break;
		
	case CTLCOLOR_EDIT:
		hbr = (HBRUSH)m_brEdit.GetSafeHandle();
		pDC->SetBkColor(m_clrEdit);
		break;

	case CTLCOLOR_LISTBOX:
		hbr = (HBRUSH)m_brListBox.GetSafeHandle();
		pDC->SetBkColor(m_clrListBox);
		break;

	case CTLCOLOR_BTN:
		hbr = (HBRUSH)m_brButton.GetSafeHandle();
		pDC->SetBkColor(m_clrButton);
		break;
	}
	
	return hbr;
}

LRESULT CAgvDialog::OnQuitApp(WPARAM wParam, LPARAM lParam)
{
	CWnd* pParentWnd = GetParent();
	
	if (pParentWnd == NULL)
	{
		//PostQuitMessage(0);
		DestroyWindow();
	}
	else
	{
		::PostMessage(pParentWnd->m_hWnd, WM_QUIT_APP, 0, 0);
		DestroyWindow();
	}
	return 0L;
}

void CAgvDialog::OnDestroy() 
{
	CWnd* pParentWnd = GetParent();
	if (pParentWnd != NULL)
		::PostMessage(pParentWnd->m_hWnd, WM_CHILD_CLOSED, m_wParam, m_lParam);
	CDialog::OnDestroy();
}

void CAgvDialog::SetTitleString(CString strTitle)
{
	m_strText = strTitle;
	Invalidate();
}

void CAgvDialog::OnPaint()
{
/*
	CClientDC dc(this);
	CPen pen(PS_SOLID, 5, CLR_GREEN);
	dc.SelectObject(&pen);
	
	dc.MoveTo(0, 0);
	dc.LineTo(100, 100);
	
	CRect r;
	GetClientRect(&r);
	r.bottom -= 40;
	
	
	CBrush br(CLR_RED);
	dc.FrameRect(r, &br);
	r.InflateRect(-1, -1);
	dc.FrameRect(r, &br);
*/	
	CDialog::OnPaint();
}

⌨️ 快捷键说明

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