|
It happen to a query from CP user, He wanted to know a way to check/uncheck all children , parent is checked/unchecked . It is WinSDK. In dialog procedure WM_NOTIFY needs to be handled. Again a custom message need to be defined for parent dialog, which checks children of tree item, given its parent.
In parent dialog procedure code goes like this,
case WM_CHECK:
{
BOOL bRet = FALSE;
HTREEITEM hRootItem= (HTREEITEM)wParam;
HTREEITEM hTempItem = NULL;
BOOL bCheck = (BOOL)(lParam);
HTREEITEM hItem = TreeView_GetChild(hTree,hRootItem);
if (hItem == NULL)
{
return bRet;
}
do
{
TVITEM item;
item.mask = TVIF_HANDLE | TVIF_STATE;
item.hItem = hItem;
item.stateMask = TVIS_STATEIMAGEMASK;
item.state = INDEXTOSTATEIMAGEMASK((bCheck ? 2 : 1));
lpResult = SendMessage(hTree,TVM_SETITEM, 0, (LPARAM)(&item));
lpResult = SendMessage(hWnd,WM_CHECK,(WPARAM)hItem,(LPARAM)bCheck );
hTempItem = TreeView_GetNextSibling(hTree,hItem);
hItem = hTempItem ;
}while(hItem);
bRet = TRUE;
return bRet;
}
break;
WM_NOTIFY handler will look like this,
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
TVHITTESTINFO ht = {0};
DWORD dw = 0;
HTREEITEM hParentt= (HTREEITEM)wParam;
if ( pnmh->code == NM_CLICK )
{
DWORD dwpos = GetMessagePos();
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
MapWindowPoints(HWND_DESKTOP, pnmh->hwndFrom, &ht.pt, 1);
TreeView_HitTest(pnmh->hwndFrom, &ht);
if(TVHT_ONITEMSTATEICON & ht.flags)
{
TVITEM tvItem;
tvItem.mask = TVIF_HANDLE ;
tvItem.hItem = ht.hItem;
bREs = TreeView_GetItem(hTree,&tvItem);
bCheck = (BOOL) ((tvItem .state >> 12) -1);
SendMessage(hWnd,WM_CHECK,(WPARAM)ht.hItem,(LPARAM)(!bCheck) );
if (bCheck == FALSE)
{
}
}
}
return TRUE;
}
break;
|
|
|
|
|
Few days back, a poster ask a easy way to convert CString array to CStringArray . Though , I feel this is wiered requirement. Ofcourse, he was concerned about efficiency.And wanted to avoid for loop.CStringArray has no c'tor designed to do this. But, what if we extend the class ? I propsed this solution,
class CStringArrayEx: public CStringArray
{
public:
CStringArrayEx(CString*,size_t);
};
CStringArrayEx::CStringArrayEx(CString* pSrc,size_t size):CStringArray()
{
SetSize(size);
CopyElements(m_pData, pSrc,size);
}
What you think ?
|
|
|
|
|
Do you mind if I use any of the information from your blog page in something that I am working on? I sure will give you a mention.
Never injure a friend, even in jest.
- Marcus Tullius Cicero
|
|
|
|
|
Sure. Its for sharing only. Glad to see that, you find something useful here.
|
|
|
|
|
Just checking your page, good work dude keep posting useful things here my wishes.
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
Posting 1000th post on own page . Wish me luck !
I'll be personality now.
-- modified at 3:50 Monday 5th March, 2007
Its 1500 posts now.
|
|
|
|
|
Cheers buddy!
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|