system.cpp
上传用户:maxiaolivb
上传日期:2022-06-07
资源大小:915k
文件大小:18k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /*
  2. ** Haaf's Game Engine 1.5
  3. ** Copyright (C) 2003-2004, Relish Games
  4. ** hge.relishgames.com
  5. **
  6. ** Core system functions
  7. */
  8. #include "hge_impl.h"
  9. #define LOWORDINT(n) ((int)((signed short)(LOWORD(n))))
  10. #define HIWORDINT(n) ((int)((signed short)(HIWORD(n))))
  11. const char *WINDOW_CLASS_NAME = "HGE__WNDCLASS";
  12. LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
  13. int nRef=0;
  14. HGE_Impl* pHGE=0;
  15. BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID)
  16. {
  17.     return TRUE;
  18. }
  19. HGE* CALL hgeCreate(int ver)
  20. {
  21. if(ver==HGE_VERSION) return (HGE*)HGE_Impl::_Interface_Get();
  22. else return 0;
  23. }
  24. HGE_Impl* HGE_Impl::_Interface_Get()
  25. {
  26. if(!pHGE) pHGE=new HGE_Impl();
  27. nRef++;
  28. return pHGE;
  29. }
  30. void CALL HGE_Impl::Release()
  31. {
  32. nRef--;
  33. if(!nRef)
  34. {
  35. if(pHGE->hwnd) pHGE->System_Shutdown();
  36. Resource_RemoveAllPacks();
  37. delete pHGE;
  38. pHGE=0;
  39. }
  40. }
  41. bool CALL HGE_Impl::System_Initiate()
  42. {
  43. OSVERSIONINFO os_ver;
  44. SYSTEMTIME tm;
  45. MEMORYSTATUS mem_st;
  46. WNDCLASS winclass;
  47. int width, height;
  48. System_Log("HGE Started..n");
  49. System_Log("HGE version: %X.%X", HGE_VERSION>>8, HGE_VERSION & 0xFF);
  50. GetLocalTime(&tm);
  51. System_Log("Date: %02d.%02d.%d, %02d:%02d:%02dn", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond);
  52. System_Log("Application: %s",szWinTitle);
  53. os_ver.dwOSVersionInfoSize=sizeof(os_ver);
  54. GetVersionEx(&os_ver);
  55. System_Log("OS: Windows %ld.%ld.%ld",os_ver.dwMajorVersion,os_ver.dwMinorVersion,os_ver.dwBuildNumber);
  56. GlobalMemoryStatus(&mem_st);
  57. System_Log("Memory: %ldK total, %ldK freen",mem_st.dwTotalPhys/1024L,mem_st.dwAvailPhys/1024L);
  58. winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  59. winclass.lpfnWndProc = WindowProc;
  60. winclass.cbClsExtra = 0;
  61. winclass.cbWndExtra = 0;
  62. winclass.hInstance = hInstance;
  63. winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  64. winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  65. winclass.lpszMenuName = NULL; 
  66. winclass.lpszClassName = WINDOW_CLASS_NAME;
  67. if(szIcon) winclass.hIcon = LoadIcon(hInstance, szIcon);
  68. else winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  69. if (!RegisterClass(&winclass)) {
  70. _PostError("Can't register window class");
  71. return false;
  72. }
  73. width=nScreenWidth + GetSystemMetrics(SM_CXFIXEDFRAME)*2;
  74. height=nScreenHeight + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
  75. rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2;
  76. rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2;
  77. rectW.right=rectW.left+width;
  78. rectW.bottom=rectW.top+height;
  79. styleW=WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE; //WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
  80. rectFS.left=0;
  81. rectFS.top=0;
  82. rectFS.right=nScreenWidth;
  83. rectFS.bottom=nScreenHeight;
  84. styleFS=WS_POPUP|WS_VISIBLE; //WS_POPUP
  85. if(hwndParent)
  86. {
  87. rectW.left=0;
  88. rectW.top=0;
  89. rectW.right=nScreenWidth;
  90. rectW.bottom=nScreenHeight;
  91. styleW=WS_CHILD|WS_VISIBLE; 
  92. bWindowed=true;
  93. }
  94. if(bWindowed)
  95. hwnd = CreateWindowEx(0, WINDOW_CLASS_NAME, szWinTitle, styleW,
  96. rectW.left, rectW.top, rectW.right-rectW.left, rectW.bottom-rectW.top,
  97. hwndParent, NULL, hInstance, NULL);
  98. else
  99. hwnd = CreateWindowEx(WS_EX_TOPMOST, WINDOW_CLASS_NAME, szWinTitle, styleFS,
  100. 0, 0, 0, 0,
  101. NULL, NULL, hInstance, NULL);
  102. if (!hwnd)
  103. {
  104. _PostError("Can't create window");
  105. return false;
  106. }
  107. ShowWindow(hwnd, SW_SHOW);
  108. timeBeginPeriod(1);
  109. Random_Seed();
  110. if(!_GfxInit()) { System_Shutdown(); return false; }
  111. if(!_SoundInit()) { System_Shutdown(); return false; }
  112. System_Log("Init done.n");
  113. fTime=0.0f;
  114. t0=t0fps=timeGetTime();
  115. dt=cfps=0;
  116. nFPS=0;
  117. #ifdef DEMO
  118. bool (*func)();
  119. bool (*rfunc)();
  120. HWND hwndTmp;
  121. if(~pHGE->nDMO != ~0xFACE0FF) // Commercial version magic
  122. {
  123. Sleep(200);
  124. func=(bool(*)())pHGE->System_GetStateFunc(HGE_FRAMEFUNC);
  125. rfunc=(bool(*)())pHGE->System_GetStateFunc(HGE_RENDERFUNC);
  126. hwndTmp=hwndParent; hwndParent=0;
  127. pHGE->System_SetStateFunc(HGE_FRAMEFUNC, DFrame);
  128. pHGE->System_SetStateFunc(HGE_RENDERFUNC, 0);
  129. DInit();
  130. pHGE->System_Start();
  131. DDone();
  132. hwndParent=hwndTmp;
  133. pHGE->System_SetStateFunc(HGE_FRAMEFUNC, func);
  134. pHGE->System_SetStateFunc(HGE_RENDERFUNC, rfunc);
  135. }
  136. #endif
  137. return true;
  138. }
  139. void CALL HGE_Impl::System_Shutdown()
  140. {
  141. System_Log("nFinishing..");
  142. timeEndPeriod(1);
  143. _ClearQueue();
  144. _SoundDone();
  145. _GfxDone();
  146. if(hwnd)
  147. {
  148. //ShowWindow(hwnd, SW_HIDE);
  149. //SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
  150. //ShowWindow(hwnd, SW_SHOW);
  151. DestroyWindow(hwnd);
  152. hwnd=0;
  153. }
  154. if(hInstance) UnregisterClass(WINDOW_CLASS_NAME, hInstance);
  155. System_Log("The End.");
  156. }
  157. bool CALL HGE_Impl::System_Start()
  158. {
  159. MSG msg;
  160. POINT pt;
  161. RECT rc;
  162. if(!hwnd)
  163. {
  164. _PostError("System_Start: System_Initiate wasn't called");
  165. return false;
  166. }
  167. if(!procFrameFunc)
  168. {
  169. _PostError("System_Start: No frame function defined");
  170. return false;
  171. }
  172. bActive=true;
  173. for(;;)
  174. {
  175. if(!hwndParent)
  176. {
  177. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  178. if (msg.message == WM_QUIT)
  179. break;
  180. // TranslateMessage(&msg);
  181. DispatchMessage(&msg);
  182. continue;
  183. }
  184. }
  185. GetCursorPos(&pt);
  186. GetClientRect(hwnd, &rc);
  187. MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
  188. if(bCaptured || (PtInRect(&rc, pt) && WindowFromPoint(pt)==hwnd))
  189. bMouseOver=true;
  190. else
  191. bMouseOver=false;
  192. if(bActive || bDontSuspend)
  193. {
  194. do
  195. {
  196. dt=timeGetTime() - t0;
  197. } while(dt < 1);
  198. if(dt >= nFixedDelta)
  199. {
  200. fDeltaTime=dt/1000.0f;
  201. if(fDeltaTime > 0.2f)
  202. {
  203. if(nFixedDelta)
  204. fDeltaTime=nFixedDelta/1000.0f;
  205. else
  206. fDeltaTime=0.01f;
  207. }
  208. fTime+=fDeltaTime;
  209. t0=timeGetTime();
  210. if(t0-t0fps < 1000)
  211. cfps++;
  212. else
  213. {
  214. nFPS=cfps;
  215. cfps=0;
  216. t0fps=t0;
  217. }
  218. if(procFrameFunc())
  219. break;
  220. if(procRenderFunc)
  221. procRenderFunc();
  222. if(hwndParent)
  223. break;
  224. _ClearQueue();
  225. if(!bWindowed && nHGEFPS==HGEFPS_VSYNC)
  226. Sleep(1);
  227. }
  228. else
  229. {
  230. if(nFixedDelta && dt+3 < nFixedDelta)
  231. Sleep(1);
  232. }
  233. }
  234. else Sleep(1);
  235. }
  236. _ClearQueue();
  237. bActive=false;
  238. return true;
  239. }
  240. void CALL HGE_Impl::System_SetStateBool(hgeBoolState state, bool value)
  241. {
  242. switch(state) {
  243. case HGE_WINDOWED: if(VertArray || hwndParent) break;
  244. if(pD3DDevice && bWindowed != value)
  245. {
  246. if(d3dppW.BackBufferFormat==D3DFMT_UNKNOWN || d3dppFS.BackBufferFormat==D3DFMT_UNKNOWN) break;
  247. if(procFocusLostFunc) procFocusLostFunc();
  248. if(bWindowed) GetWindowRect(hwnd, &rectW);
  249. bWindowed=value;
  250. if(bWindowed) d3dpp=&d3dppW;
  251. else d3dpp=&d3dppFS;
  252. if(_format_id(d3dpp->BackBufferFormat) < 4) nScreenBPP=16;
  253. else nScreenBPP=32;
  254. _GfxRestore();
  255. _AdjustWindow();
  256. if(procFocusGainFunc) procFocusGainFunc();
  257. }
  258. else bWindowed=value;
  259. break;
  260. case HGE_ZBUFFER: if(!pD3DDevice) bZBuffer=value;
  261. break;
  262. case HGE_TEXTUREFILTER: bTextureFilter=value;
  263. if(pD3DDevice)
  264. {
  265. _render_batch();
  266. if(bTextureFilter)
  267. {
  268. pD3DDevice->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_LINEAR);
  269. pD3DDevice->SetTextureStageState(0,D3DTSS_MINFILTER,D3DTEXF_LINEAR);
  270. }
  271. else
  272. {
  273. pD3DDevice->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_POINT);
  274. pD3DDevice->SetTextureStageState(0,D3DTSS_MINFILTER,D3DTEXF_POINT);
  275. }
  276. }
  277. break;
  278. case HGE_USESOUND: if(bUseSound!=value)
  279. {
  280. bUseSound=value;
  281. if(bUseSound && hwnd) _SoundInit();
  282. if(!bUseSound && hwnd) _SoundDone();
  283. }
  284. break;
  285. case HGE_HIDEMOUSE: bHideMouse=value; break;
  286. case HGE_DONTSUSPEND: bDontSuspend=value; break;
  287. }
  288. }
  289. void CALL HGE_Impl::System_SetStateFunc(hgeFuncState state, hgeCallback value)
  290. {
  291. switch(state) {
  292. case HGE_FRAMEFUNC: procFrameFunc=value; break;
  293. case HGE_RENDERFUNC: procRenderFunc=value; break;
  294. case HGE_FOCUSLOSTFUNC: procFocusLostFunc=value; break;
  295. case HGE_FOCUSGAINFUNC: procFocusGainFunc=value; break;
  296. case HGE_EXITFUNC: procExitFunc=value; break;
  297. }
  298. }
  299. void CALL HGE_Impl::System_SetStateHwnd(hgeHwndState state, HWND value)
  300. {
  301. switch(state) {
  302. case HGE_HWNDPARENT: if(!hwnd) hwndParent=value; break;
  303. }
  304. }
  305. void CALL HGE_Impl::System_SetStateInt(hgeIntState state, int value)
  306. {
  307. switch(state) {
  308. case HGE_SCREENWIDTH: if(!pD3DDevice) nScreenWidth=value; break;
  309. case HGE_SCREENHEIGHT: if(!pD3DDevice) nScreenHeight=value; break;
  310. case HGE_SCREENBPP: if(!pD3DDevice) nScreenBPP=value; break;
  311. case HGE_SAMPLERATE: if(!hBass) nSampleRate=value;
  312. break;
  313. case HGE_FXVOLUME: nFXVolume=value;
  314. _SetFXVolume(nFXVolume);
  315. break;
  316. case HGE_MUSVOLUME: nMusVolume=value;
  317. _SetMusVolume(nMusVolume);
  318. break;
  319. case HGE_FPS: if(VertArray) break;
  320. if(pD3DDevice)
  321. {
  322. if((nHGEFPS>=0 && value <0) || (nHGEFPS<0 && value>=0))
  323. {
  324. if(value==HGEFPS_VSYNC)
  325. {
  326. d3dppW.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
  327. d3dppFS.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;
  328. }
  329. else
  330. {
  331. d3dppW.SwapEffect = D3DSWAPEFFECT_COPY;
  332. d3dppFS.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
  333. }
  334. if(procFocusLostFunc) procFocusLostFunc();
  335. _GfxRestore();
  336. if(procFocusGainFunc) procFocusGainFunc();
  337. }
  338. }
  339. nHGEFPS=value;
  340. if(nHGEFPS>0) nFixedDelta=int(1000.0f/value);
  341. else nFixedDelta=0;
  342. break;
  343. #ifdef DEMO
  344. case (hgeIntState)14: nDMO=value; break;
  345. #endif
  346. }
  347. }
  348. void CALL HGE_Impl::System_SetStateString(hgeStringState state, const char *value)
  349. {
  350. FILE *hf;
  351. switch(state) {
  352. case HGE_ICON: szIcon=value;
  353. if(pHGE->hwnd) SetClassLong(pHGE->hwnd, GCL_HICON, (LONG)LoadIcon(pHGE->hInstance, szIcon));
  354. break;
  355. case HGE_TITLE: strcpy(szWinTitle,value);
  356. if(pHGE->hwnd) SetWindowText(pHGE->hwnd, szWinTitle);
  357. break;
  358. case HGE_INIFILE: if(value) strcpy(szIniFile,Resource_MakePath(value));
  359. else szIniFile[0]=0;
  360. break;
  361. case HGE_LOGFILE: if(value)
  362. {
  363. strcpy(szLogFile,Resource_MakePath(value));
  364. hf=fopen(szLogFile, "w");
  365. if(!hf) szLogFile[0]=0;
  366. else fclose(hf);
  367. }
  368. else szLogFile[0]=0;
  369. break;
  370. }
  371. }
  372. bool CALL HGE_Impl::System_GetStateBool(hgeBoolState state)
  373. {
  374. switch(state) {
  375. case HGE_WINDOWED: return bWindowed;
  376. case HGE_ZBUFFER: return bZBuffer;
  377. case HGE_TEXTUREFILTER: return bTextureFilter;
  378. case HGE_USESOUND: return bUseSound;
  379. case HGE_DONTSUSPEND: return bDontSuspend;
  380. case HGE_HIDEMOUSE: return bHideMouse;
  381. }
  382. return false;
  383. }
  384. hgeCallback CALL HGE_Impl::System_GetStateFunc(hgeFuncState state)
  385. {
  386. switch(state) {
  387. case HGE_FRAMEFUNC: return procFrameFunc;
  388. case HGE_RENDERFUNC: return procRenderFunc;
  389. case HGE_FOCUSLOSTFUNC: return procFocusLostFunc;
  390. case HGE_FOCUSGAINFUNC: return procFocusGainFunc;
  391. case HGE_EXITFUNC: return procExitFunc;
  392. }
  393. return NULL;
  394. }
  395. HWND CALL HGE_Impl::System_GetStateHwnd(hgeHwndState state)
  396. {
  397. switch(state) {
  398. case HGE_HWND: return hwnd;
  399. case HGE_HWNDPARENT: return hwndParent;
  400. }
  401. return 0;
  402. }
  403. int CALL HGE_Impl::System_GetStateInt(hgeIntState state)
  404. {
  405. switch(state) {
  406. case HGE_SCREENWIDTH: return nScreenWidth;
  407. case HGE_SCREENHEIGHT: return nScreenHeight;
  408. case HGE_SCREENBPP: return nScreenBPP;
  409. case HGE_SAMPLERATE: return nSampleRate;
  410. case HGE_FXVOLUME: return nFXVolume;
  411. case HGE_MUSVOLUME: return nMusVolume;
  412. case HGE_FPS: return nHGEFPS;
  413. }
  414. return 0;
  415. }
  416. const char* CALL HGE_Impl::System_GetStateString(hgeStringState state) {
  417. switch(state) {
  418. case HGE_ICON: return szIcon;
  419. case HGE_TITLE: return szWinTitle;
  420. case HGE_INIFILE: if(szIniFile[0]) return szIniFile;
  421. else return 0;
  422. case HGE_LOGFILE: if(szLogFile[0]) return szLogFile;
  423. else return 0;
  424. }
  425. return NULL;
  426. }
  427. char* CALL HGE_Impl::System_GetErrorMessage()
  428. {
  429. return szError;
  430. }
  431. void CALL HGE_Impl::System_Log(const char *szFormat, ...)
  432. {
  433. FILE *hf = NULL;
  434. char tmp[256];
  435. if(!szLogFile[0]) return;
  436. hf = fopen(szLogFile, "a");
  437. if(!hf) return;
  438. vsprintf(tmp, szFormat, (char *)&szFormat+sizeof(szFormat));
  439. fprintf(hf, tmp);
  440. fprintf(hf, "n");
  441. fclose(hf);
  442. }
  443. bool CALL HGE_Impl::System_Launch(const char *url)
  444. {
  445. if((DWORD)ShellExecute(pHGE->hwnd, NULL, url, NULL, NULL, SW_SHOWMAXIMIZED)>32) return true;
  446. else return false;
  447. }
  448. void CALL HGE_Impl::System_Snapshot(const char *filename)
  449. {
  450. LPDIRECT3DSURFACE8 pSurf;
  451. char *shotname, tempname[_MAX_PATH];
  452. int i;
  453. if(!filename)
  454. {
  455. i=0;
  456. shotname=Resource_EnumFiles("shot???.bmp");
  457. while(shotname)
  458. {
  459. i++;
  460. shotname=Resource_EnumFiles();
  461. }
  462. sprintf(tempname, "shot%03d.bmp", i);
  463. filename=Resource_MakePath(tempname);
  464. }
  465. if(pD3DDevice)
  466. {
  467. pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurf);
  468. D3DXSaveSurfaceToFile(filename, D3DXIFF_BMP, pSurf, NULL, NULL);
  469. pSurf->Release();
  470. }
  471. }
  472. //////// Implementation ////////
  473. HGE_Impl::HGE_Impl()
  474. {
  475. hInstance=GetModuleHandle(0);
  476. hwnd=0;
  477. bActive=true;
  478. szError[0]=0;
  479. pD3D=0;
  480. pD3DDevice=0;
  481. d3dpp=0;
  482. pTargets=0;
  483. pCurTarget=0;
  484. pScreenSurf=0;
  485. pScreenDepth=0;
  486. pVB=0;
  487. pIB=0;
  488. VertArray=0;
  489. textures=0;
  490. hBass=0;
  491. bSilent=false;
  492. streams=0;
  493. hSearch=0;
  494. res=0;
  495. queue=0;
  496. Char=VKey=Zpos=0;
  497. Xpos=Ypos=0.0f;
  498. bMouseOver=false;
  499. bCaptured=false;
  500. nHGEFPS=HGEFPS_UNLIMITED;
  501. fTime=0.0f;
  502. fDeltaTime=0.0f;
  503. nFPS=0;
  504. procFrameFunc=0;
  505. procRenderFunc=0;
  506. procFocusLostFunc=0;
  507. procFocusGainFunc=0;
  508. procExitFunc=0;
  509. szIcon=0;
  510. strcpy(szWinTitle,"HGE");
  511. nScreenWidth=800;
  512. nScreenHeight=600;
  513. nScreenBPP=32;
  514. bWindowed=false;
  515. bZBuffer=false;
  516. bTextureFilter=true;
  517. szLogFile[0]=0;
  518. szIniFile[0]=0;
  519. bUseSound=true;
  520. nSampleRate=44100;
  521. nFXVolume=100;
  522. nMusVolume=100;
  523. nFixedDelta=0;
  524. bHideMouse=true;
  525. bDontSuspend=false;
  526. hwndParent=0;
  527. #ifdef DEMO
  528. nDMO=0;
  529. #endif
  530. GetModuleFileName(GetModuleHandle(NULL), szAppPath, sizeof(szAppPath));
  531. int i;
  532. for(i=strlen(szAppPath)-1; i>0; i--) if(szAppPath[i]=='\') break;
  533. szAppPath[i+1]=0;
  534. }
  535. void HGE_Impl::_PostError(char *error) {
  536. System_Log(error);
  537. strcpy(szError,error);
  538. }
  539. void HGE_Impl::_FocusChange(bool bAct) {
  540. bActive=bAct;
  541. if(bActive) {
  542. _GfxRestore();
  543. if(procFocusGainFunc) procFocusGainFunc();
  544. }
  545. else {
  546. if(procFocusLostFunc) procFocusLostFunc();
  547. }
  548. }
  549. LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
  550. switch(msg) {
  551. case WM_CREATE: 
  552. return FALSE;
  553. case WM_PAINT:
  554. if(pHGE->procRenderFunc) pHGE->procRenderFunc();
  555. break;
  556. case WM_DESTROY:
  557. PostQuitMessage(0);
  558. return FALSE;
  559. case WM_ACTIVATEAPP:
  560. if(pHGE->pD3D && pHGE->bActive != (wparam == TRUE)) pHGE->_FocusChange(wparam == TRUE);
  561. return FALSE;
  562. case WM_SETCURSOR:
  563. if(pHGE->bActive && LOWORD(lparam)==HTCLIENT && pHGE->bHideMouse) SetCursor(NULL);
  564. else SetCursor(LoadCursor(NULL, IDC_ARROW));
  565. return FALSE;
  566. case WM_SYSKEYDOWN:
  567. if(wparam==VK_F4)
  568. {
  569. if(pHGE->procExitFunc)
  570. {
  571. if(pHGE->procExitFunc())
  572. return DefWindowProc(hwnd, msg, wparam, lparam);
  573. else
  574. return FALSE;
  575. }
  576. else
  577. return DefWindowProc(hwnd, msg, wparam, lparam);
  578. }
  579. else
  580. {
  581. pHGE->_BuildEvent(INPUT_KEYDOWN, wparam, HIWORD(lparam) & 0xFF, (lparam & 0x40000000) ? HGEINP_REPEAT:0, -1, -1);
  582. return FALSE;
  583. }
  584. case WM_CHAR:
  585. case WM_KEYDOWN:
  586. pHGE->_BuildEvent(INPUT_KEYDOWN, wparam, HIWORD(lparam) & 0xFF, (lparam & 0x40000000) ? HGEINP_REPEAT:0, -1, -1);
  587. return FALSE;
  588. case WM_SYSKEYUP:
  589. pHGE->_BuildEvent(INPUT_KEYUP, wparam, HIWORD(lparam) & 0xFF, 0, -1, -1);
  590. return FALSE;
  591. case WM_KEYUP:
  592. pHGE->_BuildEvent(INPUT_KEYUP, wparam, HIWORD(lparam) & 0xFF, 0, -1, -1);
  593. return FALSE;
  594. case WM_LBUTTONDOWN:
  595. SetFocus(hwnd);
  596. pHGE->_BuildEvent(INPUT_MBUTTONDOWN, HGEK_LBUTTON, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  597. return FALSE;
  598. case WM_MBUTTONDOWN:
  599. SetFocus(hwnd);
  600. pHGE->_BuildEvent(INPUT_MBUTTONDOWN, HGEK_MBUTTON, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  601. return FALSE;
  602. case WM_RBUTTONDOWN:
  603. SetFocus(hwnd);
  604. pHGE->_BuildEvent(INPUT_MBUTTONDOWN, HGEK_RBUTTON, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  605. return FALSE;
  606. case WM_LBUTTONDBLCLK:
  607. pHGE->_BuildEvent(INPUT_MBUTTONDOWN, HGEK_LBUTTON, 0, HGEINP_REPEAT, LOWORDINT(lparam), HIWORDINT(lparam));
  608. return FALSE;
  609. case WM_MBUTTONDBLCLK:
  610. pHGE->_BuildEvent(INPUT_MBUTTONDOWN, HGEK_MBUTTON, 0, HGEINP_REPEAT, LOWORDINT(lparam), HIWORDINT(lparam));
  611. return FALSE;
  612. case WM_RBUTTONDBLCLK:
  613. pHGE->_BuildEvent(INPUT_MBUTTONDOWN, HGEK_RBUTTON, 0, HGEINP_REPEAT, LOWORDINT(lparam), HIWORDINT(lparam));
  614. return FALSE;
  615. case WM_LBUTTONUP:
  616. pHGE->_BuildEvent(INPUT_MBUTTONUP, HGEK_LBUTTON, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  617. return FALSE;
  618. case WM_MBUTTONUP:
  619. pHGE->_BuildEvent(INPUT_MBUTTONUP, HGEK_MBUTTON, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  620. return FALSE;
  621. case WM_RBUTTONUP:
  622. pHGE->_BuildEvent(INPUT_MBUTTONUP, HGEK_RBUTTON, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  623. return FALSE;
  624. case WM_MOUSEMOVE:
  625. pHGE->_BuildEvent(INPUT_MOUSEMOVE, 0, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  626. return FALSE;
  627. case 0x020A: // WM_MOUSEWHEEL, GET_WHEEL_DELTA_WPARAM(wparam);
  628. pHGE->_BuildEvent(INPUT_MOUSEWHEEL, short(HIWORD(wparam))/120, 0, 0, LOWORDINT(lparam), HIWORDINT(lparam));
  629. return FALSE;
  630. case WM_SIZE:
  631. if(wparam==SIZE_RESTORED) pHGE->_Resize(LOWORD(lparam), HIWORD(lparam));
  632. //return FALSE;
  633. break;
  634. case WM_SYSCOMMAND:
  635. if(wparam==SC_CLOSE)
  636. {
  637. if(pHGE->procExitFunc)
  638. {
  639. if(pHGE->procExitFunc()) { pHGE->bActive=false; return DefWindowProc(hwnd, msg, wparam, lparam); }
  640. else return FALSE;
  641. }
  642. else { pHGE->bActive=false; return DefWindowProc(hwnd, msg, wparam, lparam); }
  643. }
  644. break;
  645. }
  646. return DefWindowProc(hwnd, msg, wparam, lparam);
  647. }