求助:各位大哥,请帮我看看下面这段小程序,谢谢!

youall 2007-04-26 08:57:35
bool CALL HGE_Impl::System_Start()
{
MSG msg;
POINT pt;
RECT rc;

if(!hwnd)
{
_PostError("System_Start: System_Initiate wasn't called");
return false;
}

if(!procFrameFunc) {
_PostError("System_Start: No frame function defined");
return false;
}

bActive=true;

for(;;)
{

if(!hwndParent) //这是父窗口,是吗?
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
// TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
}

GetCursorPos(&pt);
GetClientRect(hwnd, &rc);
MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
if(bCaptured || (PtInRect(&rc, pt) && WindowFromPoint(pt)==hwnd)) bMouseOver=true;
else bMouseOver=false;

if(bActive || bDontSuspend) {
do { dt=timeGetTime() - t0; } while(dt < 1);
if(dt >= nFixedDelta)
{
fDeltaTime=dt/1000.0f;
if(fDeltaTime > 0.2f)
{
if(nFixedDelta) fDeltaTime=nFixedDelta/1000.0f;
else fDeltaTime=0.01f;
}
fTime+=fDeltaTime;

t0=timeGetTime();
if(t0-t0fps < 1000) cfps++;
else {nFPS=cfps; cfps=0; t0fps=t0;}
if(procFrameFunc()) break;
if(procRenderFunc) procRenderFunc();
if(hwndParent) break;
_ClearQueue();
if(!bWindowed && nHGEFPS==HGEFPS_VSYNC) Sleep(1);
}
else { if(nFixedDelta && dt+3 < nFixedDelta) Sleep(1); }
}
else Sleep(1);
}
_ClearQueue();
bActive=false;
return true;
}


求助:
这一段程序,我有几个地方看不懂,请各位大哥帮忙

问题1:
if(!hwndParent) //这是父窗口,是吗?
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
// TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}

这一段程序什么意思啊?


问题2:
什么条件才能跳出 for 循环?

问题3:
MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);

这句话什么意思?

问题4:
if(bCaptured || (PtInRect(&rc, pt) && WindowFromPoint(pt)==hwnd)) bMouseOver=true;
else bMouseOver=false;

这句话是什么意思?


谢谢!
...全文
317 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
youall 2007-04-26
  • 打赏
  • 举报
回复


谢谢楼上各位大哥
DispatchMessage(&msg);//解析消息

解析成为什么啊?


下面的程序用到了:
System_Start()



#include "hge.h"
#include "hgesprite.h"
#include "hgefont.h"
#include "hgeparticle.h"


// Pointer to the HGE interface.
// Helper classes require this to work.
HGE *hge=0;


// Pointers to the HGE objects we will use
hgeSprite* spr;
hgeSprite* spt;
hgeFont* fnt;
hgeParticleSystem* par;

// Handles for HGE resourcces
HTEXTURE tex;
HEFFECT snd;

// Some "gameplay" variables
float x=100.0f, y=100.0f;
float dx=0.0f, dy=0.0f;

const float speed=90;
const float friction=0.98f;

// Play sound effect
void boom() {
int pan=int((x-400)/4);
float pitch=(dx*dx+dy*dy)*0.0005f+0.2f;
hge->Effect_PlayEx(snd,100,pan,pitch);
}

bool FrameFunc()
{
float dt=hge->Timer_GetDelta(); //

// Process keys
if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
if (hge->Input_GetKeyState(HGEK_LEFT)) dx-=speed*dt;
if (hge->Input_GetKeyState(HGEK_RIGHT)) dx+=speed*dt;
if (hge->Input_GetKeyState(HGEK_UP)) dy-=speed*dt;
if (hge->Input_GetKeyState(HGEK_DOWN)) dy+=speed*dt;

// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
if(x>784) {x=784-(x-784);dx=-dx;boom();}
if(x<16) {x=16+16-x;dx=-dx;boom();}
if(y>584) {y=584-(y-584);dy=-dy;boom();}
if(y<16) {y=16+16-y;dy=-dy;boom();}

// Update particle system
par->info.nEmission=(int)(dx*dx+dy*dy)*2;
par->MoveTo(x,y);
par->Update(dt);

return false;
}


bool RenderFunc()
{
// Render graphics
hge->Gfx_BeginScene();
hge->Gfx_Clear(0);
par->Render();
spr->Render(x, y);
fnt->printf(5, 5, HGETEXT_LEFT, "dt:%.3f\nFPS:%d (constant)", hge->Timer_GetDelta(), hge->Timer_GetFPS());
hge->Gfx_EndScene();

return false;
}


int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
hge = hgeCreate(HGE_VERSION); //创建 hge 句柄 创建Engine接口

hge->System_SetState((hgeIntState)14,(int)0xFACE0FF); //使不显示 HGE LOGO
hge->System_SetState(HGE_LOGFILE, "hge_tut03.log"); //生成日志
hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); //设置回调
hge->System_SetState(HGE_RENDERFUNC, RenderFunc); //
hge->System_SetState(HGE_TITLE, "HGE Tutorial 03 - Using helper classes"); //设置窗口标题
hge->System_SetState(HGE_FPS, 100); //设置最大 FPS
hge->System_SetState(HGE_WINDOWED, true); //是否是窗口模式
hge->System_SetState(HGE_SCREENWIDTH, 800); //设置窗口的大小 宽
hge->System_SetState(HGE_SCREENHEIGHT, 600); //设置窗口的大小 长
hge->System_SetState(HGE_SCREENBPP, 32); //设置色彩深度

//hge->System_SetState(HGE_USESOUND, true); //是否使用声音资源

//Engine 初始化
if(hge->System_Initiate()) {

// Load sound and texture
snd=hge->Effect_Load("menu.wav"); //载入声音
tex=hge->Texture_Load("particles.png"); //载入图片
if(!snd || !tex) //这个是什么意思啊
{
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, "Can't load one of the following files:\nMENU.WAV, PARTICLES.PNG, FONT1.FNT, FONT1.PNG, TRAIL.PSI", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown(); //关闭程序
hge->Release(); //释放资源
return 0;
}

// Create and set up a sprite
spr=new hgeSprite(tex, 96, 64, 32, 32); //创建粒子
spr->SetColor(0xFFFFA000); //给粒子颜色
spr->SetHotSpot(16,16); //初始化它的坐标

// Load a font
fnt=new hgeFont("font1.fnt");

// Create and set up a particle system
spt=new hgeSprite(tex, 32, 32, 32, 32);
spt->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
spt->SetHotSpot(16,16);
par=new hgeParticleSystem("trail.psi",spt);
par->Fire();

// Let's rock now!
//启动 Engine 开始主循环
hge->System_Start();

// Delete created objects and free loaded resources
delete par;
delete fnt;
delete spt;
delete spr;
hge->Texture_Free(tex);
hge->Effect_Free(snd);
}

// Clean up and shutdown
hge->System_Shutdown();
hge->Release();
return 0;
}



程序为什么能跳到执行
RenderFunc()


谢谢!
lin_style 2007-04-26
  • 打赏
  • 举报
回复
老师来了。先闪
lin_style 2007-04-26
  • 打赏
  • 举报
回复
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
// TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}

取消息..如果是quit(关闭)就...


for(;;) //语句本身肯定跳不出了。 找找break之类的

MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);//取点吗?LPPOINT结构应该是long x,long y之类



lidongri 2007-04-26
  • 打赏
  • 举报
回复
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))//接收消息
{
if (msg.message == WM_QUIT) break;//如果为推出,则跳出循环
TranslateMessage(&msg);
DispatchMessage(&msg);//解析消息
continue;
}
FingerStyle 2007-04-26
  • 打赏
  • 举报
回复
去vc版问 比较合适。。
upsonn 2007-04-26
  • 打赏
  • 举报
回复
for 循环的退出,要么在循环中break 或return,或者在for循环判断条件中设置推出条件

至于其他的请看<windows程序设计>
lin_style 2007-04-26
  • 打赏
  • 举报
回复
程序为什么能跳到执行
RenderFunc()

//hge->System_SetState(HGE_RENDERFUNC, RenderFunc); //

//windows程序设计
//前几章可以答疑你的疑惑

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧