Talking to CListCtrl that resides in a different process window
-
Suppose that there is a window of another process and that window has a CListCtrl on it , i only have the CWnd pointer of the main window that hosts the CListCtrl, i need to add/remove entries in that CListCtrl, ... My approach is that First i need to first get access to the CListCtrl window by getting its handle using BOOL EnumChildWindows( HWND hWndParent, WNDENUMPROC lpEnumFunc, LPARAM lParam ); and once i get this handle i would either try to get CWnd* from it or try sending LVM_XXX messages using CListCtrl handle... I am unsure about if all this would work ... any of you guys , if have any views please share Ahmed
-
Suppose that there is a window of another process and that window has a CListCtrl on it , i only have the CWnd pointer of the main window that hosts the CListCtrl, i need to add/remove entries in that CListCtrl, ... My approach is that First i need to first get access to the CListCtrl window by getting its handle using BOOL EnumChildWindows( HWND hWndParent, WNDENUMPROC lpEnumFunc, LPARAM lParam ); and once i get this handle i would either try to get CWnd* from it or try sending LVM_XXX messages using CListCtrl handle... I am unsure about if all this would work ... any of you guys , if have any views please share Ahmed
If you have the
CWnd
pointer of the target window (main window, for now), then continuing from there is very, very easy. First, useGetTopWindow
to get the first child window of the main window. Save this into a seperate pointer. Using the returned pointer, first call::GetClassName
to get the class name of the window. SpecifyCWnd::m_hWnd
as theHWND
parameter. If the returned name matches "SysListView32", then thisCWnd
is the list view control. If the name doesn't match, use the child window pointer and callCWnd::GetWindow( GWL_HWNDNEXT )
to retrieve the next window in the chain. When the pointer is returned, useCWnd::IsChild
with the main window pointer to determine if this window is still a child of the target window. If it is, compare the::GetClassName
again with the list view control classname. After you find theCWnd
that a) Is a child of the main window b) Matches the list view control classname, then useDYNAMIC_DOWNCAST
like this:CListCtrl* pListCtrl = DYNAMIC_DOWNCAST( CListCtrl, pMainWindow );
This will give you a pointer to the CListCtrl class of the list control. If the returned value is
NULL
, the cast failed. It shouldn't beNULL
, because theSysListView32
is encapsulated by theCListCtrl
. Remember that your project must be compiled with the Run-Time Type Checking option set to Yes. Otherwise the cast will also fail. Now use the CListCtrl pointer to manipulate the list view control. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.