Get parent handle ?? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Get parent handle ??

nmgnmg Posts: 4Member
I created an app that use a CSplitterWnd to make 2 pane of class CListView. One of thst pane is set as parent of a modeless dialog box that pop up in some particular conditions.

Inside this modeless dialog box I need to know parent window handle for manipulating list view parent window associated according user choices.

Here is my code:


void CDlgLstAd::OnItemchangedLisact(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if((pNMListView->uNewState & LVIS_SELECTED) == LVIS_SELECTED)
{

// get associated data
long lParam = (long)pNMListView->lParam;

/////////////////////////////////////////////////////
// SOMETHING WRONG HERE ??
//
// get parent window
CListView* pCtrView = (CListView*)GetParent();

// get list ctrl associated
CListCtrl& list = pCtrView->GetListCtrl();
//
////////////////////////////////////////////////////



// find item and select it
LVFINDINFO lvf;
lvf.flags = LVFI_PARAM;
lvf.lParam = lParam;

int idx = list.FindItem(&lvf, -1);
list.SetItemState(idx, LVIS_SELECTED, LVIS_SELECTED);
list.EnsureVisible(idx, FALSE);

}

*pResult = 0;
}

But this code not work.The parent window do not respond. What's wrong ?
Thanks in advance.

Comments

  • BriballBriball Posts: 265Member
    When you create your modeless dialog, do you pass the list view as the parent? The default is NULL. You have to put:

    [code]
    CDialog *pDlg = new CDialog;
    pDlg->Create(IDD_DIALOG, this);
    pDlg->ShowDialog(SW_SHOW);
    //bla bla bla...
    [/code]

    If it still doesn't work you could just make a public variable in the dialog class called m_pParent which points to the list view. Manually set it when the list view is created.
Sign In or Register to comment.