In a C++ app, I have an hWnd pointing to a window running in a third party process. This window contains controls which extend the COM TreeView control. I am interested in obtaining the CheckState of this control.
I use the hWnd to get an HTREEITEM using TreeView_GetRoot(hwnd) from commctrl.h
hwnd points to the window and hItem is return value from TreeView_GetRoot(hwnd). They are used as follows:
int iCheckState = TreeView_GetCheckState(hwnd, hItem); switch (iCheckState) { case 0: // (unchecked) case 1: // checked ... }
I’m looking to port this code into a C# app which does the same thing (switches off the CheckState of the TreeView control). I have never used COM and am quite unfamiliar.
I have tried using the .NET mscomctl but can’t find equivalent methods to TreeView_GetRoot or TreeView_GetCheckState. I’m totally stuck and don’t know how to recreate this code in C# 🙁
Suggestions?
We have these definitions from CommCtrl.h:
We can translate this to C# using PInvoke. First, we implement these macros as functions, and then add whatever other support is needed to make those functions work. Here is my first shot at it. You should double check my code especially when it comes to the marshalling of the struct. Further, you may want to Post the message cross-thread instead of calling SendMessage.
Lastly, I am not sure if this will work at all since I believe that the common controls use WM_USER+ messages. When these messages are sent cross-process, the data parameter’s addresses are unmodified and the resulting process may cause an Access Violation. This would be a problem in whatever language you use (C++ or C#), so perhaps I am wrong here (you say you have a working C++ program).