自绘listbox 显示汉字的问题 请别人 自绘了个 listbox 绘成了 能调整高度颜色的 表格 来显示数据,可是 我调试的时候 发现 却不能显示汉字,不知道应该怎么解决这个问题!??那个自绘的人 我一直没联系上,而老板又催的紧,希望各位帮帮我啊@! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一开始给我的就是 英文演示,因为我刚毕业,没想到现实 汉字的问题 所以我也没多想!这是 效果,空白的地方时有汉字的!可是没显示出来! CTextInfo* pTI = pli->CreateTextInfo(); TextItem ti; ti.m_crText = RGB(0, 0, 0); ti.m_strText = "发生地方按时发生大21\n\n12738123\n"; pTI->AddTextItem(ti); ti.m_crText = RGB(0, 0, 0); ti.m_strText = "发生地方按时发生大啊啊啊啊aaaaaaa"; pTI->AddTextItem(ti); pli->SetSubItem(i, pTI, TRUE, t* 10 + i);这是 显示的代码!typedef struct tagTextItem{ CString m_strText; COLORREF m_crText;}TextItem;这是定义 ti.m_strText = _T("发生地方按时发生大21\n\n12738123\n");ti.m_strText = _T("发生地方按时发生大啊啊啊啊aaaaaaa"); void CListBoxItem::SetSubItem(int i, CTextInfo* pTextInfo, BOOL bClick, int nID){ std::map<int, ListSubItem>::iterator itCur = m_mapListSubItem.find(i); if ( itCur != m_mapListSubItem.end() ) { if ( itCur->second.nType == 0 ) { delete itCur->second.pTextInfo; } } ListSubItem subItem; subItem.nType = 0; subItem.pTextInfo = pTextInfo; subItem.hBitmap = NULL; subItem.bClick = bClick; subItem.nID = nID; m_mapListSubItem[i] = subItem;}你看是这里么? 去ListBox的自绘代码里,把OnDrawItem函数之类的贴出来。或则尝试把工程弄成Unicode代码。 void CListBoxEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct){ // TODO: 添加您的代码以绘制指定项// CDC dc;// dc.Attach(lpDrawItemStruct->hDC); CDC dc; dc.CreateCompatibleDC(CDC::FromHandle(lpDrawItemStruct->hDC)); CBitmap bmp; bmp.CreateCompatibleBitmap(CDC::FromHandle(lpDrawItemStruct->hDC), lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top); CBitmap* pOldBmp = dc.SelectObject(&bmp); CFont* pFont = GetFont(); CFont* pOldFont = dc.SelectObject(pFont); if ( m_nSelIndex == lpDrawItemStruct->itemID ) { dc.FillSolidRect(0, 0, lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top, m_crSelColor); } else { dc.FillSolidRect(0, 0, lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top, m_crBk); } if ( m_bGridLine ) { CPen pen(PS_SOLID, 1, m_crGridColor); CPen* pOldPen = dc.SelectObject(&pen); dc.MoveTo(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - 1 - lpDrawItemStruct->rcItem.top); dc.LineTo(lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom - 1 - lpDrawItemStruct->rcItem.top); std::vector<int>::iterator itLeft = m_vecColumnWidth.begin(); std::vector<int>::iterator itRight = m_vecColumnWidth.end(); int nLeft = 0; int nRight = lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left; BOOL bLeft = TRUE; while ( itLeft != itRight ) { nLeft += *itLeft; dc.MoveTo(nLeft, 0); dc.LineTo(nLeft, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top); itLeft ++; } dc.SelectObject(pOldPen); } if ( lpDrawItemStruct->itemID != -1 ) { CListBoxItem* pListBoxItem = (CListBoxItem*)GetItemData(lpDrawItemStruct->itemID); if ( pListBoxItem != NULL ) { DrawItem(&dc, pListBoxItem, lpDrawItemStruct); } GetParent()->PostMessage(UM_SHOWITEM, lpDrawItemStruct->itemID); } ::BitBlt(lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top, lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top, dc.m_hDC, 0, 0, SRCCOPY); dc.SelectObject(pOldBmp); dc.SelectObject(pOldFont);// dc.Detach();}这个应该怎么弄,能具体些么? CListBoxItem里面是否有DrawItem还有可能是CListBoxItem* pListBoxItem = (CListBoxItem*)GetItemData(lpDrawItemStruct->itemID); if ( pListBoxItem != NULL ) { DrawItem(&dc, pListBoxItem, lpDrawItemStruct); }里面的DrawItem,你看看是否有显示文本的地方!贴出来 上面我不是把 void CListBoxEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)的代码贴了么?这个应该怎么判断?我没找到 void CListBoxEx::SetListBoxItemData(int nIndex, CListBoxItem* pListBoxItem){ CListBoxItem* pLBI = (CListBoxItem*)GetItemData(nIndex); if ( pLBI != NULL ) { delete pLBI; } SetItemData(nIndex, (unsigned long)pListBoxItem); AdjustItemHeight(nIndex); Invalidate(); UpdateWindow();} [email protected]那我就试一下! DrawItem(&dc, pListBoxItem, lpDrawItemStruct);三个参数的绘制DrawItem函数没有贴。DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) ==> DrawItem(&dc, pListBoxItem, lpDrawItemStruct);把工程弄成Unicode代码,VC6的话在工程编译选项上加上 _UNICODE,UNICODE定义,然后根据MSDN说明改入口点mainCRTStartup->wmainCRTStartupmain->wmain WinMainCRTStartup->wWinMainCRTStartupVS2003以上只要常规里的字符集选上Unicode即可。最后后把字符串处理代码全部改成TCHAR和适应函数。(编译错误解决的话,就解决了80%的适应问题,剩下20%要看调试和经验了。) 看了,给我TextItem类的定义与实现,汉字本来两个字节,可能是你们分开显示了 unicode 这块不行,我已经做了很大量的 工作了,再修改太费时间和精力了,typedef struct tagDRAWITEMSTRUCT { UINT CtlType; UINT CtlID; UINT itemID; UINT itemAction; UINT itemState; HWND hwndItem; HDC hDC; RECT rcItem; DWORD itemData;} DRAWITEMSTRUCT, NEAR *PDRAWITEMSTRUCT, FAR *LPDRAWITEMSTRUCT;class CListBoxItem{ friend class CListBoxEx;public: CTextInfo* CreateTextInfo(); void SetSubItem(int i, CTextInfo* pTextInfo, BOOL bClick = FALSE, int nID = 0); void SetSubItem(int i, HBITMAP hBitmap, int nLeft, int nTop, BOOL bClick = FALSE, int nID = 0); BOOL GetSubItem(int i, ListSubItem& listSubItem); int GetHeight(CDC* pDC, int* pWidthArr, int n); ~CListBoxItem();private: int GetSubItemHeight(CDC* pDC,int nIndex, int nWidth); std::map<int, ListSubItem> m_mapListSubItem; std::map<int, CRect> m_mapIDToRect;}; 已经将改动的那个文件,发到你的MAIL里面了,你可以替换这个文件试试了! 令为你开了80 分的帖子!如下fandh (好了)为了感谢你!再加80分,谢谢!结贴完好像又反给了我点分!呵呵! 求助,等高手指点 软件运行错误,必须强制关机 才能关掉软件 向你寻求实时处理程序 自绘滚动条疑问很多 VC2005如何设置禁止用户更改桌面 csdn?? 请问如何让属性表CPropertySheet充满整个CFormView窗口? 要分的进来,急人啊! Image使用方法 如何构造一组包含不同类型的数据?送分题!!! 求助WaitForSingleObject线程超时问题 使用OpengL 怎么样在一个填充的平面上画虚线网格
这是 效果,空白的地方时有汉字的!可是没显示出来!
CTextInfo* pTI = pli->CreateTextInfo();
TextItem ti;
ti.m_crText = RGB(0, 0, 0);
ti.m_strText = "发生地方按时发生大21\n\n12738123\n";
pTI->AddTextItem(ti);
ti.m_crText = RGB(0, 0, 0);
ti.m_strText = "发生地方按时发生大啊啊啊啊aaaaaaa";
pTI->AddTextItem(ti);
pli->SetSubItem(i, pTI, TRUE, t* 10 + i);
这是 显示的代码!
typedef struct tagTextItem
{
CString m_strText;
COLORREF m_crText;
}TextItem;这是定义
ti.m_strText = _T("发生地方按时发生大啊啊啊啊aaaaaaa");
{
std::map<int, ListSubItem>::iterator itCur = m_mapListSubItem.find(i);
if ( itCur != m_mapListSubItem.end() )
{
if ( itCur->second.nType == 0 )
{
delete itCur->second.pTextInfo;
}
} ListSubItem subItem;
subItem.nType = 0;
subItem.pTextInfo = pTextInfo;
subItem.hBitmap = NULL;
subItem.bClick = bClick;
subItem.nID = nID; m_mapListSubItem[i] = subItem;
}
你看是这里么?
或则尝试把工程弄成Unicode代码。
{ // TODO: 添加您的代码以绘制指定项
// CDC dc;
// dc.Attach(lpDrawItemStruct->hDC);
CDC dc;
dc.CreateCompatibleDC(CDC::FromHandle(lpDrawItemStruct->hDC));
CBitmap bmp;
bmp.CreateCompatibleBitmap(CDC::FromHandle(lpDrawItemStruct->hDC),
lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top);
CBitmap* pOldBmp = dc.SelectObject(&bmp);
CFont* pFont = GetFont();
CFont* pOldFont = dc.SelectObject(pFont); if ( m_nSelIndex == lpDrawItemStruct->itemID )
{
dc.FillSolidRect(0, 0,
lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top,
m_crSelColor);
}
else
{
dc.FillSolidRect(0, 0,
lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top,
m_crBk);
} if ( m_bGridLine )
{
CPen pen(PS_SOLID, 1, m_crGridColor);
CPen* pOldPen = dc.SelectObject(&pen);
dc.MoveTo(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - 1 - lpDrawItemStruct->rcItem.top);
dc.LineTo(lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom - 1 - lpDrawItemStruct->rcItem.top); std::vector<int>::iterator itLeft = m_vecColumnWidth.begin();
std::vector<int>::iterator itRight = m_vecColumnWidth.end();
int nLeft = 0;
int nRight = lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left;
BOOL bLeft = TRUE;
while ( itLeft != itRight )
{
nLeft += *itLeft;
dc.MoveTo(nLeft, 0);
dc.LineTo(nLeft, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top);
itLeft ++;
} dc.SelectObject(pOldPen);
} if ( lpDrawItemStruct->itemID != -1 )
{
CListBoxItem* pListBoxItem = (CListBoxItem*)GetItemData(lpDrawItemStruct->itemID);
if ( pListBoxItem != NULL )
{
DrawItem(&dc, pListBoxItem, lpDrawItemStruct);
} GetParent()->PostMessage(UM_SHOWITEM, lpDrawItemStruct->itemID);
} ::BitBlt(lpDrawItemStruct->hDC,
lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top,
lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top,
dc.m_hDC, 0, 0, SRCCOPY); dc.SelectObject(pOldBmp);
dc.SelectObject(pOldFont);
// dc.Detach();
}这个应该怎么弄,能具体些么?
还有可能是
CListBoxItem* pListBoxItem = (CListBoxItem*)GetItemData(lpDrawItemStruct->itemID);
if ( pListBoxItem != NULL )
{
DrawItem(&dc, pListBoxItem, lpDrawItemStruct);
}
里面的DrawItem,你看看是否有显示文本的地方!贴出来
的代码贴了么?
这个应该怎么判断?我没找到
{
CListBoxItem* pLBI = (CListBoxItem*)GetItemData(nIndex);
if ( pLBI != NULL )
{
delete pLBI;
} SetItemData(nIndex, (unsigned long)pListBoxItem);
AdjustItemHeight(nIndex);
Invalidate();
UpdateWindow();
}
那我就试一下!
==> DrawItem(&dc, pListBoxItem, lpDrawItemStruct);
把工程弄成Unicode代码,VC6的话在工程编译选项上加上 _UNICODE,UNICODE定义,然后根据MSDN说明改入口点
mainCRTStartup->wmainCRTStartup
main->wmain
WinMainCRTStartup->wWinMainCRTStartupVS2003以上只要常规里的字符集选上Unicode即可。最后后把字符串处理代码全部改成TCHAR和适应函数。(编译错误解决的话,就解决了80%的适应问题,剩下20%要看调试和经验了。)
UINT CtlType;
UINT CtlID;
UINT itemID;
UINT itemAction;
UINT itemState;
HWND hwndItem;
HDC hDC;
RECT rcItem;
DWORD itemData;
} DRAWITEMSTRUCT, NEAR *PDRAWITEMSTRUCT, FAR *LPDRAWITEMSTRUCT;
class CListBoxItem
{
friend class CListBoxEx;
public:
CTextInfo* CreateTextInfo();
void SetSubItem(int i, CTextInfo* pTextInfo, BOOL bClick = FALSE, int nID = 0);
void SetSubItem(int i, HBITMAP hBitmap, int nLeft, int nTop, BOOL bClick = FALSE, int nID = 0);
BOOL GetSubItem(int i, ListSubItem& listSubItem);
int GetHeight(CDC* pDC, int* pWidthArr, int n);
~CListBoxItem();
private:
int GetSubItemHeight(CDC* pDC,int nIndex, int nWidth);
std::map<int, ListSubItem> m_mapListSubItem;
std::map<int, CRect> m_mapIDToRect;
};