[英]Disable button animation for a single application in Win32 C++
With this call 有了这个电话
SystemParametersInfo(SPI_SETCLIENTAREAANIMATION, 0, (LPVOID)FALSE, 0);
I disable the animation of buttons in my Win32 C++ project (no MFC or anything else) that has Visual Styles Common Controls 6.0.0.0 enabled and correctly initialized by calling InitCommonControlsEx
function. 我禁用了启用了Visual Styles Common Controls 6.0.0.0并通过调用
InitCommonControlsEx
函数正确初始化的Win32 C ++项目(没有MFC或其他工具)中按钮的动画。 Is there an alternative method to do this? 有替代方法可以做到这一点吗? I am asking because I don't want to disable the animation for the whole system but ONLY for my application.
我问是因为我不想禁用整个系统的动画,而只禁用我的应用程序。 The buttons I create are Custom Drawn (not Owner Drawn).
我创建的按钮是“自定义绘制”(不是“所有者绘制”)。 I create a button like this in the
WM_CREATE
message (hwndbutton is defined before as static so that I can share it between all WM messages): 我在
WM_CREATE
消息中创建了一个这样的按钮(hwndbutton之前被定义为静态的,以便可以在所有WM消息之间共享):
hwndbutton = CreateWindowEx(0, L"BUTTON", L"example", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, x, y, width, height, hwnd, (HMENU)button_id, GetModuleHandle(NULL), NULL);
and I draw it 然后画出来
...
case WM_NOTIFY:
{
LPNMHDR item = (LPNMHDR)lParam;
if (item->idFrom == button_id && item->code == NM_CUSTOMDRAW)
{
LPNMCUSTOMDRAW item_draw = (LPNMCUSTOMDRAW)item;
if (item_draw->uItemState & CDIS_HOT)
{
SetDCBrushColor(item_draw->hdc, RGB(180, 180, 180));
SelectObject(item_draw->hdc, GetStockObject(DC_BRUSH));
}
else
{
SetDCBrushColor(item_draw->hdc, RGB(255, 255, 255));
SelectObject(item_draw->hdc, GetStockObject(DC_BRUSH));
}
SetDCPenColor(item_draw->hdc, RGB(0, 0, 0));
SelectObject(item_draw->hdc, GetStockObject(DC_PEN));
RoundRect(item_draw->hdc, item_draw->rc.left, item_draw->rc.top, item_draw->rc.right, item_draw->rc.bottom, 0, 0);
return CDRF_DODEFAULT; // Return would be CDRF_SKIPDEFAULT but I want to keep the text "example" drawn
}
break;
...
By "button animation", I mean for example the fading effect that takes place in the button color when you move the cursor over a button and then leave it: I would like it to be colorA when normale state or colorB when mouse is over and not colorA when normal and fade_until_you_reach_colorB when mouse is over. 所谓“按钮动画”,是指例如当您将光标移到按钮上然后离开它时,按钮颜色发生的褪色效果:当正常状态时,我希望它是colorA;当鼠标悬停在上面时,我希望它是colorB。正常时不是colorA,鼠标悬停时是不是fade_until_you_reach_colorB。
Thanks 谢谢
EDIT: I add two gifs The first is what I want (and I obtain with a previous call to SystemParametersInfo) and the second is the animation I would like to avoid 编辑:我添加了两个gif图像,第一个是我想要的(我通过对SystemParametersInfo的先前调用获得),第二个是我想要避免的动画
Theme for individual windows and controls can be disabled as follows: 可以如下禁用各个窗口和控件的主题:
SetWindowTheme(hbutton, L" ", L" ");
Animation should already be disabled because you are using custom draw. 动画应该已经被禁用,因为您正在使用自定义绘制。 This method will also disable mouse-hover effect.
此方法还将禁用鼠标悬停效果。
Normally when you disable a button's theme it may look weird with old 3-D borders on newer systems. 通常,当您禁用按钮的主题时,在较新的系统上,它的旧3D边框看起来可能很奇怪。 You can add
BS_FLAT
to button's style. 您可以将
BS_FLAT
添加到按钮的样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.