[英]win32 C++ Custom Color for Trackbar thumb
I have spent today searching everywhere for a concrete explanation or example of coloring the thumb on a trackbar (slider) in win32 C++. 我今天花了很多时间在各处寻找有关Win32 C ++中轨迹栏(滑块)上的拇指着色的具体解释或示例。 Everything I've found has been partially explained, and in trying every conceivable variation I have come up blank.
我发现的所有内容都得到了部分解释,在尝试所有可能的变体时,我都空白了。
The control I have been focused on is defined in my rc file as CONTROL "",IDC_PLAYSLIDER,"msctls_trackbar32",TBS_NOTICKS | 我一直关注的控件在我的rc文件中定义为CONTROL“”,IDC_PLAYSLIDER,“ msctls_trackbar32”,TBS_NOTICKS | WS_TABSTOP,5,22,187,15
WS_TABSTOP,5,22,187,15
Essentially, my message handling of NM_CUSTOMDRAW comes down to the following. 本质上,我对NM_CUSTOMDRAW的消息处理归结为以下内容。 I have no confidence on my color/hdc handling, but the lack of messages is my primary problem.
我对颜色/ hdc处理没有信心,但是缺少消息是我的主要问题。
INT_PTR CALLBACK dialogproc(HWND h, UINT m, WPARAM w, LPARAM l)
{
switch (m) {
case WM_NOTIFY:
{
switch (((LPNMHDR)l)->code) {
case NM_CUSTOMDRAW:
{
LPNMCUSTOMDRAW lpNMCD = (LPNMCUSTOMDRAW)l;
UINT idc = lpNMCD->hdr.idFrom;
switch (lpNMCD->dwDrawStage) {
case CDDS_PREPAINT:
return CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
{
switch (lpNMCD->dwItemSpec)
{
case TBCD_THUMB:
HGDIOBJ old_pen = SelectObject(lpNMCD->hdc, penSlider);
HGDIOBJ old_brush = SelectObject(lpNMCD->hdc, brushSlider);
return CDRF_NEWFONT;
}
}
break;
}
What I am getting at runtime is a CDDS_PREPAINT on the correct control, but no matter what I have tried, I have had no further CDDS_ drawStage messages. 我在运行时得到的是正确控件上的CDDS_PREPAINT,但是无论我尝试了什么,都没有更多的CDDS_ drawStage消息。
If anyone has done this on a trackbar (most examples are list controls) and is willing to share their message handler code, or can otherwise shed light on my confusion, that would be greatly appreciated. 如果有人在轨迹栏上执行过此操作(大多数示例是列表控件),并且愿意分享其消息处理程序代码,或者可以使我感到困惑,那么将不胜感激。
From the docs for NM_CUSTOMDRAW
: 从
NM_CUSTOMDRAW
的文档中:
If this message is handled in a dialog procedure, you must set the return value as part of the window data before returning TRUE.
如果在对话过程中处理了此消息,则必须在返回TRUE之前将返回值设置为窗口数据的一部分。 For more information, see DialogProc .
有关更多信息,请参见DialogProc 。
The DialogProc
docs say: DialogProc
文档说:
If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE
如果对话框过程处理了需要特定返回值的消息,则该对话框过程应在返回TRUE之前立即调用SetWindowLong(hwndDlg,DWL_MSGRESULT,lResult)来设置所需的返回值。
Note that with the advent of 64-bit windows it is better practice to use SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, lResult)
. 请注意,随着64位窗口的出现,更好的做法是使用
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, lResult)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.