MFC2010如何在对话框类外部对对话框的显示进行UpdateData(FALSE),求高手解答,有代码更好~~
2个回答
展开全部
在CxxxDlg.h
//定义用户消息,不可与系统消息冲突,所以就这样定义
//WM+USER表示用户消息,加100还是加其他值并没多大区别的
#define WM_MYUPDATEDATA WM_USER+100
在线程内
//向主程序框架MainFrm发送消息
//SendMessage第二第三参数可以为其他更多的类型,不局限于此
DWORD RondomLeftThread(CxxxDlg*p)
{
p->SendMessage(WM_MYUPDATEDATA,FALSE);
}
//调用线程的地方
hThread_1=CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)RondomLeftThread,
this,
0,
(unsigned long *)&ThreadID);
在CxxxDlg.cpp内
//关联自定义消息
BEGIN_MESSAGE_MAP(CxxxDlg, CDialog)
//{{AFX_MSG_MAP(CxxxDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_MYUPDATEDATA,OnUpdateMyData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
定义OnUpdateMyData
class CxxxDlg: public CDialog
{
// Construction
public:
CxxxDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CxxxDlg)
enum { IDD = IDD_RANDOM_DIALOG };
HANDLE hThread_1;
HANDLE hThread_2;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CxxxDlg)
protected:
virtualvoid DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CxxxDlg)
virtualBOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
LRESULT OnUpdateMyData(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
void EnableDisplay(int,BOOL);
};
实现OnUpdateMyData
LRESULT CxxxDlg::OnUpdateMyData(WPARAM wParam, LPARAM lParam)
{
UpdateData(wParam);
return 1;
}
//定义用户消息,不可与系统消息冲突,所以就这样定义
//WM+USER表示用户消息,加100还是加其他值并没多大区别的
#define WM_MYUPDATEDATA WM_USER+100
在线程内
//向主程序框架MainFrm发送消息
//SendMessage第二第三参数可以为其他更多的类型,不局限于此
DWORD RondomLeftThread(CxxxDlg*p)
{
p->SendMessage(WM_MYUPDATEDATA,FALSE);
}
//调用线程的地方
hThread_1=CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)RondomLeftThread,
this,
0,
(unsigned long *)&ThreadID);
在CxxxDlg.cpp内
//关联自定义消息
BEGIN_MESSAGE_MAP(CxxxDlg, CDialog)
//{{AFX_MSG_MAP(CxxxDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_MYUPDATEDATA,OnUpdateMyData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
定义OnUpdateMyData
class CxxxDlg: public CDialog
{
// Construction
public:
CxxxDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CxxxDlg)
enum { IDD = IDD_RANDOM_DIALOG };
HANDLE hThread_1;
HANDLE hThread_2;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CxxxDlg)
protected:
virtualvoid DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CxxxDlg)
virtualBOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
LRESULT OnUpdateMyData(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
void EnableDisplay(int,BOOL);
};
实现OnUpdateMyData
LRESULT CxxxDlg::OnUpdateMyData(WPARAM wParam, LPARAM lParam)
{
UpdateData(wParam);
return 1;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询