📄 animthrd.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name: animthrd.cpp
Abstract: handles the animation thread
Functions:
Notes: This class encapsulates the thread that runs the animation
--*/
#include "Precomp.h"
#include "resource.h"
#include "mainwnd.h"
#include "animthrd.h"
#ifndef NOCOMMANDBAR
#define MAXFRAMES 41 //the number of frames in the bitmap
CAnimThread::CAnimThread(CMainWnd *pMainWnd)
{
_nIndex = 0;
_hBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_ANIMATION));
_bRun = FALSE;
_pMainWnd = pMainWnd;
HKEY hk = NULL;
DWORD dwSize = sizeof(DWORD);
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,L"Software\\Microsoft\\Internet Explorer\\Main",0,0,&hk))
{
if(ERROR_SUCCESS != RegQueryValueEx(hk, L"AnimationTicks",0,NULL, (LPBYTE)&_dwTimerInterval, &dwSize))
{
_dwTimerInterval = ANIMATIONINTERVAL;
}
RegCloseKey(hk);
}
}
CAnimThread::~CAnimThread()
{
DeleteObject(_hBitmap);
}
VOID CAnimThread::StartThread()
{
HANDLE hthd;
_hwndCmdband = _pMainWnd->GetCommandBand();
hthd = CreateThread(NULL, 0, AnimationThreadProc, this, 0, &_dwThreadID);
CloseHandle(hthd); // the thread is on its own
}
DWORD WINAPI CAnimThread::AnimationThreadProc(LPVOID lpParam)
{
CAnimThread *pAnimation = (CAnimThread *)lpParam;
return pAnimation->Run();
}
DWORD CAnimThread::Run()
{
_hwndAnimation = CreateWindowEx(0, _T("STATIC"), NULL, WS_CHILD|WS_VISIBLE|WS_DISABLED,
0, 0, ANIMATIONWIDTH, ANIMATIONHEIGHT, _hwndCmdband, NULL,
g_hInstance, NULL);
if (!_hwndAnimation)
return FALSE;
SetWindowLong(_hwndAnimation, GWL_USERDATA, (DWORD)this);
REBARBANDINFO rbbi[1];
rbbi[0].cbSize = sizeof(REBARBANDINFO);
rbbi[0].fMask = RBBIM_ID|RBBIM_STYLE|RBBIM_CHILD|RBBIM_SIZE|RBBIM_CHILDSIZE;
rbbi[0].cx = ANIMATIONWIDTH;
rbbi[0].cxMinChild = ANIMATIONWIDTH;
rbbi[0].cyMinChild = 24;
rbbi[0].wID = (DWORD)-1; ID_ANIMATIONWINDOW;
rbbi[0].fStyle = RBBS_FIXEDSIZE;
rbbi[0].hwndChild = _hwndAnimation;
#if 0
if (!CommandBands_AddBands(_hwndCmdband, g_hInstance, 1, rbbi))
return FALSE;
#endif
if(!SendMessage(_hwndCmdband, RB_INSERTBAND, (WPARAM)-1, (LPARAM)rbbi))
return FALSE;
if (0 == SetTimer(_hwndAnimation, ID_ANIMATIONTIMER, _dwTimerInterval, NULL))
return FALSE;
_lpfnAnimationProc = (WNDPROC )SetWindowLong(_hwndAnimation, GWL_WNDPROC, (LONG )AnimationWndProc);
MSG msg;
while(GetMessage(&msg, _hwndAnimation, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
KillTimer(_hwndAnimation, ID_ANIMATIONTIMER);
return msg.wParam;
}
LRESULT CALLBACK CAnimThread::AnimationWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CAnimThread *pthrdAnimation = (CAnimThread*)GetWindowLong(hwnd, GWL_USERDATA);
switch(message)
{
case WM_TIMER:
pthrdAnimation->Paint();
return 0L;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return CallWindowProc(pthrdAnimation->_lpfnAnimationProc, hwnd, message, wParam, lParam);
}
VOID CAnimThread::Paint()
{
HDC hDC = GetDC(_hwndAnimation);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hBmpOld = (HBITMAP )SelectObject(hMemDC, _hBitmap);
BitBlt(hDC, 0, 0, ANIMATIONWIDTH, ANIMATIONHEIGHT,
hMemDC, 0, _nIndex*ANIMATIONHEIGHT, SRCCOPY);
SelectObject(hMemDC, hBmpOld);
DeleteDC(hMemDC);
ReleaseDC(_hwndAnimation, hDC);
if (_bRun)
{
InterlockedIncrement(&_nIndex);
if(_nIndex == MAXFRAMES)
{
LONG lVal = 0;
InterlockedExchange(&_nIndex, lVal);
}
}
}
//StartAnimation and StopAnimation are called from the main thread, to control the animation
VOID CAnimThread::StartAnimation()
{
LONG dwVal = TRUE;
InterlockedExchange(&_bRun, dwVal);
}
VOID CAnimThread::StopAnimation()
{
LONG lVal = 0;
InterlockedExchange(&_bRun, lVal);
InterlockedExchange(&_nIndex, lVal);
}
#endif //NOCOMMANDBAR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -