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

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

Author

Message

Xcrypt#1 / 4

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?

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

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

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?

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

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