Access to its caller from a Dialog
-
Hi all, Inside a View class (CChildView), I call CDialog. The Dialog pops up. Now, how can I talk to the CChildView while the Dialog still shows? Say CChildView display a bitmap; in my dialog, I change the zoom parameter to 2x, I want the image to reflex the change immediately in the CChildView. Thank you in advance,
-
Hi all, Inside a View class (CChildView), I call CDialog. The Dialog pops up. Now, how can I talk to the CChildView while the Dialog still shows? Say CChildView display a bitmap; in my dialog, I change the zoom parameter to 2x, I want the image to reflex the change immediately in the CChildView. Thank you in advance,
What about defining an user message (WM_APP + something) and post it/ send it from the dialog to the view?
Fold With Us! What a sad world it would be if everyone said and did only what was easy - Shog9
-
What about defining an user message (WM_APP + something) and post it/ send it from the dialog to the view?
Fold With Us! What a sad world it would be if everyone said and did only what was easy - Shog9
Do I define WM_APP message in View and from Dialog I do: this->SendMessage(WM_DO_STUFF,0,0)? I did that, but it didn't work out. Thanks
-
Do I define WM_APP message in View and from Dialog I do: this->SendMessage(WM_DO_STUFF,0,0)? I did that, but it didn't work out. Thanks
* Is your dialog modal or modeless? * Try to use PostMessage instead of SendMessage you should have in : #define WM_DO_STUFF WM_APP+1 In <myview.h>
BEGIN_MESSAGE_MAP(CMyView, CView) [...] afx_msg LRESULT OnDoStuff(WPARAM wParam, LPARAM lParam); END_MESSAGE_MAP()
In <myview.cpp>BEGIN_MESSAGE_MAP(CMyView, CView) [...] ON_MESSAGE(WM_DO_STUFF, OnDoStuff) END_MESSAGE_MAP() LRESULT CMyView::OnDoStuff(WPARAM wParam, LPARAM lParam) { // do stuff return 0L; }
in <mydialog.cpp> (CMyDialog must know about the view)void CMyDialog::OnActionButton() { ASSERT(m_pMyView); m_pMyView->PostMessage(WM_DO_STUFF); }
HTH,
Fold With Us! What a sad world it would be if everyone said and did only what was easy - Shog9
-
* Is your dialog modal or modeless? * Try to use PostMessage instead of SendMessage you should have in : #define WM_DO_STUFF WM_APP+1 In <myview.h>
BEGIN_MESSAGE_MAP(CMyView, CView) [...] afx_msg LRESULT OnDoStuff(WPARAM wParam, LPARAM lParam); END_MESSAGE_MAP()
In <myview.cpp>BEGIN_MESSAGE_MAP(CMyView, CView) [...] ON_MESSAGE(WM_DO_STUFF, OnDoStuff) END_MESSAGE_MAP() LRESULT CMyView::OnDoStuff(WPARAM wParam, LPARAM lParam) { // do stuff return 0L; }
in <mydialog.cpp> (CMyDialog must know about the view)void CMyDialog::OnActionButton() { ASSERT(m_pMyView); m_pMyView->PostMessage(WM_DO_STUFF); }
HTH,
Fold With Us! What a sad world it would be if everyone said and did only what was easy - Shog9
Thank you K, I finally passed a pointer of MyView to Dialog and access functions in MyView such as Invalidate and other member functions through this pointer. Thanks,
-
* Is your dialog modal or modeless? * Try to use PostMessage instead of SendMessage you should have in : #define WM_DO_STUFF WM_APP+1 In <myview.h>
BEGIN_MESSAGE_MAP(CMyView, CView) [...] afx_msg LRESULT OnDoStuff(WPARAM wParam, LPARAM lParam); END_MESSAGE_MAP()
In <myview.cpp>BEGIN_MESSAGE_MAP(CMyView, CView) [...] ON_MESSAGE(WM_DO_STUFF, OnDoStuff) END_MESSAGE_MAP() LRESULT CMyView::OnDoStuff(WPARAM wParam, LPARAM lParam) { // do stuff return 0L; }
in <mydialog.cpp> (CMyDialog must know about the view)void CMyDialog::OnActionButton() { ASSERT(m_pMyView); m_pMyView->PostMessage(WM_DO_STUFF); }
HTH,
Fold With Us! What a sad world it would be if everyone said and did only what was easy - Shog9
Hi K, I finally passed a MyView pointer to CDialog through constructor. Thus, I can access MyView member functions from CDialog. However, when I clicked OK on the Dialog, the program crashed. My guess is that I don't know how to delete the *pView that I passed to Dialog. I delete it in the contructor Dialog destructor). Any thought? By the way, it is a Modal dialog. Thanks,