void TreeDlg::OnExpandOrCollapse() { CTreeCtrl *ctrl = getTreeCtrl(); HTREEITEM item = ctrl->GetSelectedItem(); UINT state; if((state = ctrl->GetItemState(item, TVIS_EXPANDED)) & TVIS_EXPANDED) { OnCollapse(); } else { OnExpand(); } }
// @pymethod (int,int)|PyCTreeCtrl|GetItemState|Retrieves the state and mask of an item. // @pyparm HTREEITEM|item||The specified item // @pyparm int|stateMask||The mask for the result. PyObject *PyCTreeCtrl_GetItemState( PyObject *self, PyObject *args ) { PyObject *obItem; UINT stateMask; if (!PyArg_ParseTuple( args, "Ok:GetItemState", &obItem, &stateMask)) return NULL; CTreeCtrl *pList = GetTreeCtrl(self); if (!pList) return NULL; HTREEITEM item; if (!PyWinObject_AsHANDLE(obItem, (HANDLE *)&item)) return NULL; GUI_BGN_SAVE; long state = pList->GetItemState(item, stateMask); GUI_END_SAVE; return PyInt_FromLong(state); }