1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include <windows.h>
#include <math.h>
__int64 Frame;
__int64 FromStart;
__int64 LastFrame;
RECT rect;
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
void Render(HWND hwnd,int);
BOOL AnimateNextFrame(int desiredFrameRate);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
FromStart=GetTickCount();
Frame=0;
LastFrame=62000000000LL;
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass = {sizeof (wndclass), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance,
LoadIcon (NULL, IDI_WINLOGO), LoadCursor (NULL, IDC_ARROW), (HBRUSH) GetStockObject (WHITE_BRUSH),
NULL, "MCT", LoadIcon (NULL, IDI_WINLOGO)};
RegisterClassEx (&wndclass);
hwnd = CreateWindow ("MCT", // window class name
"Bitmap Background", // window's Title
WS_SYSMENU, // window style - This style won't allow the window to resize
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
800, // Here we pass in our desired width (800)
600, // Here we pass in our desired height (600)
NULL, // This is the parent window handle.
NULL, // This is the window menu handle
hInstance, // This is the programs instance handle.
NULL); // We don't want to pass any extra data in, so NULL
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
GetClientRect(hwnd,&rect);
while (1)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT) break;
TranslateMessage (&msg);
DispatchMessage (&msg);
}
else
{
if(AnimateNextFrame(60))
{
Render(hwnd,GetTickCount()-LastFrame);
LastFrame=GetTickCount();
Frame=Frame+1;
}
}
}
UnregisterClass("Window Class",hInstance);
return msg.wParam ;
}
void Render(HWND hwnd,int f)
{
HDC hDC;
PAINTSTRUCT Ps;
hDC = BeginPaint(hwnd, &Ps);
RECT r;
r.top=0;
r.left=0;
r.right=800;
r.bottom=600;
FillRect(hDC,&r,(HBRUSH)CreateSolidBrush(0x00FFFFFF));
XFORM xform;
int nGraphicsMode = SetGraphicsMode(hDC, GM_ADVANCED);
double m_iAngle=Frame*60;//i/360000;
double fangle = (double)m_iAngle / 180.0 * 3.1415926;
xform.eM11 = (float)cos(fangle);
xform.eM12 = (float)sin(fangle);
xform.eM21 = (float)-sin(fangle);
xform.eM22 = (float)cos(fangle);
xform.eDx = (float)(0 - cos(fangle)*0 + sin(fangle)*0);
xform.eDy = (float)(0 - cos(fangle)*0 - sin(fangle)*0);
SetWorldTransform(hDC, &xform);
char buf[8];
itoa(GetTickCount()/1000,buf,10);
TextOut(hDC, 50, 42, buf, 13);
EndPaint(hwnd, &Ps);
}
BOOL AnimateNextFrame(int desiredFrameRate)
{
static float lastTime = 0.0f;
float elapsedTime = 0.0;
// Get current time in seconds (milliseconds * .001 = seconds)
float currentTime = GetTickCount() * 0.001f;
// Get the elapsed time by subtracting the current time from the last time
elapsedTime = currentTime - lastTime;
// Check if the time since we last checked is over (1 second / framesPerSecond)
if( elapsedTime > (1.0f / desiredFrameRate) )
{
// Reset the last time
lastTime = currentTime;
// Return TRUE, to animate the next frame of animation
return TRUE;
}
// We don't animate right now.
return FALSE;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
Render(hwnd,0);
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
| |