自定义绘制不适用于Win 8 [英] Custom Draw not working on Win 8

查看:82
本文介绍了自定义绘制不适用于Win 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Windows 8计算机上运行了我们的软件,遇到了自定义绘图功能无法正常工作的问题。自定义绘制在Windows XP和Windows 7上运行正常。我们正在根据每个项目的数据和状态将背景颜色和一些文本更改为粗体。



I用ctreectrl和自定义绘图敲了一个简单的裸骨应用程序,但仍然没有运气。这是测试应用中使用的代码段。



I recently ran our software on a Windows 8 machine and encountered an issue where the custom draw functionality is simply not working. The custom draw works fine on windows XP and windows 7. We are changing background colours and some text to bold in a ctreectrl depending on each items data and state.

I knocked up a simple bare bones app with a ctreectrl and custom draw, but still no luck. This is a code snippet used in the test app.

...
DDX_Control(pDX, IDC_TREE1,m_TreeCtrl);
...
ON_NOTIFY(TVN_GETDISPINFO, IDC_TREE1, &CMyTreeView::OnTvnGetdispinfoTree1)
...
void CMyTreeView::OnNMCustomdrawTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);

   LPNMTVCUSTOMDRAW tvcd = (LPNMTVCUSTOMDRAW) pNMHDR;
   
   // Get the tree control item
   HTREEITEM hItem = (HTREEITEM) (pNMCD->dwItemSpec);
   *pResult = 0;
   if(hItem == NULL)
   {
      return;
   }

   switch(tvcd->nmcd.dwDrawStage)
   {
      case CDDS_PREPAINT:
      {
	 *pResult = (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW);
	 break;
      }
      case CDDS_ITEMPREPAINT:
      {
         if ((tvcd->nmcd.uItemState & CDIS_SELECTED) == CDIS_SELECTED)
         {// Set item text to bold if selected
            m_TreeCtrl.SetItemState(hItem,TVIS_BOLD,TVIS_BOLD);
         }
         else
            m_TreeCtrl.SetItemState(hItem,0,TVIS_BOLD);
         // Set Item background color
         tvcd->clrTextBk = Items.GetAt(
                                    (POSITION)(m_TreeCtrl.GetItemData(hItem))).col;

         *pResult = (CDRF_NOTIFYPOSTPAINT | CDRF_NEWFONT);
	 break;
      }
      case CDDS_ITEMPOSTPAINT:
      {
         *pResult = 0;
         break;
      }
   }
}





此代码显示在Win XP和7下运行时的颜色但是没有获胜8.我通过谷歌和MSDN进行搜索也没有太多运气。任何想法或可能的修复将不胜感激。



This code displays the colours when run under Win XP and 7, but not win 8. I've searched through Google and MSDN with not much luck either. Any thoughts or possible fixes would be greatly appreciated.

推荐答案

我在MSDN论坛上发布了这个问题,建议是调整 hItem == NULL检查,因为 hItem 现在在Windows 8的 CDDS_PREPAINT 阶段实际上是NULL(我假设)所以绘制函数被跳过。



更改以下代码

I posted this question on the MSDN forums and the suggestion was to adjust the hItem == NULL check since hItem now is actually NULL during the CDDS_PREPAINT stage on Windows 8 (i'm assuming) so the draw function gets skipped.

Changed the following code from
if(hItem == NULL)
{
   return;
}





to





to

if(hItem == NULL && tvcd->nmcd.dwDrawStage != CDDS_PREPAINT)
{
   return;
}





它现在可以在Windows 8上正常使用。



It now draws fine on windows 8.


我想在您需要CDRF_DODEFAULT到* pResult的CDDS_ITEMPREPAINT阶段。这就是我通常做的事情。 CDRF_NEWFONT仅在您指定新字体时使用(通过SelectObject())
I think in the CDDS_ITEMPREPAINT stage you need to CDRF_DODEFAULT to *pResult. This is what I usually do. CDRF_NEWFONT is only used when you specified a new font (via SelectObject())


这篇关于自定义绘制不适用于Win 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆