如何在 MFC 单文档中存储坐标
How to store coordinates in MFC-single-document?
我正在做一个绘图工具的小项目。
我使用线来绘制多边形,所以我使用CList<CPoint,CPoint> m_Points
来存储每条线的终点。
这是我的代码:
void CDrawToolView::OnLButtonUp(UINT nFlags, CPoint point)
{
.
.
.
CList<CPoint,CPoint> m_Points;
m_Points.AddTail(point);
.
.
.
}
我想把这些点传递给一个对话框。在调用函数中:
void CDrawToolView::OnEditProperty()
{
CPropertyDlg dlg;
dlg.Points = m_Points;
if (dlg.DoModal() == IDOK)
{
m_Points = dlg.Points;
}
}
然后在对话框中,单击"确定"时,读取CList<CPoint,CPoint> Points
中的所有点:
void CPropertyDlg::OnBnClickedOk()
{
CList<CPoint,CPoint> Points;
Points.AddTail(polypoint);
POSITION pos = Points.GetHeadPosition();
while( pos != NULL )
{
int i = 0;
element = Points.GetNext(pos);
polygon_x[i] = element.x;
polygon_y[i] = element.y;
i ++;
}
}
运行程序时,CObject::operator =' : cannot access private member declared in class 'CObject'
,如何解决这个问题?
此外,我可以使用此方法将点传递给对话框吗?
m_Points
将 CPropertyDlg 的成员声明为 CList<CPoint,CPoint>*
并将指针传递给此对话框:
void CDrawToolView::OnEditProperty()
{
CPropertyDlg dlg;
dlg.Points = &m_Points;
if (dlg.DoModal() == IDOK)
{
//m_Points = dlg.Points; // not necessary because Points is changed in-place
}
}
现有代码中的问题,即您尝试按值传递CList
,这需要复制整个对象。MFC 作者不允许这样做,方法是将operator=
设为私有。
顺便说一句,如果您正在尝试实现绘图功能,请查看 MFC 示例 DRAWCLI。
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 如何在文档文件夹中创建目录
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 关于类的 Python 文档 - 对C++的引用不正确
- C++/autoconf 等效于文档库要求.txt的要求是什么?
- mbed:使用 USB 文档库编译会导致错误
- C++ VISUAL STUDIO:GLFWwindow没有初始化,即使它是在文档中编写的并且以前工作过
- 使用 yaml-cpp 更新 YAML 文档的节点和值
- 在加载 MSHTML 文档之前从 MSHTML 文档中删除无效的 URL
- 如何在C++中表示JSON文档的递归对象结构?
- 如何查找 Redshift Maya API 文档?
- 如何使用值模板编写文档测试用例?
- 如何使用 Gradle DSL(领域特定语言)上的文档?
- ncurses 找不到任何关于cchar_t的文档
- 在TXT文档的一部分中查找信息并将其存储在变量中
- 将BSONObj对象存储在std::vector中会与大型文档发生冲突
- 如何在 MFC 单文档中存储坐标
- 可嵌入的文档存储数据库
- 如何在MongoDB文档中存储unsigned long (uint64_t)值