我想实现的功能是:
鼠标在控件 A 里执行指定操作的时候调用对话框成员函数 B ,由函数 B 实现对 Edit Box 内容的更新
我的代码:
控件 A 的.cpp中
#include "resource.h"
#include "GOPOSDlg.h"
。。
int CBitmapCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
。
CGOPOSDlg m_GoposDlg;
m_GoposDlg.SendCoordinateMessage(point.x , point.y);
delete m_GoposDlg;
。
} 在对话框 GOPOSDlg.cpp中:
void CGOPOSDlg::SendCoordinateMessage(int xc, int yc)
{
m_EDIT_XCoordinates.Format("%d", xc);
m_EDIT_YCoordinates.Format("%d", yc); UpdateData(FALSE);
} 如果不加 UpdateData(FALSE);就正常,如果加了,就会出现如下错误
The thread 0xC4C has exited with code 3 (0x3).
The program 'C:\GOPOS\Debug\GOPOS.exe' has exited with code 3 (0x3). 去掉 UpdateData(FALSE); 加上MssageBox(m_EDIT_XCoordinates)可以显示正确的结果
但为什么就不能 UpdateData(FALSE); 显示呢?
我究竟错在哪了呢?
鼠标在控件 A 里执行指定操作的时候调用对话框成员函数 B ,由函数 B 实现对 Edit Box 内容的更新
我的代码:
控件 A 的.cpp中
#include "resource.h"
#include "GOPOSDlg.h"
。。
int CBitmapCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
。
CGOPOSDlg m_GoposDlg;
m_GoposDlg.SendCoordinateMessage(point.x , point.y);
delete m_GoposDlg;
。
} 在对话框 GOPOSDlg.cpp中:
void CGOPOSDlg::SendCoordinateMessage(int xc, int yc)
{
m_EDIT_XCoordinates.Format("%d", xc);
m_EDIT_YCoordinates.Format("%d", yc); UpdateData(FALSE);
} 如果不加 UpdateData(FALSE);就正常,如果加了,就会出现如下错误
The thread 0xC4C has exited with code 3 (0x3).
The program 'C:\GOPOS\Debug\GOPOS.exe' has exited with code 3 (0x3). 去掉 UpdateData(FALSE); 加上MssageBox(m_EDIT_XCoordinates)可以显示正确的结果
但为什么就不能 UpdateData(FALSE); 显示呢?
我究竟错在哪了呢?
m_GoposDlg.SendCoordinateMessage(point.x , point.y);
delete m_GoposDlg;m_GoposDlg没有调用DoModal函数,没有创建好界面,UpdateData当然会出错了。在m_GoposDlg调用DoModal之后,保存对话框的指针。
m_EDIT_XCoordinates是什么类型的?CString ?
估计是Format的问题,你试试直接m_EDIT_XCoordinates="asdasf";
m_EDIT_YCoordinates="sdsdgsdgsg";
然后UpdateData试试
为什么不能 UpdateData(FALSE) 呀
一碰 UpdateData(FALSE) 就出错
。
The thread 0xC4C has exited with code 3 (0x3).
The program 'C:\GOPOS\Debug\GOPOS.exe' has exited with code 3 (0x3).崩溃呀,请高手帮我想想办法,大感激~!!!
m_GoposDlg.SendCoordinateMessage(point.x , point.y);
delete m_GoposDlg;
//m_EDIT_YCoordinates.Format("%d", yc);
m_GoposDlg.SendCoordinateMessage(point.x , point.y);
delete m_GoposDlg;
改为
SendCoordinateMessage(point.x , point.y);
其他多余的删了,函数本生就在类里面,你再创建个自己的对象干什么啊?
用this->UpdateData(FALSE);也不行一样会报错,呜呜
忘了说一声了,CBitmapCtrl 是我自己改写的一个类,用于在Picture上显示位图用的,这样的一个类也许不能用普通控件来理解吧
以前用普通控件的时候,数据传递操作是很正常的,呜呜
{
(CGOPOSDlg *)GetParent()->SendCoordinateMessage(point.x , point.y);
}试试,不知道行不行
则提示 error C2039: 'SendCoordinateMessage' : is not a member of 'CWnd'其他我用过的类似的还有:
1、CGOPOSDlg* m_GoposDlg;
m_GoposDlg = (CGOPOSDlg*)AfxGetMainWnd()->GetDescendantWindow(IDD_GOPOS_DIALOG);
m_GoposDlg->SendCoordinateMessage(point.x + x_offset, point.y + y_offset);
delete m_GoposDlg;2、m_pa->SendCoordinateMessage(point.x + x_offset, point.y + y_offset);
m_pa是我在CBitmapCtrl类中定义的public指针 :CGOPOSDlg* m_pa;
已经分别在CGOPOSDlg.cpp中的构造和析构函数中用new 申请空间,和delect 删除对象
int CBitmapCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
CGOPOSDlg * a=(CGOPOSDlg *)GetParent();
a->SendCoordinateMessage(point.x , point.y);
}我自己写了一个,没有问题的`~~
我也学会了如何在自己构造的类中调用主窗口函数了,感觉真好
谢谢 livedeal(怀念) ,解决了困扰我一天的问题
请加我为好友,再次感谢
你那个对话框存在吗?