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

📄 pointinfo.cpp

📁 Visual C++_ 600 编程学习捷径
💻 CPP
字号:
// PointInfo.cpp : implementation file
//

#include "stdafx.h"
#include "Exam2.h"
#include "PointInfo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPointInfo dialog


CPointInfo::CPointInfo(CWnd* pParent /*=NULL*/)
	: CDialog(CPointInfo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPointInfo)
	m_strMouseX = _T("");
	m_strMouseY = _T("");
	//}}AFX_DATA_INIT
	m_pParentWnd = pParent;
}


void CPointInfo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPointInfo)
	DDX_Control(pDX, IDC_POINT_LIST, m_List);
	DDX_Text(pDX, IDC_MOUSE_X, m_strMouseX);
	DDX_Text(pDX, IDC_MOUSE_Y, m_strMouseY);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPointInfo, CDialog)
	//{{AFX_MSG_MAP(CPointInfo)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_CLOSE, OnClose)
	ON_MESSAGE(WM_ADD_POINT, OnAddPoint)
	ON_MESSAGE(WM_MOUSE_CHANGED, OnMouseChanged)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPointInfo message handlers

void CPointInfo::OnDelete() 
{
	//得到列表框中被选中项的索引
	int index = m_List.GetCurSel(); 
	if(index == LB_ERR) //如果没有被选中的项或者出错则返回
		return;
	m_List.DeleteString(index);//从列表框中把选中的项删除

	//向父窗口发送WM_DELETE_POINT消息,并把删除的项的索引index
	//作为消息的lParam参数传递给父窗口
	m_pParentWnd->SendMessage(WM_DELETE_POINT, 0, (LPARAM)index);
}

void CPointInfo::OnClose() 
{
	//隐藏对话框
	ShowWindow(SW_HIDE);
}

void CPointInfo::OnAddPoint(WPARAM wParam, LPARAM lParam)
{
	int x = LOWORD(lParam);//得到添加点的x坐标
	int y = HIWORD(lParam);//得到添加点的y坐标
	
	CString szString;
	szString.Format("(%d, %d)", x, y);//格式化字符串
	m_List.AddString(szString);       //添加到列表框中
}

void CPointInfo::OnMouseChanged(WPARAM wParam, LPARAM lParam)
{
	int x = LOWORD(lParam);//得到鼠标点的x坐标
	int y = HIWORD(lParam);//得到鼠标点的y坐标
	
	//格式化静态文本字符串
	m_strMouseX.Format("x = %d", x);
	m_strMouseY.Format("y = %d", y);

	UpdateData(FALSE); //刷新静态文本显示
}

⌨️ 快捷键说明

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