C++ 自定义控件绘图
我有一些问题。C++ 自定义控件绘图,c++,mfc,C++,Mfc,我有一些问题。 我制作了自定义控制器内部单选按钮。 但这并不是每次(眨眼或重叠)都清晰地画出来 所以,问题是这 如何绘制customctrl内部控制器? 使用CDC?或内部控制器重画()?(我习惯于重画()) 第二个是listctrl频繁覆盖的内部单选按钮。 如何每次在listctrl上方绘制内部单选按钮 这是我的代码: vfcxxx:xxx相同 void CCheckListCtrl::DrawItem(_In_ LPDRAWITEMSTRUCT lpDrawItemStruct) {
我制作了自定义控制器内部单选按钮。
但这并不是每次(眨眼或重叠)都清晰地画出来 所以,问题是这
如何绘制customctrl内部控制器?
使用CDC?或内部控制器重画()?(我习惯于重画()) 第二个是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);
}
}
}
void CCheckListCtrl::DrawItem(u In_uLpDrawItemStructlpDrawItemStruct)
{
int cnt=lpDrawItemStruct->itemID;
静态整数行数=0;
VfcLong tmpnum=-1;
LONG prev_left=lpDrawItemStruct->rcItem.left;
LV_列数据;
memset(&column_data,0,sizeof(LV_column));
列_data.mask=LVCF_WIDTH | LVCF_FMT;
for(int column_index=0;GetColumn(column_index和column_data);column_index++)
{
矩形tempRC;
{
tempRC.top=lpDrawItemStruct->rcItem.top;
tempRC.bottom=lpDrawItemStruct->rcItem.bottom;
tempRC.left=(左上角);
tempRC.right=(prev_left+=column_data.cx);
}
如果(列索引>1)中断;
LV_项目模板;
wchar_t缓冲区[256];
{
tempLI.mask=LVIF_TEXT | LVIF_PARAM;
tempLI.iItem=lpDrawItemStruct->itemID;
tempLI.iSubItem=列索引;
tempLI.pszText=缓冲区;
tempLI.cchTextMax=sizeof(缓冲区);
验证(GetItem(&tempLI));
}
CString tmpChk=缓冲区;
CDC*pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
如果((tmpnum=isInsert(defaultGroup,cnt))!=-1)
{
pDC->FillSolidRect(&tempRC,RGB(255、255、255));
pDC->SetTextColor(RGB(0,0,0));
tempRC.left+=2;
pDC->DrawText(缓冲区、wcslen(缓冲区)和tempRC、DT_左);
}
否则如果((tmpnum=isInsert(放射组,cnt))!=-1)
{
放射细胞=放射组[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(缓冲区、wcslen(缓冲区)和tempRC、DT_左);
}
其他的
{
pDC->FillSolidRect(&tempRC,RGB(255、255、255));
pDC->SetTextColor(RGB(0,0,0));
tempRC.left+=2;
pDC->DrawText(缓冲区、wcslen(缓冲区)和tempRC、DT_左);
}
}
setVisibleRowNumber();
设置VisibleAttrRadioButton(上一个左-列数据.cx/2);
}
VfcVoid CCheckListCtrl::setVisibleRowNumber()
{
visibleMinRow=GetScrollPos(SB_VERT);
visibleMaxRow=visibleMinRow+12;
}
VfcVoid CCheckListCtrl::setVisibleAttrRadioButton(VfcLong左)
{
VfcLong行;
放射性细胞;
对于(int i=0;i=visibleInRow和行SetWindowPos(空,左-6,(行-visibleInRow+1)*19+4,0,0,SWP_NOSIZE);
cell.btn->ShowWindow(SW_SHOW);
cell.btn->重画窗口();
}
其他的
{
cell.btn->ShowWindow(SW\u隐藏);
}
}
}
不要在这样的控件中使用控件。你永远不会减少由窗口重叠引起的所有闪烁
自己绘制按钮。CListCtrl也有自己的复选框样式。
这是
甚至在CListCtrl中添加多个复选框都已经成功了。请不要多次询问。