Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
killmichnich
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
#include <windows.h> #include <scrnsave.h> #include "Snow.h" UINT timer_id; CSnow* Snow; long WINAPI ScreenSaverProc(HWND hWnd,UINT message, WPARAM wParam,LPARAM lParam) { HDC hdc; hdc = GetDC(hWnd); switch(message) { case WM_CREATE: { srand(GetTickCount()); SetTimer(hWnd,timer_id,3,NULL); int screenX = GetSystemMetrics(SM_CXSCREEN); int screenY = GetSystemMetrics(SM_CYSCREEN); Snow = new CSnow(100, screenX, screenY, hdc); break; } case WM_TIMER: { PostMessage(hWnd, WM_PAINT, 0, 0); break; } case WM_DESTROY: { KillTimer(hWnd,timer_id); ReleaseDC(hWnd,hdc); delete Snow; Snow = NULL; break; } case WM_PAINT: { PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); Snow->Draw(); EndPaint(hWnd, &ps); break; } } return DefScreenSaverProc(hWnd,message,wParam,lParam); } BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: EndDialog(hWnd,0); return TRUE; case IDCANCEL: EndDialog(hWnd,0); return FALSE; } break; case WM_CLOSE: EndDialog(hWnd,0); return TRUE; } return FALSE; } BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#pragma once #include <windows.h> #include <iostream> #include <map> using namespace std; struct SNOWFLAKE { float Xpos; float Ypos; float vx; float vy; }; class CSnow { public: CSnow(); CSnow(int numberofflakes, int scr_width, int scr_height, HDC hDc); void Draw(); protected: map<int, SNOWFLAKE>SnowFlakes; int SCR_Width; int SCR_Height; HDC hdc; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include "Snow.h" CSnow::CSnow() { SCR_Width = 800; SCR_Height = 600; hdc = GetDC(NULL); } CSnow::CSnow(int numberofflakes, int scr_width, int scr_height, HDC hDc) { SCR_Width = scr_width; SCR_Height = scr_height; hdc = hDc; for(int i=0; i<numberofflakes; i++) { SNOWFLAKE s = {(float)(rand()%SCR_Width), (float)(rand()%SCR_Height), 1, 10}; SnowFlakes[i] = s; } } void CSnow::Draw() { HPEN pen = CreatePen( PS_SOLID,1, RGB(0, 0, 0)); SelectObject(hdc, pen); Rectangle(hdc, 0, 0, SCR_Width, SCR_Height); for(int i=0; i<SnowFlakes.size(); i++) { SNOWFLAKE s = SnowFlakes[i]; s.Xpos+=s.vx; s.Ypos+=s.vy; if(s.Xpos>=SCR_Width || s.Ypos>=SCR_Height) { s.Xpos = (float)(rand()%SCR_Width); s.Ypos = 0; } if(s.Xpos>0 && s.Xpos<SCR_Width && s.Ypos>0 && s.Ypos<SCR_Height) { SetPixel(hdc, (int)s.Xpos, (int)s.Ypos, RGB(255, 0, 255)); } } DeleteObject(pen); } |
killmichnich
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
case WM_TIMER: { PostMessage(hWnd, WM_PAINT, 0, 0); break; } |
Treue Seele
Werbeanzeige