显然 SysLink 控件 无法显示禁用。
我有一个包含以下控件的对话框(此示例中的坐标不准确):
CONTROL "Foo",IDC_CHECK8 "Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,
12,192,256,28
CONTROL "<a href=""https://www.somewhere.com"">Bar</a>",IDC_STATIC4,
"SysLink",0x0,22,219,144,9
当我使用
IDC_CHECK8
禁用两个控件IDC_STATIC4
(复选框)和
EnableWindow()
(SysLink控件)时,只有复选框显示为“禁用”外观,SysLink控件正常显示,就好像它没有残疾人:
问题不在我的代码中,因为 SysLink 实际上 已禁用(您无法单击它,这是预期的)。
有没有一种简单的方法来显示禁用的SysLink控件,有点像这样:
您可以定义一个全局标志来控制颜色变化。您可以使用
LM_SETITEM
设置 Syslink 并使用 LIS_DEFAULTCOLORS
允许 Syslinks 使用自定义颜色。然后你可以用SetTextColor
中的WM_CTLCOLORSTATIC
改变文字颜色,这些都可以达到预期的效果。
BOOL m_bSyslinkEnableFlag = TRUE;
case WM_INITDIALOG:
{
HWND syslinkhwnd = GetDlgItem(hDlg, IDC_SYSLINK2);
tagLITEM* pItem = new tagLITEM;
pItem->iLink = 0;
pItem->mask = LIF_ITEMINDEX | LIF_STATE;
pItem->state = LIS_ENABLED | LIS_FOCUSED | LIS_DEFAULTCOLORS;
pItem->stateMask = LIS_ENABLED | LIS_FOCUSED | LIS_DEFAULTCOLORS;
//LIS_DEFAULTCOLORS can use custom color
SendMessage(syslinkhwnd, LM_SETITEM, NULL, (LPARAM)pItem);
return (INT_PTR)TRUE;
}
case WM_CTLCOLORSTATIC:
{
HWND syslinkhwnd = GetDlgItem(hDlg, IDC_SYSLINK2);
if (LOWORD(lParam) == LOWORD(syslinkhwnd) && (m_bSyslinkEnableFlag == TRUE))
{
//Set the text color blue
SetTextColor((HDC)wParam, RGB(0, 35, 245));
}
else if (LOWORD(lParam) == LOWORD(syslinkhwnd) && (m_bSyslinkEnableFlag == FALSE))
{
//Set the text color black when disable
SetTextColor((HDC)wParam, RGB(0, 0, 0));
}
SetBkMode(HDC(wParam), TRANSPARENT);
//return default background color
return (INT_PTR)(HBRUSH)CreateSolidBrush(RGB(240, 240, 240));
}
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BUTTON1)
{
HWND syslinkhwnd = GetDlgItem(hDlg, IDC_SYSLINK2);
EnableWindow(syslinkhwnd, TRUE);
//set flag,the clor will change in WM_CTLCOLORSTATIC
m_bSyslinkEnableFlag = TRUE;
//redraw control and raise WM_CTLCOLORSTATIC
RedrawWindow(syslinkhwnd, NULL, NULL, RDW_INVALIDATE);
return (INT_PTR)TRUE;
}
if (LOWORD(wParam) == IDC_BUTTON2)
{
HWND syslinkhwnd = GetDlgItem(hDlg, IDC_SYSLINK2);
EnableWindow(syslinkhwnd, FALSE);
//set flag,the clor will change in WM_CTLCOLORSTATIC
m_bSyslinkEnableFlag = FALSE;
//redraw control and raise WM_CTLCOLORSTATIC
RedrawWindow(syslinkhwnd, NULL, NULL, RDW_INVALIDATE);
return (INT_PTR)TRUE;
}