|
|
请教:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
MSG msg;
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); //是否使用声音资源
if(hge->System_Initiate())
{
hge->System_Start();
}
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
return 0;
}
我的
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
应该是没有起作用的,
因为 HGE 的
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;
}
我需要自己抓消息,因为我需要接收串口的信息
各位大哥 System_Start() 需要怎么改啊?
我希望改以后,能这样用:
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,
LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
char temp[128];
switch(message)
{
case WM_CREATE:
return 0;
//获取键盘输入
case WM_KEYDOWN:
switch(wParam)
{
//按Esc键推出
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
//其余按键发声,并且开启时钟
MessageBeep(MB_OK);
//SetTimer(1,1000,NULL);
return 0;
//按下鼠标左键发声
case WM_LBUTTONDOWN:
MessageBeep(MB_OK);
//KillTimer(1);
KillTimer(hwnd,1);
return 0;
//按下鼠标右键退出
case WM_RBUTTONDOWN:
PostQuitMessage(0);
return 0;
//鼠标位置改变,显示坐标
case WM_MOUSEMOVE:
//hdc = GetDC(hwnd);
//sprintf(temp,"x: %d , y: %d",50,50);
//TextOut(hdc,10,10,temp,strlen(temp));
//ReleaseDC(hwnd,hdc);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_TIMER:
i++;
if (i%2)
{
hdc = GetDC(hwnd);
sprintf(temp,"x: %d , y: %d",50,50);
TextOut(hdc,100,100,temp,strlen(temp));
ReleaseDC(hwnd,hdc);
}
else
{
hdc = GetDC(hwnd);
sprintf(temp,"x: %d , y: %d",60,60);
TextOut(hdc,100,100,temp,strlen(temp));
ReleaseDC(hwnd,hdc);
}
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
谢谢!
[em3] [em17] [em20] [em20] |
|