Feature: add tooltips to the password input dialog
The passcode input dialog now explains every control the operator can use on hover, using the same MFC built-in tooltip mechanism as the generate-passcode dialog (EnableToolTips + OnToolHitTest + TTN_NEEDTEXT, with the max tip width applied when the tip is requested). The passcode tip carries the main point: the value must match the current serial and binding mode, and a passcode that was tampered with, cracked or forged is invalid. The OK tip says the authorization check verifies the passcode after saving rather than claiming the dialog checks it. The checksum tip reflects that V2 verifies the passcode signature while V1 checks the passcode itself, and the root-credential tip notes that clearing the box does not delete the stored credential. While here, the TTN_NEEDTEXT handlers keep idFrom in UINT_PTR: on x64 the old UINT intermediate could truncate a control HWND. The same fix is applied to the generate-passcode dialog. All 6 texts are translated in the en_US, de_DE and zh_TW packs. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
f22bd574ea
commit
2b26f22d27
5 files changed
+119
-3
No files matched your search
@@ -599,6 +599,7 @@ void CPasswordDlg::DoDataExchange(CDataExchange* pDX)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CPasswordDlg, CDialogEx)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_BIND, &CPasswordDlg::OnCbnSelchangeComboBind)
|
||||
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CPasswordDlg::OnToolTipNotify)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -632,10 +633,94 @@ BOOL CPasswordDlg::OnInitDialog()
|
||||
m_EditRootCert.SetWindowText(m_sRootCert);
|
||||
}
|
||||
|
||||
// 各操作控件的悬浮提示。重点:口令必须由管理员合法签发,
|
||||
// 自行篡改、破解或伪造的口令一律无效。
|
||||
m_tips.clear();
|
||||
m_tips[IDC_COMBO_BIND] = _TR(
|
||||
"选择授权绑定的对象:\n"
|
||||
"选硬件方式时绑定本机硬件;\n"
|
||||
"选主控地址方式时绑定当前公网地址。\n"
|
||||
"切换后序列号会自动重算,与新序列号不匹配的旧口令随之失效。");
|
||||
m_tips[IDC_EDIT_DEVICEID] = _TR(
|
||||
"按「授权方式」自动计算的设备序列号(只读)。\n"
|
||||
"口令只对这个序列号有效;序列号与授权方式不一致时\n"
|
||||
"无法通过校验。");
|
||||
m_tips[IDC_EDIT_DEVICEPWD] = _TR(
|
||||
"粘贴管理员签发的授权口令(必填)。\n"
|
||||
"【重点】口令必须与当前序列号、授权方式匹配;\n"
|
||||
"自行篡改、破解或伪造的口令均无效,\n"
|
||||
"校验不通过将无法通过授权检查。");
|
||||
m_tips[IDC_EDIT_PASSCODE_HMAC] = _TR(
|
||||
"口令对应的验证码/签名(V2 模式下必填,以 v2: 开头)。\n"
|
||||
"V2 用它校验口令签名,必须与口令、序列号一起由管理员签发;\n"
|
||||
"V1 模式下由口令本身完成校验。");
|
||||
m_tips[IDC_EDIT_ROOT_CERT] = _TR(
|
||||
"可选的上级授权凭证,用于多层授权。\n"
|
||||
"由上级管理员提供;普通单层授权可留空。\n"
|
||||
"填写错误不影响本机口令校验,但下发给下级的授权会无效;\n"
|
||||
"清空输入框不会删除已保存的凭证。");
|
||||
m_tips[IDOK] = _TR(
|
||||
"保存序列号、授权口令和验证码。\n"
|
||||
"【重点】保存后由授权检查验证口令,\n"
|
||||
"篡改、破解或伪造的口令一律无效;\n"
|
||||
"请勿手工拼接口令。");
|
||||
EnableToolTips(TRUE);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// 异常: OCX 属性页应返回 FALSE
|
||||
}
|
||||
|
||||
INT_PTR CPasswordDlg::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
|
||||
{
|
||||
// point 是对话框客户区坐标。逐个登记过提示的可见控件做矩形命中,
|
||||
// 不依赖鼠标消息落在哪个窗口:combo 的内部编辑框、禁用控件都能命中;隐藏控件跳过。
|
||||
for (const auto& kv : m_tips) {
|
||||
CWnd* w = GetDlgItem(kv.first);
|
||||
if (w == nullptr || !w->IsWindowVisible())
|
||||
continue;
|
||||
CRect rc;
|
||||
w->GetWindowRect(&rc);
|
||||
ScreenToClient(&rc);
|
||||
if (!rc.PtInRect(point))
|
||||
continue;
|
||||
if (pTI != nullptr) {
|
||||
pTI->hwnd = m_hWnd;
|
||||
pTI->uId = (UINT_PTR)w->GetSafeHwnd();
|
||||
pTI->uFlags |= TTF_IDISHWND;
|
||||
// 与 MFC 默认实现一致:非按钮控件让提示居中。
|
||||
if (!(::SendMessage(w->GetSafeHwnd(), WM_GETDLGCODE, 0, 0) & DLGC_BUTTON))
|
||||
pTI->uFlags |= TTF_NOTBUTTON | TTF_CENTERTIP;
|
||||
pTI->lpszText = LPSTR_TEXTCALLBACK;
|
||||
}
|
||||
return (INT_PTR)kv.first;
|
||||
}
|
||||
return -1; // 其余控件(标签等)不加提示
|
||||
}
|
||||
|
||||
BOOL CPasswordDlg::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
// 内建工具提示默认单行绘制(未设 TTM_SETMAXTIPWIDTH 时 \n 不生效)。
|
||||
// 在提示即将显示时设置,避免每次鼠标移动都向共享的 tooltip 发消息。
|
||||
AFX_MODULE_THREAD_STATE* ts = AfxGetModuleThreadState();
|
||||
if (ts != nullptr && ts->m_pToolTip != nullptr && ts->m_pToolTip->GetSafeHwnd() != nullptr)
|
||||
ts->m_pToolTip->SetMaxTipWidth(600);
|
||||
|
||||
TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;
|
||||
UINT_PTR idFrom = pNMHDR->idFrom;
|
||||
UINT nID = (UINT)idFrom;
|
||||
if (pTTT->uFlags & TTF_IDISHWND) {
|
||||
// idFrom 是工具窗口句柄,换成控件 ID(保留完整宽度,避免 x64 截断)
|
||||
nID = (UINT)::GetDlgCtrlID((HWND)idFrom);
|
||||
}
|
||||
auto it = m_tips.find(nID);
|
||||
if (it == m_tips.end())
|
||||
return FALSE;
|
||||
// 指向成员里的 CString:生命周期覆盖提示显示期间,也避开 szText 的 80 字符限制。
|
||||
pTTT->lpszText = const_cast<LPTSTR>((LPCTSTR)it->second);
|
||||
if (pResult) *pResult = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CPasswordDlg::OnCbnSelchangeComboBind()
|
||||
{
|
||||
m_nBindType = m_ComboBinding.GetCurSel();
|
||||
@@ -1115,10 +1200,11 @@ BOOL CPwdGenDlg::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
|
||||
ts->m_pToolTip->SetMaxTipWidth(600);
|
||||
|
||||
TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;
|
||||
UINT nID = (UINT)pNMHDR->idFrom;
|
||||
UINT_PTR idFrom = pNMHDR->idFrom;
|
||||
UINT nID = (UINT)idFrom;
|
||||
if (pTTT->uFlags & TTF_IDISHWND) {
|
||||
// idFrom 是工具窗口句柄,换成控件 ID
|
||||
nID = (UINT)::GetDlgCtrlID((HWND)nID);
|
||||
// idFrom 是工具窗口句柄,换成控件 ID(保留完整宽度,避免 x64 截断)
|
||||
nID = (UINT)::GetDlgCtrlID((HWND)idFrom);
|
||||
}
|
||||
auto it = m_tips.find(nID);
|
||||
if (it == m_tips.end())
|
||||
|
||||
Reference in new issue
Block a user