英文:
Is there any way for a tooltip to show the selected colour descriptively?
问题
可以配置CMFCColorDialog
,以在鼠标悬停在其上时显示活动颜色的工具提示吗?
英文:
It is possible to configure the CMFCColorDialog
to how the active colour in a tooltip when the mouse is over it?
Being colour blind I find it hard to identify "Red" for example. I got around it by clicking the Custom tab and using the RGB properties and setting Red that way:
But I wondered if a tooltip could be supported.
答案1
得分: 1
I didn't find any built-in functionality supporting tooltips here.
But, if you are open to DIY project ( and I feel that you are ), you can easily subclass that dialog, overriding single PreTranslateMessage
function:
#pragma once
#include <afxcolordialog.h>
class CMyColorDlg :
public CMFCColorDialog
{
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
private:
CToolTipCtrl m_ToolTip;
bool m_bCreate = true;
bool m_bTrackingMouseLeave = false;
COLORREF m_LastColor = 0;
};
Here is my demo implementation:
#include "pch.h"
#include "CMyColorDlg.h"
BOOL CMyColorDlg::PreTranslateMessage(MSG* pMsg) {
if (pMsg->message == WM_MOUSEMOVE) {
if (m_bCreate) {
m_bCreate = false;
m_ToolTip.Create(&m_pColourSheetOne->m_hexpicker, TTS_ALWAYSTIP | TTS_NOANIMATE);
m_ToolTip.AddTool(&m_pColourSheetOne->m_hexpicker, L"RGB");
}
CWnd* pw = WindowFromPoint(pMsg->pt);
if (pw->m_hWnd == m_pColourSheetOne->m_hexpicker.m_hWnd) {
if (!m_bTrackingMouseLeave)
{
TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hWnd;
::_TrackMouseEvent(&tme);
m_ToolTip.Activate(TRUE);
m_bTrackingMouseLeave = TRUE;
}
pw->ScreenToClient(&pMsg->pt);
COLORREF color = pw->GetDC()->GetPixel(pMsg->pt);
if (m_LastColor != color) {
if (color == 0xF9F9F9) { // RGB(249,249,249) - gray around the color stuff
m_ToolTip.Activate(FALSE);
}
else if (m_LastColor == 0xF9F9F9) {
m_ToolTip.Activate(TRUE);
}
m_LastColor = color;
CString s;
s.Format(L"R=%d, G=%d, B=%d\n",
GetRValue(color), GetGValue(color), GetBValue(color));
m_ToolTip.UpdateTipText(s, &m_pColourSheetOne->m_hexpicker);
m_ToolTip.Popup();
}
}
}
else if (pMsg->message == WM_MOUSELEAVE) {
m_bTrackingMouseLeave = FALSE;
m_ToolTip.Activate(FALSE);
}
return CMFCColorDialog::PreTranslateMessage(pMsg);
}
You only get WM_MOUSEMOVE
over that control after you click <kbd>Select...</kbd>
button.
英文:
I didn't find any built-in functionality supporting tooltips here.
But, if you are open to DIY project ( and I feel that you are ), you can easily subclass that dialog, overriding single PreTranslateMessage
function:
#pragma once
#include <afxcolordialog.h>
class CMyColorDlg :
public CMFCColorDialog
{
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
private:
CToolTipCtrl m_ToolTip;
bool m_bCreate = true;
bool m_bTrackingMouseLeave = false;
COLORREF m_LastColor = 0;
};
Here is my demo implementation:
#include "pch.h"
#include "CMyColorDlg.h"
BOOL CMyColorDlg::PreTranslateMessage(MSG* pMsg) {
if (pMsg->message == WM_MOUSEMOVE) {
if (m_bCreate) {
m_bCreate = false;
m_ToolTip.Create(&m_pColourSheetOne->m_hexpicker, TTS_ALWAYSTIP | TTS_NOANIMATE);
m_ToolTip.AddTool(&m_pColourSheetOne->m_hexpicker, L"RGB");
}
CWnd* pw = WindowFromPoint(pMsg->pt);
if (pw->m_hWnd == m_pColourSheetOne->m_hexpicker.m_hWnd) {
if (!m_bTrackingMouseLeave)
{
TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hWnd;
::_TrackMouseEvent(&tme);
m_ToolTip.Activate(TRUE);
m_bTrackingMouseLeave = TRUE;
}
pw->ScreenToClient(&pMsg->pt);
COLORREF color = pw->GetDC()->GetPixel(pMsg->pt);
if (m_LastColor != color) {
if (color == 0xF9F9F9) { // RGB(249,249,249) - gray around the color stuff
m_ToolTip.Activate(FALSE);
}
else if (m_LastColor == 0xF9F9F9) {
m_ToolTip.Activate(TRUE);
}
m_LastColor = color;
CString s;
s.Format(L"R=%d, G=%d, B=%d\n",
GetRValue(color), GetGValue(color), GetBValue(color));
m_ToolTip.UpdateTipText(s, &m_pColourSheetOne->m_hexpicker);
m_ToolTip.Popup();
}
}
}
else if (pMsg->message == WM_MOUSELEAVE) {
m_bTrackingMouseLeave = FALSE;
m_ToolTip.Activate(FALSE);
}
return CMFCColorDialog::PreTranslateMessage(pMsg);
}
You only get WM_MOUSEMOVE
over that control after you click <kbd>Select...</kbd> button.
UPDATE:
With a credit to Ovidiu Cucu, added tracking tooltip control.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论