Placing CListControl on Dialog

Placing CListControl on Dialog

Post by Richard We » Thu, 03 Feb 2005 06:02:24


Hi all,
I've got a dialog, and I've derived my own class from CListCtrl adding
my own member functions. I now want to place my ListCtrl on the dialog. I
placed a picture box (IDC_PLACEHOLDER) on the dialog and wrote (In
OnInitDialog):

CStatic* pPlaceHolder = (CStatic*)GetDlgItem(IDC_PLACEHOLDER);
CRect theRect;
(*pPlaceHolder).GetWindowRect(theRect);

When I call the Create method of my ListCtrl I pass theRect as a parameter,
I do this in the dialog's OnInitDialog:

m_ListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL |
LVS_SORTASCENDING, theRect, this, IDC_THELIST);

I was expecting my ListCtrl to be displayed exactly over the top of where I
had drawn the picture box. Unfortunatley the ListCtrl is drawn approximately
half way down the where the picture box is and is shifted slightly to the
right.

What have I done wrong?! I can't figure it out!

Any help would be really appreciated,
Thanks,
Richard.
 
 
 

Placing CListControl on Dialog

Post by Baxte » Thu, 03 Feb 2005 10:11:33

The answer to your question is probably that you need to convert Logical
Coordinates to Device Coordinates. Check out LPToDP().

But why do it the hard way? Just drop a ListCtrl on your dialog, add
a -control- type member variable to it, and then replace the "CListCtrl" in
the dialog header with your derived type.

--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------




parameter,
I
approximately

 
 
 

Placing CListControl on Dialog

Post by Richard We » Thu, 03 Feb 2005 17:38:19

Thanks for the reply Baxter. I'm will try out both methods today, but your
suggestion of replacing CListCtrl in the dialog header is a far better way
of doing it! I'm still very new to MFC (only been doing it a few weeks) so
i'm learning how to do all these things for the first time!

Again thanks for the help,
Rich.



in


adding
I
where
the
 
 
 

Placing CListControl on Dialog

Post by AliR » Fri, 04 Feb 2005 02:03:09

The problem you are facing is due to the fact that GetWindowRect returns
screen corrdinates, you need to call ScreenToClient after GetWindowRect.

But there is a much easier way (window subclassing). Place a regular list
control on the dialog in the resource editor. Then map a variable to it. The
variables type will be CListCtrl. Change the type from CListCtrl to
CMyListCtrl.

class CMyDlg : public CDialog
{
protected:
CMyListCtrl m_ListCtrl;
}

void CMyDlg::DoDataExchange(CDataExchange *pDX)
{
DDX_Control(pDX,IDC_LISTCTRL,m_ListCtrl);
}

AliR.



parameter,
I
approximately