WIN32,C ++:是否可以动画窗口而不隐藏它? [英] WIN32, C++: Is it possible to animate a window without hiding it?

查看:181
本文介绍了WIN32,C ++:是否可以动画窗口而不隐藏它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编辑控件(文本字段),我想动画。我想要的动画是它滑出来,为这个文本字段创建一个额外的行。我能够动画我的文本字段,并能够使其更大,但是显示滑动动画我第一次必须隐藏它。这意味着整个文本字段滑出,好像是第一次从无创建,而不是只添加一个新行。

I Have an edit control (a text field) which I want to animate. The animation I want is that it slides out, creating an extra line for this text field. I am able to animate my text field and able to make it larger, however to show the sliding animation I first have to hide it. This means the entire text fields slides out as if being created for the first time from nothing, instead of just adding a new line.

这是我现在的代码:

SetWindowPos(hwnd, HWND_TOP, x, y, newWidth, newHeight, SWP_DRAWFRAME);

ShowWindow(hwnd, SW_HIDE);

AnimateWindow(hwnd, 300, AW_SLIDE | AW_VER_NEGATIVE);

是否可以不隐藏此动画来显示此动画?

Is it possible to show this animation without hiding it?

推荐答案

要扩展Nick D的答案,这里是实现你正在寻找的代码...

To expand on Nick D's answer, here's the code to achieve what you're looking for...

.h

#define ANIMATION_TIMER 1234
#define ANIMATION_LIMIT 8
#define ANIMATION_OFFSET 4

int m_nAnimationCount;


.cpp

void CExampleDlg::OnTimer(UINT_PTR nIDEvent)
{
    if (nIDEvent == ANIMATION_TIMER)
    {
        if (++m_nAnimationCount > ANIMATION_LIMIT)
            KillTimer(EXPAND_TIMER);
        else
        {
            CRect rcExpand;
            m_edtExpand.GetWindowRect(rcExpand);
            ScreenToClient(rcExpand);

            rcExpand.bottom += ANIMATION_OFFSET;

            m_edtExpand.MoveWindow(rcExpand);
        }   
    }

    CDialog::OnTimer(nIDEvent);
}

void CExampleDlg::OnStartAnimation()
{
    m_nAnimationCount = 0;
    SetTimer(ANIMATION_TIMER, 20, NULL);
}

不要忘记设置对编辑控件(m_edtExpand)

Don't forget to set the Multiline property on the edit control (m_edtExpand)

这篇关于WIN32,C ++:是否可以动画窗口而不隐藏它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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