博文

CListCtrl第一列不能居中的问题(2010-03-09 13:43:00)

摘要:把CListCtrl设置为report风格,但是插入第一列的时候(InsertColumn)的时候会发现文字不能居中,即使使用了LVCFMT_CENTER,但是其他列都可以正常居中。
解决方案:
(1)巧妙解决:插入第一列时宽度设置为0,弃之不用。但是这样有问题,凡是与第一列相关的一些设置将发挥不了作用,例如checkbox和icon。
(2)插入第一列后,改变它的参数:
LVCOLUMN   lvc;
lvc.mask   =LVCF_FMT;
m_ctrList.GetColumn(0,&lvc);   
lvc.fmt&=~LVCFMT_JUSTIFYMASK;   
lvc.fmt|=LVCFMT_CENTER;
m_ctrList.SetColumn(0,&lvc); 
(3)插入第一列后,将其删除,第二列此时会充当第一列,已经居中了。。。......

阅读全文(5940) | 评论:1

CListCtrl OnTimer释疑(2009-10-19 16:45:00)

摘要:自认为对CListCtrl够了解了,但是还不够。昨日碰到一古怪问题,在ClistCtrl中设置一个Timer,但是始终OnTimer只进去一次,很纳闷…… 搜索找到了答案: 如果您调用 SetTimer 函数将定期的 WM _ TIMER 消息发送到列表控件时,您可能会发现仅两次调用列表控件的在 WM _ TIMER 消息处理程序 ( OnTimer 函数)。 解决办法: 如果您在 SetTimer 调用中定义计时器 ID,不要 WM _ TIMER 的调用默认处理程序。   参考:http://support.microsoft.com/kb/200054/zh-cn  ......

阅读全文(2252) | 评论:0

CListCtrl滚动条的一些问题搜集(2009-10-16 11:33:00)

摘要:(1)ICON形式中,如果设置属性中对齐方式为LVS_ALIGNTOP,那么当内容容纳不下时,只会出现竖直滚动条(Vertical Scroll) (2)ICON形式中,如果设置属性中对齐方式为LVS_ALIGNLEFT,那么当内容容纳不下时,只会出现水平滚动条(Vertical Scroll) (3)Report形式中,当行容纳不下时,出现竖直滚动条;当列容纳不下时,出现水平滚动条 有些时候,如果要强烈禁止出现水平滚动条或者竖直滚动条,那么可以用下面的方法: void CThumbnailViewList::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
 // TODO: Add your message handler code here and/or call default
 ModifyStyle(WS_HSCROLL,0);   // 强烈禁止
 ShowScrollBar(SB_VERT,1);     //  强烈打开
 CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
} 例如有人碰到这样的问题: Hello. I'm working with a CListCtrl on a property sheet, and am having a problem with window sizing and the scroll bars.When my list grows enough to need a vertical scroll, the window space taken by the vertical scroll causes the Control to also create a horizontal scroll. This works fine, but I'm wondering if there is a way to prevent the horizontal scroll from being there. I'......

阅读全文(8114) | 评论:4

CGridCtrl在VS2008下的使用问题(2009-09-21 11:30:00)

摘要:VC的控件里面是有GridCtrl的,我为了找到扩展性强的,在codeproject上随便下了个控件玩一玩,但是发现VC下CGridCtrl用的好好的,为什么到了VS2008下就用不了了呢?只要一创建就会报错,到底是哪里出了问题?   查看了资料,看看国外友人的解决办法:   I had the following problem with the 2.26 version.

I build an application with VS2008 and 2.26 gridctrl.
When i wanted to run the program on an XP box, the grid did not display correct.
There was no text, and the columns where very big.

I found in this message area a remark.
So i change CGridDefaultCell::CGridDefaultCell()

changed :
ncm.cbSize = sizeof(NONCLIENTMETRICS);
into :
ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth);

After this things worked.

I think this is a bug. 参考资料: 1、http://www.cppblog.com/jerysun0818/archive/2007/05/08/8965.html 2、http://69.10.233.10/KB/miscctrl/gridctrl.aspx......

阅读全文(5254) | 评论:0

Custom Draw ListView Controls(7)(2009-01-20 12:00:00)

摘要:  // do we want to do any drawing after  // the list control is finished  virtual bool IsSubItemPostDraw() { return false; }  // if we are doing the drawing afterwards ourselves  // override and put the code in here  // the return value is not used here  virtual bool OnSubItemPostDraw(CDC* /*pDC*/,                                 int /*nItem*/,                                 int /*nSubItem*/,                                 UINT /*nState*/,        ......

阅读全文(1617) | 评论:2

Custom Draw ListView Controls(6)(2009-01-20 11:53:00)

摘要: // do we want to handle custom draw for  // individual sub items  virtual bool IsNotifySubItemDraw(int /*nItem*/,                                   UINT /*nState*/,                                   LPARAM /*lParam*/)  { return false; }  // do we want to be notified when the  // painting has finished  virtual bool IsNotifyItemPostPaint(int /*nItem*/,                                     UINT /*nState*/,         ......

阅读全文(1446) | 评论:1

Custom Draw ListView Controls(5)(2009-01-20 11:46:00)

摘要: protected:  CFont* m_pOldItemFont;  CFont* m_pOldSubItemFont;  //  // Callbacks for whole control  //  // do we want to do the drawing ourselves?  virtual bool IsDraw() { return false; }  // if we are doing the drawing ourselves  // override and put the code in here  // and return TRUE if we did indeed do  // all the drawing ourselves  virtual bool OnDraw(CDC* /*pDC*/, const CRect& /*r*/)  { return false; }  // do we want to handle custom draw for  // individual items  virtual bool IsNotifyItemDraw() { return false; }  // do we want to be notified when the  // painting has finished  virtual bool IsNotifyPostPaint() { return false; }  // do we want to do any drawing after  // the list control is finished  virtual bool IsPostDraw() { return false; }  // if we are doing the drawing afterwards ourselves  // override and put the code in here ......

阅读全文(1528) | 评论:1

Custom Draw ListView Controls(4)(2009-01-20 11:43:00)

摘要:   case CDDS_ITEMPOSTPAINT:   {    // Item PostPaint    // restore old font if any    if (m_pOldItemFont) {     if (! pDC) pDC = CDC::FromHandle(hdc);     pDC->SelectObject(m_pOldItemFont);     m_pOldItemFont = NULL;    }      // do we want to do any extra drawing?    if (IsItemPostDraw()) {     if (! pDC) pDC = CDC::FromHandle(hdc);      OnItemPostDraw(pDC,nItem,nState,lParam);    }   }   break;     case CDDS_POSTPAINT:   {    // Item PostPaint    // do we want to do any extra drawing?    if (IsPostDraw()) {     if (! pDC) pDC = CDC::FromHandle(hdc);      CRect r(pNMLVCUSTOMDRAW->nmcd.rc);       OnPostDraw(pDC,r);    }   }   break;  }    AS......

阅读全文(1765) | 评论:1

Custom Draw ListView Controls(3)(2009-01-20 11:40:00)

摘要:  case CDDS_ITEMPREPAINT|CDDS_SUBITEM:   {    // Sub Item PrePaint    // set sub item number (data will be valid now)    int nSubItem = pNMLVCUSTOMDRAW->iSubItem;      m_pOldSubItemFont = NULL;      bNotifyPostPaint =     IsNotifySubItemPostPaint(nItem, nSubItem, nState, lParam);      // set up the colors to use    pNMLVCUSTOMDRAW->clrText =     TextColorForSubItem(nItem,nSubItem,nState,lParam);      pNMLVCUSTOMDRAW->clrTextBk =     BkColorForSubItem(nItem,nSubItem,nState,lParam);      // set up a different font to use, if any    CFont* pNewFont =     FontForSubItem(nItem, nSubItem, nState, lParam);      if (pNewFont) {     if (! pDC) pDC = CDC::FromHandle(hdc);      m_pOldSubItemFont = pDC->SelectObject(pNew......

阅读全文(1561) | 评论:1

Custom Draw ListView Controls(2)(2009-01-20 11:38:00)

摘要: The CListCtrlWithCustomDraw Class In the OnCustomdraw for CListCtrlWithCustomDraw, I provide a generic handler for custom draw notifications. The bulk of the code is a switch statement on the draw stage we are up to (refer to my previous article). At each of the pre-paint stages, I call virtual functions to get color information, fonts required, and to take over (or augment) the drawing process. I also allow for extra drawing during the post-paint stages. Let's look at the fleshed out OnCustomdraw function for CListCtrlWithCustomDraw:
void CListCtrlWithCustomDraw::OnCustomdraw(NMHDR* pNMHDR,LRESULT* pResult) {  // first, lets extract data from  // the message for ease of use later  NMLVCUSTOMDRAW* pNMLVCUSTOMDRAW = (NMLVCUSTOMDRAW*)pNMHDR;  // we'll copy the device context into hdc  // but won't convert it to a pDC* until (and if)  // we need it as this requires ......

阅读全文(1820) | 评论:0