|
josip cagalj wrote: Is this requiring for owner drawn fixed
I think by handling the NM_CUSTOMEDRAW notification, we can achive this. There are some sample in the codeproject itself that handles the NM_CUSTOMEDRAW in list ctrl/view. Check them...
modified on Wednesday, October 1, 2008 2:48 AM
|
|
|
|
|
Are you sure I can hilite cell (not entire row) where user clicked just by handling NM_CUSTOMEDRAW notification?
Anyway thanks for your help.
P.S.
How to get row&column info where click occur?
|
|
|
|
|
josip cagalj wrote: Are you sure I can hilite cell
99%
josip cagalj wrote: How to get row&column info where click occur?
First handle the NM_CLICK event. From that function, you can get the row and column in which the user clicked. Save this information in some variable.
The NM_CUSTOMEDRAW, will be sent before the list controls draws each column in the list control. It gives a structure that contains some variables that represent the background color, text color etc of the column to be drawn. You can change the value in those variable and the list control will draw the column with those colors. So what I am saying is, when ever the list control send a NM_CUSTOMEDRAW message and the item and subitem matches the values that we stored in NM_CLICK, change the value of the variable in the structure with the desired one.
|
|
|
|
|
Ok. this is my code
void CIMAPIListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
int cur_col=pDispInfo->item.iItem;
int index = GetNextItem(-1, LVIS_SELECTED);
CString message;
message.Format("Clicked on item: %d,%d",index,cur_col);
AfxMessageBox(message);
*pResult = 0;
}
line int index = GetNextItem(-1, LVIS_SELECTED); always returns -1? It's because LVIS_SELECTED !?
Maybe int HitTest( CPoint pt, UINT* pFlags = NULL ) but how to extract point from NMHDR* pNMHDR or LRESULT* pResult parameters in OnClick method?
modified on Wednesday, October 1, 2008 4:24 AM
|
|
|
|
|
It should be actually like this...
void CIMAPIListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMITEMACTIVATE pListItem = (LPNMITEMACTIVATE)pNMHDR;
LVHITTESTINFO stInfo = {0};
stInfo.pt = pListItem->ptAction;
SubItemHitTest( &stInfo );
m_nRow = stInfo.iItem;
m_nColumn = stInfo.iSubItem;
*pResult = 0;
}
|
|
|
|
|
I've found some code and applied it:
onClick:
void CIMAPIListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW * pLV = reinterpret_cast<nmlistview>(pNMHDR);
LVHITTESTINFO stInfo = {0};
stInfo.pt = pLV->ptAction;
SubItemHitTest( &stInfo );
int nRow = stInfo.iItem;
int nClmn = stInfo.iSubItem;
if (nRow != -1)
{
if (m_nSubItemSelect != nClmn)
{
m_nSubItemSelect = nClmn;
m_nCurrentlySelectedItem = nRow;
CRect rcItem;
GetItemRect(nRow, rcItem, LVIR_BOUNDS);
InvalidateRect(rcItem);
}
}
*pResult = 0;
}</nmlistview>
onCustomDraw:
void CIMAPIListCtrl::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<nmlvcustomdraw*>(pNMHDR);
*pResult = 0;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
CDC* pDC = CDC::FromHandle ( pLVCD->nmcd.hdc );
CRect rct;
GetSubItemRect(m_nCurrentlySelectedItem,m_nSubItemSelect,LVIR_BOUNDS,rct);
if ((m_nSubItemSelect == pLVCD->iSubItem) &&
(GetItemState(pLVCD->nmcd.dwItemSpec, LVIS_SELECTED) == LVIS_SELECTED) &&
m_nCurrentlySelectedItem == pLVCD->nmcd.dwItemSpec )
{
pDC->FillSolidRect ( rct, RGB(0,0,255) );
pDC->SetTextColor(RGB(255,255,255));
}
else
{
pDC->FillSolidRect ( rct, RGB(255,255,255) );
pDC->SetTextColor(RGB(0,0,0));
}
}
}
My code never reaches inside else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM)) this is because I'm setting vrong value with *pResult = CDRF_NOTIFYSUBITEMDRAW; ??
|
|
|
|
|
hmm there is some problem in your code. I have modified it as follows
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
*pResult = CDRF_DODEFAULT;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT )
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
if ( (m_nSubItemSelect == pLVCD->iSubItem) &&
((pLVCD->nmcd.uItemState &CDIS_SELECTED) == CDIS_SELECTED))
{
pLVCD->clrTextBk = RGB(0,0,255);
pLVCD->clrText = RGB(255,255,255);
}
else
{
pLVCD->clrTextBk = RGB(255,255,255);
pLVCD->clrText = RGB(0,0,0);
pLVCD->nmcd.uItemState = pLVCD->nmcd.uItemState& ~CDIS_SELECTED;
}
}
|
|
|
|
|
Nave, thank you very much for helping me!
My code now looks like this:
void CIMAPIListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW * pLV = reinterpret_cast<nmlistview>(pNMHDR);
LVHITTESTINFO stInfo = {0};
if(m_nSubItemSelect != -1 && m_nCurrentlySelectedItem != -1)
{
CRect rcItem;
GetItemRect(m_nCurrentlySelectedItem, rcItem, LVIR_BOUNDS);
InvalidateRect(rcItem);
}
stInfo.pt = pLV->ptAction;
SubItemHitTest( &stInfo );
int nRow = stInfo.iItem;
int nClmn = stInfo.iSubItem;
if(GetItemText(nRow,nClmn)=="") return;
if (nRow != -1)
{
if (m_nSubItemSelect != nClmn)
{
m_nSubItemSelect = nClmn;
m_nCurrentlySelectedItem = nRow;
CRect rcItem;
GetItemRect(nRow, rcItem, LVIR_BOUNDS);
InvalidateRect(rcItem);
}
}
*pResult = 0;
}
void CIMAPIListCtrl::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<nmlvcustomdraw*>(pNMHDR);
*pResult = CDRF_DODEFAULT;
if ( pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
if((m_nSubItemSelect == pLVCD->iSubItem) &&
(pLVCD->nmcd.uItemState & CDIS_SELECTED)==CDIS_SELECTED &&
m_nCurrentlySelectedItem == pLVCD->nmcd.dwItemSpec)
{
pLVCD->clrTextBk = RGB(0,0,255);
pLVCD->clrText = RGB(255,255,255);
}
else
{
pLVCD->clrTextBk = RGB(255,255,255);
pLVCD->clrText = RGB(0,0,0);
pLVCD->nmcd.uItemState = pLVCD->nmcd.uItemState& ~CDIS_SELECTED;
}
}
}
</nmlistview>
The problem is that for hiliting subitem I need first to click on column 0 and then subitem column to work. Exception is when clicking on first row after listctrl is populated!
|
|
|
|
|
josip cagalj wrote: if (nRow != -1) { if (m_nSubItemSelect != nClmn) { m_nSubItemSelect = nClmn; m_nCurrentlySelectedItem = nRow; CRect rcItem; GetItemRect(nRow, rcItem, LVIR_BOUNDS); InvalidateRect(rcItem); } }
I think the checking should be done in the following way...
if (nRow != -1)
{
m_nCurrentlySelectedItem = nRow;
if (m_nSubItemSelect != nClmn)
{
m_nSubItemSelect = nClmn;
m_nCurrentlySelectedItem = nRow;
CRect rcItem;
GetItemRect(nRow, rcItem, LVIR_BOUNDS);
InvalidateRect(rcItem);
}
}
|
|
|
|
|
Now I need to click twice on subitem to hilite it! First time nothing happens.
It works now while clicking in different columns, but when clicked on same column but different row it takes two clicks to hilite it!?
Also when clicking on column 0 only text portion is hilited while on subitem whole cell hilites
modified on Thursday, October 2, 2008 5:43 AM
|
|
|
|
|
OK I've made some corrections and now everything works fine.
Once again big thank to Naveen and others!
The Code Project rocks!
|
|
|
|
|
I think this article is what I need:
|
|
|
|
|
I think this article is what I need (SubItem Selection in List Control):
http://www.codeproject.com/KB/list/SubItemSel.aspx
|
|
|
|
|
Hi all,
I m using a TreeCtrl with CTreeCtrl derived class.
Here i m using a LButtonDown function for get Item Text.
void CTree::OnLButtonDown(UINT nFlags, CPoint point)<br />
{<br />
CTreeView::OnLButtonDown(nFlags, point);<br />
<br />
CTreeCtrl& tc = GetTreeCtrl();<br />
::GetCursorPos(&point);<br />
tc.ScreenToClient(&point);<br />
<br />
UINT uFlags ;<br />
HTREEITEM hItem = tc.HitTest(point, &uFlags);<br />
if ((hItem != NULL) && (TVHT_ONITEM & uFlags))<br />
{<br />
tc.Select(hItem, TVGN_CARET);<br />
}<br />
tc.SelectItem(hItem);<br />
tc.SetFocus(); <br />
CString Tree_str;<br />
Tree_str = tc.GetItemText(hItem);<br />
AfxMessageBox(Tree_str);<br />
<br />
}<br />
<br />
<br />
Here number of items are present.
if i expnd all th item the VScroll display.
if scrollbar displays and i select any item than it prompt a wrong value of item.
i think its happens becoz of position change by VScroll.
Please tell me any solution for this.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
modified on Saturday, October 4, 2008 1:45 AM
|
|
|
|
|
|
Please help me
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
"_$h@nky_" wrote: Please help me
Already helped you no? What's new? did u check those links?
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi Experts,
How can I traverse System Volume Information folder?
|
|
|
|
|
You have to take ownership of the directory and its objects before you can enumerate them. That works on XP, not sure about Vista or 2003.
modified on Tuesday, September 30, 2008 11:40 AM
|
|
|
|
|
|
MPTP wrote: How Can I do that?
I don't know how to do it programmatically, try googling. From the command line you can do it like this:
cacls "[driveletter]:\system volume information" /e /g [username]:f
|
|
|
|
|
Hi All,
I have created a MFC dll with dialog box(It doesn't have any methods.only dialog box).I got sam.dll and sam.lib.Now i want to use this sam.dll to my MFC application.That is,
If i click ok button,It should show that dll dialog.I dont know how to import to my button click event.
Plz... helpme.
Thanks & Regards,
Anitha
|
|
|
|
|
|
Do you want to create Resource only DLL??
If yes you can search CP there are good articles for the same.
Regards,
Sandip.
|
|
|
|
|
Ive seen a lot of applications load icons that seem to be a higher colour rate
the standard is 32x32 16bit color
is there a way to use an icon that is 256 or truecolor
in WINAPI or MFC
cheers
From Sarriss
|
|
|
|