[英]MFC Custom Control draw
我有一個問題。
我做了自定義控制器內部單選按鈕。
但這並不清楚每次繪制(閃爍或重疊)。
所以,問題是
您如何繪制customctrl內部控制器?
抽獎使用CDC? 或內部控制器redraw()? (我用過redraw())
其次是listctrl經常覆蓋內部的單選按鈕。
我如何每次在listctrl上方繪制內部單選按鈕。
這是我的代碼:
vfcxxx:xxx相同
void CCheckListCtrl::DrawItem(_In_ LPDRAWITEMSTRUCT lpDrawItemStruct)
{
int cnt = lpDrawItemStruct->itemID;
static int rownumber = 0;
VfcLong tmpnum = -1;
LONG prev_left = lpDrawItemStruct->rcItem.left;
LV_COLUMN column_data;
memset(&column_data, 0, sizeof(LV_COLUMN));
column_data.mask = LVCF_WIDTH | LVCF_FMT;
for(int column_index = 0; GetColumn(column_index, &column_data); column_index++)
{
RECT tempRC;
{
tempRC.top = lpDrawItemStruct->rcItem.top;
tempRC.bottom = lpDrawItemStruct->rcItem.bottom;
tempRC.left = (prev_left);
tempRC.right = (prev_left += column_data.cx);
}
if (column_index > 1) break;
LV_ITEM tempLI;
wchar_t buffer[256];
{
tempLI.mask = LVIF_TEXT | LVIF_PARAM;
tempLI.iItem = lpDrawItemStruct->itemID;
tempLI.iSubItem = column_index;
tempLI.pszText = buffer;
tempLI.cchTextMax = sizeof(buffer);
VERIFY(GetItem(&tempLI));
}
CString tmpChk = buffer;
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if( (tmpnum = isInsert(defaultGroup, cnt)) != -1)
{
pDC->FillSolidRect(&tempRC, RGB(255, 255, 255));
pDC->SetTextColor(RGB(0, 0, 0));
tempRC.left += 2;
pDC->DrawText(buffer, wcslen(buffer), &tempRC, DT_LEFT);
}
else if( (tmpnum = isInsert(radioGroup, cnt)) != -1)
{
radioCell cell = radioGroup[tmpnum];
pDC->FillSolidRect(&tempRC, RGB(cell.color[0], cell.color[1], cell.color[2]));
pDC->SetTextColor(RGB(125, 125, 125));
tempRC.left += 2;
pDC->DrawText(buffer, wcslen(buffer), &tempRC, DT_LEFT);
}
else
{
pDC->FillSolidRect(&tempRC, RGB(255, 255, 255));
pDC->SetTextColor(RGB(0, 0, 0));
tempRC.left += 2;
pDC->DrawText(buffer, wcslen(buffer), &tempRC, DT_LEFT);
}
}
setVisibleRowNumber();
setVisibleAttrRadioButton(prev_left - column_data.cx/2);
}
VfcVoid CCheckListCtrl::setVisibleRowNumber()
{
visibleMinRow = GetScrollPos(SB_VERT);
visibleMaxRow = visibleMinRow + 12;
}
VfcVoid CCheckListCtrl::setVisibleAttrRadioButton(VfcLong left)
{
VfcLong row;
radioCell cell;
for(int i = 0; i < radioGroup.size(); i++)
{
row = radioGroup[i].row;
cell = radioGroup[i];
if( row >= visibleMinRow && row <= visibleMaxRow)
{
cell.btn->SetWindowPos(NULL, left - 6, (row - visibleMinRow + 1) * 19 + 4, 0, 0, SWP_NOSIZE);
cell.btn->ShowWindow(SW_SHOW);
cell.btn->RedrawWindow();
}
else
{
cell.btn->ShowWindow(SW_HIDE);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.