Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
//globale Variablen
char szClassName[ ] = "WindowsApp";
HDC hdc;
int xmax, ymax;
int xball, yball;
int r =13;
int i =6;
int dx=2;
int dy=2;
int r2;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/*Wenn was schief gelaufen ist, Fehlermeldung*/
if (!RegisterClassEx (&wincl))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
/* Wenn was schief gelaufen Fehlermeldung */
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow (hwnd, nFunsterStil); //Fenster zeigen
UpdateWindow(hwnd);
/*Message Loop*/
while (GetMessage (&messages, NULL, 0, 0) > 0)
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
}
/* window procedur */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CLOSE: //Beim schließen des Fensters
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_KEYDOWN: //bei Tastendruck
{
switch(wParam)
{
case VK_LEFT:
xball-=dx;
_sleep(1);
break;
case VK_RIGHT:
xball +=dx;
_sleep(1);
break;
case VK_UP:
yball -= dy;
_sleep(0);
break;
case VK_DOWN:
yball += dy;
_sleep(0);
break;
case VK_SPACE:
shootBomb(hwnd);
ReleaseDC(hwnd, hdc);
break;
}
}
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
RECT rcClient;
GetClientRect(hwnd, &rcClient); //Fenstergeometrie von hwnd
int i=0;
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
}
case WM_PAINT: //Zeichnen
{
hdc = GetDC(hwnd); //Zeichen starten
Ellipse(hdc, xball-r, yball-r, xball+r, yball+r);
ValidateRect(hwnd, 0);
//Zeichnen beenden
}
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
/* include ... */
void shootBomb(HWND hwnd)
{
/* ... */
}
/* variablen */
/* WinMain */
/* include ... */
void shootBomb(HWND);
/* variablen */
/* WinMain */
/* WindowsProcedur */
void shootBomb(HWND hwnd)
{
/* ... */
}
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
RECT rcClient;
GetClientRect(hwnd, &rcClient); //Fenstergeometrie von hwnd
HDC hdcBuffer;
HBITMAP hbmBuffer, hbmOldBuffer; //Buffer
int i=0;
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
/* Double Buffering */
hdcBuffer = CreateCompatibleDC(hdc);
hbmBuffer = CreateCompatibleBitmap(hdc, rcClient.right, rcClient.bottom);
hbmOldBuffer = SelectObject(hdcBuffer, hbmBuffer);
BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcBuffer, 0, 0, SRCCOPY);
/* Bombe zeichnen */
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
}
case VK_LEFT:
xball-=dx;
UpdateBall(hwnd); //Ball neu zeichnen
break;
/* ... */
case VK_SPACE:
shootBomb(hwnd); //Bombe werfen
break;
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
int i=0;
RECT rcClient;
GetClientRect(hwnd, &rcClient);
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
doubleBuffering(hwnd, hdc);
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
}
void UpdateBall(HWND hwnd)
{
hdc = GetDC(hwnd);
doubleBuffering(hwnd,hdc);
Ellipse(hdc, xball-r, yball-r, xball+r, yball+r);
}
void doubleBuffering(HWND hwnd, HDC hdc)
{
RECT rcClient;
GetClientRect(hwnd, &rcClient); //Fenstergeometrie von hwnd
HDC hdcBuffer;
HBITMAP hbmBuffer, hbmOldBuffer; //Buffer
hdcBuffer = CreateCompatibleDC(hdc);
hbmBuffer = CreateCompatibleBitmap(hdc, rcClient.right, rcClient.bottom); //Bitmap erstellen
hbmOldBuffer = SelectObject(hdcBuffer, hbmBuffer);
FillRect(hdcBuffer, &rcClient, CreateSolidBrush(RGB(255,0,0))); //mit rgb-Farbe füllen
BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcBuffer, 0, 0, SRCCOPY); //Buffer zeichnen
}
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
//globale Variablen
char szClassName[ ] = "WindowsApp";
HDC hdc;
PAINTSTRUCT ps;
int xmax, ymax;
int xball, yball;
int r =15;
int dx=5;
int dy=5;
int r2;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/*Wenn was schief gelaufen ist, Fehlermeldung*/
if (!RegisterClassEx (&wincl))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
/* Wenn was schief gelaufen Fehlermeldung */
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow (hwnd, nFunsterStil); //Fenster zeigen
UpdateWindow(hwnd);
/*Message Loop*/
while (GetMessage (&messages, NULL, 0, 0) > 0)
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
}
/* window procedur */
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
int i=0;
RECT rcClient;
GetClientRect(hwnd, &rcClient);
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
doubleBuffering(hwnd, hdc);
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
}
void UpdateBall(HWND hwnd)
{
hdc = GetDC(hwnd);
doubleBuffering(hwnd,hdc);
Ellipse(hdc, xball-r, yball-r, xball+r, yball+r);
}
void doubleBuffering(HWND hwnd, HDC hdc)
{
RECT rcClient;
GetClientRect(hwnd, &rcClient); //Fenstergeometrie von hwnd
HDC hdcBuffer;
HBITMAP hbmBuffer, hbmOldBuffer; //Buffer
hdcBuffer = CreateCompatibleDC(hdc);
hbmBuffer = CreateCompatibleBitmap(hdc, rcClient.right, rcClient.bottom); //Bitmap erstellen
hbmOldBuffer = SelectObject(hdcBuffer, hbmBuffer);
FillRect(hdcBuffer, &rcClient, CreateSolidBrush(RGB(255,0,0))); //mit rgb-Farbe füllen
BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcBuffer, 0, 0, SRCCOPY); //Buffer zeichnen
DeleteObject(hdcBuffer);
DeleteObject(hbmOldBuffer);
DeleteObject(hbmBuffer);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CLOSE: //Beim schließen des Fensters
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_KEYDOWN: //bei Tastendruck
{
switch(wParam)
{
case VK_LEFT:
xball-=dx;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_RIGHT:
xball +=dx;
UpdateBall(hwnd);
break;
case VK_UP:
yball -= dy;
UpdateBall(hwnd);
break;
case VK_DOWN:
yball += dy;
UpdateBall(hwnd);
break;
case VK_SPACE:
shootBomb(hwnd); //Bombe werfen
break;
}
}
case WM_PAINT: //Zeichnen
{
hdc = GetDC(hwnd); //Zeichen starten
Ellipse(hdc, xball-r, yball-r, xball+r, yball+r);
ValidateRect(hwnd, 0);
//Zeichnen beenden
}
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
//globale Variablen
char szClassName[ ] = "WindowsApp";
HDC hdc;
int xmax, ymax;
int xball, yball;
int r =15;
int dx=5;
int dy=5;
int r2;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/*Wenn was schief gelaufen ist, Fehlermeldung*/
if (!RegisterClassEx (&wincl))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
/* Wenn was schief gelaufen Fehlermeldung */
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow (hwnd, nFunsterStil); //Fenster zeigen
UpdateWindow(hwnd);
/*Message Loop*/
while (GetMessage (&messages, NULL, 0, 0) > 0)
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
}
/* window procedur */
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
int i=0;
RECT rcClient;
GetClientRect(hwnd, &rcClient);
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
doubleBuffering(hwnd, hdc);
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
void UpdateBall(HWND hwnd)
{
hdc = GetDC(hwnd);
doubleBuffering(hwnd,hdc);
Ellipse(hdc, xball-r, yball-r, xball+r, yball+r);
}
void doubleBuffering(HWND hwnd, HDC hdc)
{
RECT rcClient;
GetClientRect(hwnd, &rcClient); //Fenstergeometrie von hwnd
HDC hdcBuffer;
HBITMAP hbmBuffer, hbmOldBuffer; //Buffer
hdcBuffer = CreateCompatibleDC(hdc);
hbmBuffer = CreateCompatibleBitmap(hdc, rcClient.right, rcClient.bottom); //Bitmap erstellen
hbmOldBuffer = SelectObject(hdcBuffer, hbmBuffer);
FillRect(hdcBuffer, &rcClient, CreateSolidBrush(RGB(255,0,0))); //mit rgb-Farbe füllen
BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcBuffer, 0, 0, SRCCOPY); //Buffer zeichnen
}
void shootBomb(HWND);
void UpdateBall(HWND);
void doubleBuffering(HWND, HDC);
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CLOSE: //Beim schließen des Fensters
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_KEYDOWN: //bei Tastendruck
{
switch(wParam)
{
case VK_LEFT:
xball-=dx;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_RIGHT:
xball +=dx;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_UP:
yball -= dy;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_DOWN:
yball += dy;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_SPACE:
shootBomb(hwnd); //Bombe werfen
break;
}
}
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
int i=0;
RECT rcClient;
GetClientRect(hwnd, &rcClient);
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
doubleBuffering(hwnd, hdc);
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
[COLOR=darkred][B]}[/B][/COLOR] //hat gefehlt
void UpdateBall(HWND hwnd)
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
//globale Variablen
char szClassName[ ] = "WindowsApp";
HDC hdc;
int xmax, ymax;
int xball, yball;
int r =15;
int dx=5;
int dy=5;
int r2;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/*Wenn was schief gelaufen ist, Fehlermeldung*/
if (!RegisterClassEx (&wincl))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
/* Wenn was schief gelaufen Fehlermeldung */
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow (hwnd, nFunsterStil); //Fenster zeigen
UpdateWindow(hwnd);
/*Message Loop*/
while (GetMessage (&messages, NULL, 0, 0) > 0)
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
}
/* window procedur */
void shootBomb(HWND hwnd)
{
hdc = GetDC(hwnd);
int i=0;
RECT rcClient;
GetClientRect(hwnd, &rcClient);
while(yball+r2+i<rcClient.bottom) //solange der Boden nicht erreicht wurde
{
doubleBuffering(hwnd, hdc);
Ellipse(hdc, xball-r2, yball-r2+i, xball+r2, yball+r2+i); //r2 = radius der Bombe
_sleep(10);
i+=10;
}
}
void UpdateBall(HWND hwnd)
{
hdc = GetDC(hwnd);
doubleBuffering(hwnd,hdc);
Ellipse(hdc, xball-r, yball-r, xball+r, yball+r);
}
void doubleBuffering(HWND hwnd, HDC hdc)
{
RECT rcClient;
GetClientRect(hwnd, &rcClient); //Fenstergeometrie von hwnd
HDC hdcBuffer;
HBITMAP hbmBuffer, hbmOldBuffer; //Buffer
hdcBuffer = CreateCompatibleDC(hdc);
hbmBuffer = CreateCompatibleBitmap(hdc, rcClient.right, rcClient.bottom); //Bitmap erstellen
hbmOldBuffer = SelectObject(hdcBuffer, hbmBuffer);
FillRect(hdcBuffer, &rcClient, CreateSolidBrush(RGB(255,0,0))); //mit rgb-Farbe füllen
BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcBuffer, 0, 0, SRCCOPY); //Buffer zeichnen
}
void shootBomb(HWND);
void UpdateBall(HWND);
void doubleBuffering(HWND, HDC);
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CLOSE: //Beim schließen des Fensters
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_KEYDOWN: //bei Tastendruck
{
switch(wParam)
{
case VK_LEFT:
xball-=dx;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_RIGHT:
xball +=dx;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_UP:
yball -= dy;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_DOWN:
yball += dy;
UpdateBall(hwnd); //Ball neu zeichnen
break;
case VK_SPACE:
shootBomb(hwnd); //Bombe werfen
break;
}
}
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}