From this post , I have set up the code by putting in the OnInitDialog
event:
LITEM* pItem = new LITEM;
pItem->iLink = 0; // Url index is 0
//LIF_ITEMINDEX is required for iLink, LIF_STATE is required for modifing state
pItem->mask = LIF_ITEMINDEX | LIF_STATE;
//using LIS_DEFAULTCOLORS state
pItem->state = LIS_ENABLED | LIS_FOCUSED | LIS_DEFAULTCOLORS;
pItem->stateMask = LIS_ENABLED | LIS_FOCUSED | LIS_DEFAULTCOLORS;
// Send the LM_SETITEM MESSAGE with pItem
HWND m_hWnd=nil; GetDlgItem(IDC_lbstackoverflow, &m_hWnd);
And from OnCtrlColor
event:
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkColor(normal);
pDC->SetDCBrushColor(RGB(255, 255, 255));
return (HBRUSH)GetStockObject(DC_BRUSH);
After the code runs, my result is:
If I click on it, now it works:
But, how I can change text color?
You may not be setting the control state correctly.
Please try the MFC way (it works for me). Add to your dialog class:
CLinkCtrl syslink;
Connect it to the resource ID of your link:
void CMFCApplication4Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SYSLINK1, syslink);
}
and in OnInitDialog
add this:
syslink.SetItemState(0, LIS_ENABLED | LIS_FOCUSED | LIS_DEFAULTCOLORS,
LIS_ENABLED | LIS_FOCUSED | LIS_DEFAULTCOLORS);
I see red link with your code in OnCtlColor
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.