Hello all.
I'm morking on a MSVC MFC Project that uses Allegro.
I have a custom CListCtrl control that inherits CListCtrl's properties.
I have a custom draw method to display it. So, this control has the flags "owner draw fixed" and "owner data".
I also have overriden the virtual function void DrawItem(LPDRAWITEMSTRUCT lpdrawitemstruct) to be able to draw what I like.
Each column can be one of the following types :
Displaying the text (any type except MODELDATATYPE_TEXTURE BITMAP*) is working fine.
But i must be doing something wrong when blitting with blit_to_hdc().
here is the code.
1 | /*-------------------------------------------------------------------------*/ |
2 | /*-------------------------- Draw an item in pDC --------------------------*/ |
3 | /*-------------------------------------------------------------------------*/ |
4 | void CModelListCtrl::DrawItem(LPDRAWITEMSTRUCT lpdrawitemstruct) |
5 | { |
6 | int nItem; |
7 | CDC* pDC; |
8 | char szBuf[64]; |
9 | |
10 | |
11 | nItem = lpdrawitemstruct->itemID; |
12 | pDC = CDC::FromHandle(lpdrawitemstruct->hDC); |
13 | m_HDC = &(lpdrawitemstruct->hDC); |
14 | ASSERT(nItem >= 0); |
15 | |
16 | ASSERT(nItem < m_pModel->m_nNbTextures); |
17 | DrawSubItem(pDC, nItem, 0, MODELDATATYPE_TEXTURE, &nItem); |
18 | DrawSubItem(pDC, nItem, 1, MODELDATATYPE_TEXTUREDIMS, &nItem); |
19 | DrawSubItem(pDC, nItem, 2, MODELDATATYPE_SZ , m_pModel->m_Texs[nItem].szName); |
20 | } |
21 | |
22 | /*-------------------------------------------------------------------------*/ |
23 | /*------------------------------ Draw Sub Item ----------------------------*/ |
24 | /*-------------------------------------------------------------------------*/ |
25 | void CModelListCtrl::DrawSubItem(CDC *pDC, int nItem, int nSubItem, int nDatatype, void* pt) |
26 | { |
27 | CRect rect; |
28 | char szBuf[16]; |
29 | int nIndex; |
30 | |
31 | CListCtrl::GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect); |
32 | |
33 | pDC->FillSolidRect(rect, m_nBackColor); |
34 | |
35 | |
36 | if (pt != NULL) |
37 | { |
38 | // pDC->SaveDC(); |
39 | pDC->SetBkMode(TRANSPARENT); |
40 | pDC->SetTextColor(m_nTextColor); |
41 | rect.left+=2; |
42 | |
43 | switch (nDatatype) |
44 | { |
45 | case MODELDATATYPE_SZ: |
46 | pDC->DrawText((char*)pt, &rect, DT_LEFT | DT_SINGLELINE); |
47 | break; |
48 | |
49 | case MODELDATATYPE_bool: |
50 | pDC->DrawText((*(bool*)pt == 0)?"False":"True", |
51 | &rect, DT_LEFT | DT_SINGLELINE); |
52 | break; |
53 | |
54 | case MODELDATATYPE_FIXED: |
55 | rect.right -= 2; |
56 | sprintf(szBuf, "%2.3f", fixtof(*(fixed*)pt)); |
57 | pDC->DrawText(szBuf, &rect, DT_RIGHT | DT_SINGLELINE); |
58 | break; |
59 | |
60 | case MODELDATATYPE_INT: |
61 | rect.right -= 2; |
62 | sprintf(szBuf, "%d", *(int*)pt); |
63 | pDC->DrawText(szBuf, &rect, DT_RIGHT | DT_SINGLELINE); |
64 | break; |
65 | |
66 | case MODELDATATYPE_TEXTURE: |
67 | nIndex = *(int*)pt; |
68 | if (nIndex >= 0 && nIndex < m_pModel->m_nNbTextures) |
69 | { |
70 | /* |
71 | pDC->BitBlt(rect.left, rect.top, |
72 | MIN(rect.right, m_pModel->m_nTexPreviewDim), |
73 | MIN(rect.bottom, m_pModel->m_nTexPreviewDim), |
74 | CDC::FromHandle(win_get_dc(m_pModel->m_Texs[nIndex].bmpPreview)), |
75 | 0,0, SRCCOPY); |
76 | */ |
77 | |
78 | /* |
79 | set_palette_to_hdc(pDC->m_hDC, NULL); // if I call this it crashes !! |
80 | */ |
81 | blit_to_hdc(m_pModel->m_Texs[nIndex].bmpPreview, |
82 | pDC->m_hDC, |
83 | 0, 0, 0, 0, |
84 | m_pModel->m_nTexPreviewDim, m_pModel->m_nTexPreviewDim); |
85 | |
86 | } |
87 | break; |
88 | |
89 | case MODELDATATYPE_TEXTUREDIMS: |
90 | nIndex = *(int*)pt; |
91 | if (nIndex >= 0 && nIndex < m_pModel->m_nNbTextures) |
92 | { |
93 | sprintf(szBuf, "%d * %d", |
94 | m_pModel->m_Texs[nIndex].bmpImage->w, |
95 | m_pModel->m_Texs[nIndex].bmpImage->h); |
96 | pDC->DrawText(szBuf, &rect, DT_LEFT | DT_SINGLELINE); |
97 | } |
98 | break; |
99 | } |
100 | |
101 | // pDC->RestoreDC(-1); |
102 | } |
103 | } |
Thanks a lot for any help!!
MFC is a lost cause, i hope you dont plan to invest to much in it.
Anyone except AJ knows the trick? (even if it's a lost cause....)
Thank you.
when you dont get much of a reply, i would consider that as a measure of how much everyone has already realized.