Click here to Skip to main content
15,900,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VC_2005 exe not running on Windows-2003 Pin
Naveen18-Aug-08 3:47
Naveen18-Aug-08 3:47 
Questionhow to send and receive emoticons/smiley in mfc Pin
Dhiraj kumar Saini17-Aug-08 19:49
Dhiraj kumar Saini17-Aug-08 19:49 
AnswerRe: how to send and receive emoticons/smiley in mfc Pin
Cedric Moonen17-Aug-08 20:43
Cedric Moonen17-Aug-08 20:43 
GeneralRe: how to send and receive emoticons/smiley in mfc Pin
Dhiraj kumar Saini17-Aug-08 22:52
Dhiraj kumar Saini17-Aug-08 22:52 
QuestionHow to making a hidden file Pin
VCProgrammer17-Aug-08 19:04
VCProgrammer17-Aug-08 19:04 
AnswerRe: How to making a hidden file Pin
Jijo.Raj17-Aug-08 19:09
Jijo.Raj17-Aug-08 19:09 
AnswerRe: How to making a hidden file Pin
Hamid_RT18-Aug-08 5:03
Hamid_RT18-Aug-08 5:03 
QuestionHow could I get the parent of an embedded control generically ? Pin
SherTeks17-Aug-08 18:48
SherTeks17-Aug-08 18:48 
I have a dialog-based application that contains a combo box.

I've subclassed the combo box like this :

HBRUSH CSubClassedComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{

      if (nCtlColor == CTLCOLOR_EDIT)
      {
         //[ASCII 160][ASCII 160][ASCII 160]Edit control
         if (m_CmbEditBox.GetSafeHwnd() == NULL)
            m_CmbEditBox.SubclassWindow(pWnd->GetSafeHwnd());
      }
      else if (nCtlColor == CTLCOLOR_LISTBOX)
      {

         //ListBox control
		  if (m_CmbListBox == NULL)
		  {
			  m_CmbListBox = new CListBoxEx;

			  if (m_CmbListBox->GetSafeHwnd() == NULL)
			  {			  
				  m_CmbListBox->SubclassWindow(pWnd->GetSafeHwnd());
			  }
		  }
      }

	HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
	
	return hbr;
}


m_CmbEditBox and m_CmbListBox are objects of CEdit and CListBoxEx(derived from CListBox) respectively
and declared in SubClassedComboBox.h as the class CSubClassedComboBox's members.

During run-time of my application, I pull down the list box and right-click on any of the
list box items. My control reaches here :

void CListBoxEx::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	GetParent->TestFn();	
}


Now, in CListBoxEx::OnContextMenu, I want to call a member function ( say TestFn() ) available in class CSubClassedComboBox.

Please see the following code :

void CListBoxEx::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	((CSubClassedComboBox *)GetParent())->TestFn();	//This works and TestFn() of CSubClassedComboBox is called

	GetParent())->TestFn();		//But this doesn't work
}


As in the comments, the second statement doesn't work. I don't want to cast the pointer returned
by GetParent() to CSubClassedComboBox * bcoz this wouldn't be in generic sense.

By this, I mean to say that GetParent() should be able to give the parent pointer which is
CSubClassedComboBox * in this case, but could be anything else (eg. another container window that contains
the CListBoxEx object).

In summary,

GetParent()->TestFn(); should call TestFn() of CSubClassedComboBox as per the requirement above.

But GetParent())->TestFn(); should be able to call TestFn() of say CSubClassedSomeContainerWindow
if m_ListBox is a member of CSubClassedSomeContainerWindow


So, I am looking for a solution that is generic, to find the parent.

Any help would be appreciated.

Thanks in advance.
AnswerRe: How could I get the parent of an embedded control generically ? Pin
Nibu babu thomas17-Aug-08 19:08
Nibu babu thomas17-Aug-08 19:08 
GeneralRe: How could I get the parent of an embedded control generically ? Pin
Naveen17-Aug-08 19:13
Naveen17-Aug-08 19:13 
GeneralRe: How could I get the parent of an embedded control generically ? Pin
Nibu babu thomas17-Aug-08 19:16
Nibu babu thomas17-Aug-08 19:16 
GeneralRe: How could I get the parent of an embedded control generically ? Pin
SherTeks17-Aug-08 19:28
SherTeks17-Aug-08 19:28 
GeneralRe: How could I get the parent of an embedded control generically ? Pin
Nibu babu thomas17-Aug-08 19:59
Nibu babu thomas17-Aug-08 19:59 
GeneralRe: How could I get the parent of an embedded control generically ? Pin
SherTeks17-Aug-08 21:59
SherTeks17-Aug-08 21:59 
AnswerRe: How could I get the parent of an embedded control generically ? Pin
Naveen17-Aug-08 19:11
Naveen17-Aug-08 19:11 
QuestionWeird stack corruption problem Pin
jozsurf17-Aug-08 18:11
jozsurf17-Aug-08 18:11 
AnswerRe: Weird stack corruption problem Pin
Naveen17-Aug-08 18:22
Naveen17-Aug-08 18:22 
AnswerRe: Weird stack corruption problem Pin
Stephen Hewitt17-Aug-08 18:24
Stephen Hewitt17-Aug-08 18:24 
GeneralRe: Weird stack corruption problem Pin
jozsurf17-Aug-08 18:33
jozsurf17-Aug-08 18:33 
GeneralRe: Weird stack corruption problem Pin
Stephen Hewitt17-Aug-08 18:36
Stephen Hewitt17-Aug-08 18:36 
GeneralRe: Weird stack corruption problem Pin
jozsurf17-Aug-08 19:45
jozsurf17-Aug-08 19:45 
GeneralRe: Weird stack corruption problem Pin
Stephen Hewitt17-Aug-08 19:57
Stephen Hewitt17-Aug-08 19:57 
GeneralRe: Weird stack corruption problem Pin
jozsurf17-Aug-08 20:23
jozsurf17-Aug-08 20:23 
GeneralRe: Weird stack corruption problem Pin
Nibu babu thomas17-Aug-08 18:52
Nibu babu thomas17-Aug-08 18:52 
GeneralRe: Weird stack corruption problem Pin
Stephen Hewitt17-Aug-08 19:49
Stephen Hewitt17-Aug-08 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.