non doc/view app - access to CListCtrl member of ChildView 
Author Message
 non doc/view app - access to CListCtrl member of ChildView

Hello All,
I've created a non Doc/View SDI app w/VC 6.0, I added  CListCtrl m_output to
the ChildView class. I'm to integrate this with some legay C code  (task #2
is to rewrite this legacy code to C++ -another topic)
I need to be able to be able to insert items into the List Control from my C
code.

The following works from within the ChildView but not from the C code?

#define Log(sz) ((CListCtrl*)GetDlgItem (ID_OUTPUT))->InsertItem(0,sz)

Any Ideas?
Hope, I'm making sense, I'm tired as hell.

Thanks In advance,
Tony



Thu, 24 Jul 2003 13:00:11 GMT  
 non doc/view app - access to CListCtrl member of ChildView
Well, your C code is clearly not in any C++ class. Therefore, there is
no method GetDlgItem defined for your C code. You need to call the
base API call, ::GetDlgItem, and since this returns an HWND, not a
object of type CListCtrl, you must provide an HWND as the first
parameter, and then you have to use that as the first parameter for
InsertItem, which is not an API call but a message; that is,
              LVITEM item;
             ... set the item fields
        ::SendMessage(::GetDlgItem(hView, ID_OUTPUT),
                                           LVM_INSERTITEM,
                                           0,
                                           (LPARAM)&item)
Now there are ways to fix this up, for example
        CListCtrl::FromHandle(::GetDlgItem(hView,
ID_OUTPUT))->InsertItem(0, sz);

This also requires you compile the module as a C++ module, even though
the code retains its C nature, that is, rename the file to .cpp.

Note that you can pass a CWnd * to C-like code, so you can pass the
CWnd * to the C module providing you change its extension to .cpp and
compile it as C++ (assuming the compilation works, which it usually
will), e.g.,

void MyCFunction(parmtype whatever)

could be simply rewritten as

void MyCFunction(CWnd * w, parmtype whatever)
   {
    ...
    (CListCtrl *)(w->GetDlgItem(ID_OUTPUT))->InsertItem(0, sz);
   }

                        joe

On Sun, 04 Feb 2001 05:00:11 GMT, "Xcrypto"

Quote:

>Hello All,
>I've created a non Doc/View SDI app w/VC 6.0, I added  CListCtrl m_output to
>the ChildView class. I'm to integrate this with some legay C code  (task #2
>is to rewrite this legacy code to C++ -another topic)
>I need to be able to be able to insert items into the List Control from my C
>code.

>The following works from within the ChildView but not from the C code?

>#define Log(sz) ((CListCtrl*)GetDlgItem (ID_OUTPUT))->InsertItem(0,sz)

>Any Ideas?
>Hope, I'm making sense, I'm tired as hell.

>Thanks In advance,
>Tony

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Thu, 24 Jul 2003 14:12:51 GMT  
 non doc/view app - access to CListCtrl member of ChildView
The Windows SDK has bunches of macros (such as ListView_InsertItem) that can
be used with a window handle, totally independent of MFC.


Quote:
> Hello All,
> I've created a non Doc/View SDI app w/VC 6.0, I added  CListCtrl m_output
to
> the ChildView class. I'm to integrate this with some legay C code  (task
#2
> is to rewrite this legacy code to C++ -another topic)
> I need to be able to be able to insert items into the List Control from my
C
> code.

> The following works from within the ChildView but not from the C code?

> #define Log(sz) ((CListCtrl*)GetDlgItem (ID_OUTPUT))->InsertItem(0,sz)

> Any Ideas?
> Hope, I'm making sense, I'm tired as hell.

> Thanks In advance,
> Tony



Thu, 24 Jul 2003 15:30:17 GMT  
 non doc/view app - access to CListCtrl member of ChildView
Much Thanks!
Tony



Quote:
> Well, your C code is clearly not in any C++ class. Therefore, there is
> no method GetDlgItem defined for your C code. You need to call the
> base API call, ::GetDlgItem, and since this returns an HWND, not a
> object of type CListCtrl, you must provide an HWND as the first
> parameter, and then you have to use that as the first parameter for
> InsertItem, which is not an API call but a message; that is,
>               LVITEM item;
>              ... set the item fields
> ::SendMessage(::GetDlgItem(hView, ID_OUTPUT),
>                                            LVM_INSERTITEM,
>                                            0,
>                                            (LPARAM)&item)
> Now there are ways to fix this up, for example
> CListCtrl::FromHandle(::GetDlgItem(hView,
> ID_OUTPUT))->InsertItem(0, sz);

> This also requires you compile the module as a C++ module, even though
> the code retains its C nature, that is, rename the file to .cpp.

> Note that you can pass a CWnd * to C-like code, so you can pass the
> CWnd * to the C module providing you change its extension to .cpp and
> compile it as C++ (assuming the compilation works, which it usually
> will), e.g.,

> void MyCFunction(parmtype whatever)

> could be simply rewritten as

> void MyCFunction(CWnd * w, parmtype whatever)
>    {
>     ...
>     (CListCtrl *)(w->GetDlgItem(ID_OUTPUT))->InsertItem(0, sz);
>    }

> joe

> On Sun, 04 Feb 2001 05:00:11 GMT, "Xcrypto"

> >Hello All,
> >I've created a non Doc/View SDI app w/VC 6.0, I added  CListCtrl m_output
to
> >the ChildView class. I'm to integrate this with some legay C code  (task
#2
> >is to rewrite this legacy code to C++ -another topic)
> >I need to be able to be able to insert items into the List Control from
my C
> >code.

> >The following works from within the ChildView but not from the C code?

> >#define Log(sz) ((CListCtrl*)GetDlgItem (ID_OUTPUT))->InsertItem(0,sz)

> >Any Ideas?
> >Hope, I'm making sense, I'm tired as hell.

> >Thanks In advance,
> >Tony

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Fri, 25 Jul 2003 02:05:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Control Bar in a non DOC/VIEW app

2. Can I have a Dialog Based Window in an MDI non doc/view app

3. listcontrol in a SDI non doc/view app

4. How to set window title when create a new frame in non Doc/view app

5. Doc/View for app with non-file documents?

6. CListCtrl as child window of a SDI app without MFC Doc/View

7. Accessing a CApp member variable in a doc/view

8. Help with accessing doc/view from app

9. How to Access View methods from Document in MFC DOC/VIEW

10. access to a views member variables from another view

11. Get access to a view's member var from another view using multiple templates

12. ChildView of a ChildView ?

 

 
Powered by phpBB® Forum Software