禁用按钮动画在Win32中℃的单个应用程序++ [英] Disable button animation for a single application in Win32 C++

查看:443
本文介绍了禁用按钮动画在Win32中℃的单个应用程序++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过此调用

SystemParametersInfo(SPI_SETCLIENTAREAANIMATION, 0, (LPVOID)FALSE, 0);

我禁用按钮的动画在我的Win32 C ++项目(无MFC或其他任何东西),有视觉样式公共控件6.0.0.0通过调用启用并正确初始化 INITCOMMONCONTROLSEX 功能。是否有其他方法来做到这一点?我问,因为我不希望禁用动画整个系统但只为我的申请。创建是定制绘制的按钮(而不是所有者绘制)。
我创建这样的 WM_CREATE 消息中的一个按钮(hwndbutton之前静态定义,这样我可以全部WM消息之间共享):

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. 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):

hwndbutton = CreateWindowEx(0, L"BUTTON", L"example", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, x, y, width, height, hwnd, (HMENU)button_id, GetModuleHandle(NULL), NULL);

和我画出来

...
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;
...

通过按钮动画

,我的意思是比如褪色效果,当您将光标移到一个按钮,以后不要再发生在按钮的颜色:我想它是colorA时师范学校状态或colorB当鼠标已经过去,而不是colorA正常时和fade_until_you_reach_colorB当鼠标悬停。

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.

感谢

编辑:我添加两个的GIF
首先是我想要的(我用previous调用SystemParametersInfo获得),第二个是我想避免动画

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

我想什么

我不想什么

推荐答案

主题单独的窗口和控件可以如下禁用:

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.

通常,当你关闭按钮的主题,它可能看起来怪异与新系统老3-D边框。您可以添加 BS_FLAT 来按钮的样式。

Normally when you disable a button's theme it may look weird with old 3-D borders on newer systems. You can add BS_FLAT to button's style.

这篇关于禁用按钮动画在Win32中℃的单个应用程序++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆