EDN Admin
Well-known member
Im writing a bouncing ball game but im stuck in moving the rectangle , i dont know whats wrong with my code !! , and i want to put a timer ( time counter in xx:xx format ) , i wrote the SetTimer but when i write: if(wparam==2)WGPrintf(hdc,x,x,"00:%d",gcounter++)
... nothing appears !
<div style="color:Black;background-color:White; <pre>
#include <span style="color:#A31515; "wingui.h"
<span style="color:Blue; int gx=0,gy=0,gdx=10,gdy=10;
<span style="color:Blue; int rx,ry,rx1,ry1;
<span style="color:Blue; int gcounter=0;
<span style="color:Blue; int score=0;
LRESULT WINAPI Wndproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
<span style="color:Blue; int screenheight, screenwidth;
HDC hdc;
HFONT holdfont,font;
HBRUSH holdbrush,brush;
<span style="color:Blue; switch(message)
{
<span style="color:Blue; case WM_CREATE:
{
SetWindowText(hwnd, <span style="color:#A31515; "E7NA GAMDEEN AWY");
screenwidth=GetSystemMetrics(SM_CXSCREEN);
screenheight=GetSystemMetrics(SM_CYSCREEN);
SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MAXIMIZEBOX);
SetWindowPos(hwnd, HWND_TOP, 0, 0, screenwidth, screenheight, SWP_SHOWWINDOW);
SetTimer(hwnd,1,10,NULL);
SetTimer(hwnd,2,1000,NULL);
}
<span style="color:Blue; break;
<span style="color:Blue; case WM_TIMER:
{
<span style="color:Blue; if(wparam==1)
{
RECT R;
GetClientRect(hwnd, &R);
<span style="color:Blue; int width = WGGetClientWidth(hwnd);
<span style="color:Blue; int height = WGGetClientHeight(hwnd);
<span style="color:Blue; int rx=WGGetClientWidth(hwnd);
<span style="color:Blue; int ry=WGGetClientHeight(hwnd);
rx1=rx/2;
<span style="color:Blue; if(gx>R.right||gx<R.left)gdx*=-1;
<span style="color:Blue; if(gy<R.top)gdy*=-1;
<span style="color:Blue; if(gy>960&&gx>rx1-180&&gx<rx1+180)
{
gdy*=-1;
score++;
}
<span style="color:Blue; if(gy>R.bottom)<span style="color:Blue; break;
gx+=gdx;
gy+=gdy;
hdc=GetDC(hwnd);
PatBlt(hdc,0,0,width,height,BLACKNESS);
HFONT font=WGCreateFont(<span style="color:#A31515; "Calibri",20,FS_BOLD,0);
holdfont=(HFONT)SelectObject(hdc,font);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(255,0,0));
WGPrintf(hdc,20,20,<span style="color:#A31515; "SCORE %d",score);
Ellipse(hdc,gx-35,gy-35,gx+35,gy+35);
Rectangle(hdc,rx1-150,ry-70,rx1+150,ry-40);
ReleaseDC(hwnd,hdc);
}
}
<span style="color:Blue; break;
{
<span style="color:Blue; case WM_KEYDOWN:
{
<span style="color:Blue; switch(wparam)
{
<span style="color:Blue; case VK_RIGHT: rx1+=30; <span style="color:Blue; break;
<span style="color:Blue; case VK_LEFT: rx1-=30; <span style="color:Blue; break;
}
InvalidateRect(hwnd,NULL,FALSE);
}
}
<span style="color:Blue; break;
}
<span style="color:Blue; return WGDefaultWindowProc(hwnd, message, wparam, lparam);
}
<span style="color:Blue; int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE, LPSTR, <span style="color:Blue; int cmdshow)
{
<span style="color:Blue; return WGCreateMainWindow(hinstance, cmdshow, Wndproc);
}
[/code]
View the full article
... nothing appears !
<div style="color:Black;background-color:White; <pre>
#include <span style="color:#A31515; "wingui.h"
<span style="color:Blue; int gx=0,gy=0,gdx=10,gdy=10;
<span style="color:Blue; int rx,ry,rx1,ry1;
<span style="color:Blue; int gcounter=0;
<span style="color:Blue; int score=0;
LRESULT WINAPI Wndproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
<span style="color:Blue; int screenheight, screenwidth;
HDC hdc;
HFONT holdfont,font;
HBRUSH holdbrush,brush;
<span style="color:Blue; switch(message)
{
<span style="color:Blue; case WM_CREATE:
{
SetWindowText(hwnd, <span style="color:#A31515; "E7NA GAMDEEN AWY");
screenwidth=GetSystemMetrics(SM_CXSCREEN);
screenheight=GetSystemMetrics(SM_CYSCREEN);
SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MAXIMIZEBOX);
SetWindowPos(hwnd, HWND_TOP, 0, 0, screenwidth, screenheight, SWP_SHOWWINDOW);
SetTimer(hwnd,1,10,NULL);
SetTimer(hwnd,2,1000,NULL);
}
<span style="color:Blue; break;
<span style="color:Blue; case WM_TIMER:
{
<span style="color:Blue; if(wparam==1)
{
RECT R;
GetClientRect(hwnd, &R);
<span style="color:Blue; int width = WGGetClientWidth(hwnd);
<span style="color:Blue; int height = WGGetClientHeight(hwnd);
<span style="color:Blue; int rx=WGGetClientWidth(hwnd);
<span style="color:Blue; int ry=WGGetClientHeight(hwnd);
rx1=rx/2;
<span style="color:Blue; if(gx>R.right||gx<R.left)gdx*=-1;
<span style="color:Blue; if(gy<R.top)gdy*=-1;
<span style="color:Blue; if(gy>960&&gx>rx1-180&&gx<rx1+180)
{
gdy*=-1;
score++;
}
<span style="color:Blue; if(gy>R.bottom)<span style="color:Blue; break;
gx+=gdx;
gy+=gdy;
hdc=GetDC(hwnd);
PatBlt(hdc,0,0,width,height,BLACKNESS);
HFONT font=WGCreateFont(<span style="color:#A31515; "Calibri",20,FS_BOLD,0);
holdfont=(HFONT)SelectObject(hdc,font);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(255,0,0));
WGPrintf(hdc,20,20,<span style="color:#A31515; "SCORE %d",score);
Ellipse(hdc,gx-35,gy-35,gx+35,gy+35);
Rectangle(hdc,rx1-150,ry-70,rx1+150,ry-40);
ReleaseDC(hwnd,hdc);
}
}
<span style="color:Blue; break;
{
<span style="color:Blue; case WM_KEYDOWN:
{
<span style="color:Blue; switch(wparam)
{
<span style="color:Blue; case VK_RIGHT: rx1+=30; <span style="color:Blue; break;
<span style="color:Blue; case VK_LEFT: rx1-=30; <span style="color:Blue; break;
}
InvalidateRect(hwnd,NULL,FALSE);
}
}
<span style="color:Blue; break;
}
<span style="color:Blue; return WGDefaultWindowProc(hwnd, message, wparam, lparam);
}
<span style="color:Blue; int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE, LPSTR, <span style="color:Blue; int cmdshow)
{
<span style="color:Blue; return WGCreateMainWindow(hinstance, cmdshow, Wndproc);
}
[/code]
View the full article