我正在尝试制作一个在 10 秒内旋转并绘制 360 度位图的程序,但我发现我用来执行此操作的方法不是即时的,甚至不是关闭的,所以我的函数不会在其中执行预期的时间。为了弥补这一点,我决定确定自从我用来旋转图像并绘制它直到完成的函数开始以来已经过去了多少时间,并将旋转量增加了执行所花费的额外时间。
我研究了计时器,我知道我可以创建一个计时器来增加一个变量来“计算”已经过去了多少时间,但是为了让它足够准确,它必须至少每 50 毫秒使用一次(可能更短)当我希望它是即时或接近即时时,我的重复功能每个周期已经需要大约 0.4 秒才能完成,我觉得这可能会消耗太多额外的资源并想要寻找不同的解决方案。
如果您需要任何代码,它是:
#include <windows.h>
#include <tgmath.h>
void rotatebmp (HDC hdc_x, float q, float x0, float y0)
{
q = (q * 0.01745333055);
XFORM blah;
blah.eM11 = cos(q);
blah.eM12 = sin(q);
blah.eM21 = -sin(q);
blah.eM22 = cos(q);
blah.eDx = x0 - cos(q)*x0 + sin(q)*y0;
blah.eDy = y0 - cos(q)*y0 - sin(q)*x0;
SetWorldTransform(hdc_x, &blah);
return;
}
int main()
{
float q = 0;
HDC hdc = CreateCompatibleDC(NULL);
HBITMAP cross = (HBITMAP)LoadImage(NULL, ("C:\\Documents and Settings\\Death\\My Documents\\45Hand.bmp") ,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HBITMAP crossmask = (HBITMAP)LoadImage(NULL, ("C:\\Documents and Settings\\Death\\My Documents\\45Hand2.bmp") ,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
while (1)
{
q = (q + 3.6);
HDC hdc_x = GetDC(HWND_DESKTOP);
SetGraphicsMode(hdc_x, GM_ADVANCED);
SelectObject(hdc, crossmask);
rotatebmp (hdc_x, q, 850, 375);
BitBlt(hdc_x,550,0,600,527,hdc,0,0, SRCAND);
ReleaseDC(HWND_DESKTOP,hdc_x);
hdc_x = GetDC(HWND_DESKTOP);
SetGraphicsMode(hdc_x, GM_ADVANCED);
SelectObject(hdc, cross);
rotatebmp (hdc_x, q, 850, 375);
BitBlt(hdc_x,550,0,600,527,hdc,0,0, SRCPAINT);
ReleaseDC(HWND_DESKTOP,hdc_x);
Sleep(10);
}
return 0;
}