How to call function of Dialog box from custom tree control class?

Hi to all,

               I am creating a dialog based apllication in MFC. In
which I have created my own Tree class derived from CTreeCtrl which
shows all the image files and folders(.bmp,.jpg etc).
     Now my problem is when user selects the file from tree ctrl that
image should be displayed in the dialog box. I tried to call the
function of  dialog box's ShowImages(CString strPath) from tree
controls OnSelectionChanged event handler function but it fails for
assertion  at the time of
CClientDC dc(this); this function.
        Tree is in the same dialog where i want show the Images.

Plz help me.
I m stuck with this problem for 2 days.

thx in advance,
Klic

0
11/30/2006 1:53:44 PM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
456 Views

Similar Articles

[PageSpeed] 57

"Klic" <rohit.turambekar@gmail.com> wrote in message 
news:1164894824.041571.319180@h54g2000cwb.googlegroups.com...
> Hi to all,
>
>               I am creating a dialog based apllication in MFC. In
> which I have created my own Tree class derived from CTreeCtrl which
> shows all the image files and folders(.bmp,.jpg etc).
>     Now my problem is when user selects the file from tree ctrl that
> image should be displayed in the dialog box. I tried to call the
> function of  dialog box's ShowImages(CString strPath) from tree
> controls OnSelectionChanged event handler function but it fails for
> assertion  at the time of
> CClientDC dc(this); this function.
>        Tree is in the same dialog where i want show the Images.
>
> Plz help me.
> I m stuck with this problem for 2 days.
>

Usually problems like this are cleared up by posting a user-defined Windows 
message to the dialog box, which would then call ShowImages().  This delays 
the call to ShowImages() so that it is not called when the tree is handling 
the event.  I'm not sure why that would be an issue, as I don't know much 
about tree controls, but try the Post Message.

-- David


0
dc2983 (3206)
11/30/2006 2:02:39 PM
> Usually problems like this are cleared up by posting a user-defined Windows
> message to the dialog box, which would then call ShowImages().  This delays
> the call to ShowImages() so that it is not called when the tree is handling
> the event.  I'm not sure why that would be an issue, as I don't know much
> about tree controls, but try the Post Message.
>
> -- David

But for that i will need the HWND of the dialog class. How can I get
that handle?
Here is my code for OnSelectionChanged.......

void CDirTreeCtrl::OnSelectionChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

	CString * strPath = new CString();

	//getting the path of selected file
	*strPath = GetFullPath(pNMTreeView->itemNew.hItem);

       	::PostMessage(?????, UWM_FILE_SELCTED,(WPARAM)strPath,0);
	
}

How to get ?????..........

0
11/30/2006 2:35:04 PM
Klic wrote:
> But for that i will need the HWND of the dialog class. How can I get
> that handle?
> Here is my code for OnSelectionChanged.......
> 
> void CDirTreeCtrl::OnSelectionChanged(NMHDR* pNMHDR, LRESULT* pResult)
> {
> 	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
> 
> 	CString * strPath = new CString();
> 
> 	//getting the path of selected file
> 	*strPath = GetFullPath(pNMTreeView->itemNew.hItem);
> 
>        	::PostMessage(?????, UWM_FILE_SELCTED,(WPARAM)strPath,0);
> 	
> }
> 
> How to get ?????..........
> 

GetParent()->PostMessage(UWM_FILE_SELCTED,(WPARAM)strPath,0);

-- 
Scott McPhillips [VC++ MVP]

0
Scott
11/30/2006 2:58:09 PM
"Klic" <rohit.turambekar@gmail.com> wrote in message 
news:1164897304.602301.4870@l12g2000cwl.googlegroups.com...
>
> But for that i will need the HWND of the dialog class. How can I get
> that handle?
> Here is my code for OnSelectionChanged.......
>
> void CDirTreeCtrl::OnSelectionChanged(NMHDR* pNMHDR, LRESULT* pResult)
> {
> NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
>
> CString * strPath = new CString();
>
> //getting the path of selected file
> *strPath = GetFullPath(pNMTreeView->itemNew.hItem);
>
>       ::PostMessage(?????, UWM_FILE_SELCTED,(WPARAM)strPath,0);
>
> }
>

The parent window of your tree control is the dialog:

GetParent()->PostMessage(UWM_FILE_SELCTED,(WPARAM)strPath,0);

is the call you want.

-- David



0
dc2983 (3206)
11/30/2006 3:00:50 PM
If I were doing this I would send a message to the mainframe (or the parent 
where the tree control resides) (or dialog if both of these windows are part 
of the same dialog) and let it update the other control (likely a static 
control) on the dialog.  In other words, I wouldn't have the tree control 
try to talk to a dialog that may or may not be there.  I certainly wouldn't 
have the tree control try to update a control on the dialog directly in any 
case.

I would create a function in the mainframe class that, in turn, knows if the 
dialog is "popped" and sends a message to it to update it's control (in a 
function in the dialog).

Tree -> Sends message to parent
    Parent -> Sends message to dialog
         Dialog -> Updates control

Tom

"Klic" <rohit.turambekar@gmail.com> wrote in message 
news:1164894824.041571.319180@h54g2000cwb.googlegroups.com...
> Hi to all,
>
>               I am creating a dialog based apllication in MFC. In
> which I have created my own Tree class derived from CTreeCtrl which
> shows all the image files and folders(.bmp,.jpg etc).
>     Now my problem is when user selects the file from tree ctrl that
> image should be displayed in the dialog box. I tried to call the
> function of  dialog box's ShowImages(CString strPath) from tree
> controls OnSelectionChanged event handler function but it fails for
> assertion  at the time of
> CClientDC dc(this); this function.
>        Tree is in the same dialog where i want show the Images.
>
> Plz help me.
> I m stuck with this problem for 2 days.
>
> thx in advance,
> Klic
> 


0
tserface (3861)
11/30/2006 3:02:58 PM
Another useful option in addition to what has been mentioned is to use
ON_REFLECT_EX on the parent. That is precisely the purpose of it: to let
parent be in on the game as well.

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Klic" <rohit.turambekar@gmail.com> wrote in message
news:1164894824.041571.319180@h54g2000cwb.googlegroups.com...
> Hi to all,
>
>                I am creating a dialog based apllication in MFC. In
> which I have created my own Tree class derived from CTreeCtrl which
> shows all the image files and folders(.bmp,.jpg etc).
>      Now my problem is when user selects the file from tree ctrl that
> image should be displayed in the dialog box. I tried to call the
> function of  dialog box's ShowImages(CString strPath) from tree
> controls OnSelectionChanged event handler function but it fails for
> assertion  at the time of
> CClientDC dc(this); this function.
>         Tree is in the same dialog where i want show the Images.
>
> Plz help me.
> I m stuck with this problem for 2 days.
>
> thx in advance,
> Klic
>


0
ajaykalra (6842)
12/1/2006 4:44:54 AM
Ajay Kalra wrote:
> Another useful option in addition to what has been mentioned is to use
> ON_REFLECT_EX on the parent. That is precisely the purpose of it: to let
> parent be in on the game as well.
>
> --
> Ajay Kalra [MVP - VC++]
> ajaykalra@yahoo.com
>
>
> "Klic" <rohit.turambekar@gmail.com> wrote in message
> news:1164894824.041571.319180@h54g2000cwb.googlegroups.com...
> > Hi to all,
> >
> >                I am creating a dialog based apllication in MFC. In
> > which I have created my own Tree class derived from CTreeCtrl which
> > shows all the image files and folders(.bmp,.jpg etc).
> >      Now my problem is when user selects the file from tree ctrl that
> > image should be displayed in the dialog box. I tried to call the
> > function of  dialog box's ShowImages(CString strPath) from tree
> > controls OnSelectionChanged event handler function but it fails for
> > assertion  at the time of
> > CClientDC dc(this); this function.
> >         Tree is in the same dialog where i want show the Images.
> >
> > Plz help me.
> > I m stuck with this problem for 2 days.
> >
> > thx in advance,
> > Klic
> >

==================================================================
Thank you very much You all I solved my problem.
Actually i was confused with getting handle.

Klic

0
12/1/2006 5:47:11 AM
Reply:

Similar Artilces: