Placing CListControl on Dialog - Programmer

This is a discussion on Placing CListControl on Dialog - Programmer ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Placing CListControl on Dialog

  1. Placing CListControl on Dialog

    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.



  2. Re: Placing CListControl on Dialog

    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
    -------------------------------------------------------------------------


    "Richard Webb" wrote in message
    news:2tadnfhtjPn9c2LcRVn-jA@pipex.net...
    > 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.
    >
    >




  3. Re: Placing CListControl on Dialog

    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.

    "Baxter" wrote in message
    news:1100a6ll8luoj70@corp.supernews.com...
    > 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
    > -------------------------------------------------------------------------
    >
    >
    > "Richard Webb" wrote in message
    > news:2tadnfhtjPn9c2LcRVn-jA@pipex.net...
    > > 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.
    > >
    > >

    >
    >




  4. Re: Placing CListControl on Dialog

    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:oDataExchange(CDataExchange *pDX)
    {
    DDX_Control(pDX,IDC_LISTCTRL,m_ListCtrl);
    }

    AliR.

    "Richard Webb" wrote in message
    news:2tadnfhtjPn9c2LcRVn-jA@pipex.net...
    > 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.
    >
    >




+ Reply to Thread