|
| #include <windows.h> //*** TODO: insert off screen code here **** //*** The sample code for stars *** #define MAXSTAR 100 typdef struct { int x, y; int t; } STAR; static STAR *stars; void InitStars(void) { int cnt; stars = (STAR*)malloc(sizeof(STAR)*MAXSTAR); for(cnt=0; cnt<MAXSTAR; cnt++) { stars[cnt].x = Random() % 240; stars[cnt].y = Random() % 320; stars[cnt].t = Random() % 255; } } void DeinitStars(void) { free(stars); } void DrawStars(void) { int cnt, speed, bright; PatBlt(hOffscreenDC,0,0,240,320,BLACKNESS); for(cnt=0; cnt<MAXSTAR; cnt++) { speed = 10 - (stars[cnt].t / 20); bright = 256 - stars[cnt].t; SetPixel(hOffscreenDC,stars.x,stars.y,RGB(bright,bright,bright)); stars.y += speed; if(stars.y > 320) { stars[cnt].x = Random() % 240; stars[cnt].y = 0; stars[cnt].t = Random() % 255; } } } LRESULT MainWndProc(HWND hWnd, UINT message, WPARAM uParam, LPARAM lParam) { switch(message) { case WM_WMTIMER: DrawStars(); UpdateDisplay(hWnd); break; case WM_CREATE: InitOffscreen(240,320); InitStars(); break; case WM_DESTROY: DeinitStars(); DeinitOffscreen(); PostQuitMessage(0); break; case WM_KEYDOWN: DestroyWindow(hWnd); break; default: DefWindowProc(hWnd, message, uParam, lParam); } return 0; } |
| HBTIMAP hUFO; .... LRESULT MainWndProc(HWND hWnd, UINT message, WPARAM uParam, LPARAM lParam) { switch(message) { case WM_WMTIMER: DrawStars(); TransparentImage(hOffscreenDC,100,300,24,20,hUFO,...); UpdateDisplay(hWnd); break; case WM_CREATE: InitOffscreen(240,320); InitStars(); hUFO = LoadBitmap(hInst,(TCHAR*)1); break; case WM_DESTROY: DeleteObject(hUFO); DeinitStars(); DeinitOffscreen(); PostQuitMessage(0); break; case WM_KEYDOWN: DestroyWindow(hWnd); break; default: DefWindowProc(hWnd, message, uParam, lParam); } return 0; } |