Анимация в окне на WinApi

Привет всем.
Вопрос такой:
Дано: 1) Файл анимации (в любом удобном формате: GIF, AVI,
последовательность BMP etc.) размерами примерно
10x10 pix, от 10 до 100 кадров, продолжительностью
около 1 с.
2) Окно приложения типа Hello World с меню и фоном
3) чистенький Win API (т.е. без MFC, надстроек Builder,
DirectX etc.)
Нужно: вывести анимацию в приемлемом качестве на окно.
т.е., в конечном итоге это будет простенькая игрушка, в которой
при каждом ходе одного из игроков в окно выводится такая
анимация.
Как лучше всего можно такое сделать?
Проще всего узать окно класса ANIMATE_CLASS (оконный класс)
далее - пара функций для примера.
Animate_Create, Animate_Play, и.т.д. - макросы, развертываемые
в вызовы CreateWindow.
// CreateAnimationCtrl - creates an animation control, positions it
// below the specified control in a dialog box,
// and opens the AVI clip for the animation control.
// Returns the handle to the animation control.
// hwndDlg - handle to the dialog box.
// nIDCtl - identifier of the control below which the animation
control
// is to be positioned.
//
// Constants
// IDC_ANIMATE - identifier of the animation control.
// CX_FRAME, CY_FRAME - width and height of the frames
// in the AVI clip.
HWND CreateAnimationCtrl(HWND hwndDlg, int nIDCtl)
{
HWND hwndAnim = NULL;
RECT rc;
POINT pt;
// Create the animation control.
hwndAnim = Animate_Create(hwndDlg, IDC_ANIMATE,
WS_BORDER | WS_CHILD, g_hinst);
// Get the screen coordinates of the specified control button.
GetWindowRect(GetDlgItem(hwndDlg, nIDCtl), &rc);
// Convert the coordinates of the lower-left corner to
// client coordinates.
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient(hwndDlg, &pt);
// Position the animation control below the Stop button.
SetWindowPos(hwndAnim, 0, pt.x, pt.y + 20,
CX_FRAME, CY_FRAME,
SWP_NOZORDER | SWP_DRAWFRAME);
// Open the AVI clip, and show the animation control.
Animate_Open(hwndAnim, "SEARCH.AVI");
ShowWindow(hwndAnim, SW_SHOW);
return hwndAnim;
}
// DoAnimation - plays, stops, or closes an animation control's
// AVI clip, depending on the value of an action flag.
// hwndAnim - handle to an animation control
// nAction - flag that determines whether to play, stop, or close
// the AVI clip.
void DoAnimation(HWND hwndAnim, int nAction)
{
switch (nAction) {
case PLAYIT:
// Play the clip continuously starting with the
// first frame.
Animate_Play(hwndAnim, 0, -1, -1);
break;
case STOPIT:
Animate_Stop(hwndAnim);
break;
case CLOSEIT:
Animate_Close(hwndAnim);
break;
default:
break;
}
return;
}
--
С уважением, Вахтуров Виктор.
Информационный сайт для программистов http://SoftMaker.com.ru
Номер выпуска : 2646
Возраст листа : 180 (дней)
Количество подписчиков : 377
Адрес в архиве : http://subscribe.ru/archive/comp.soft.prog.prog/msg/107785
Получить правила : mailto:comp.soft.prog.prog-rules@subscribe.ru
Формат "дайджест" : mailto:comp.soft.prog.prog-digest@subscribe.ru
Формат "каждое письмо" : mailto:comp.soft.prog.prog-normal@subscribe.ru
Формат "читать с веба" : mailto:comp.soft.prog.prog-webonly@subscribe.ru
-*Информационный канал Subscribe.Ru
Написать в лист: mailto:comp.soft.prog.prog-list@subscribe.ru
Отписаться: mailto:comp.soft.prog.prog--unsub@subscribe.ru
http://subscribe.ru/ mailto:ask@subscribe.ru