Write a VC++ Program to change Background Color of the Window after every 2 Seconds.And at each Mouse Click the fill Pattern should Change.

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

RECT rect;
HBRUSH hbr;
static int i=0;

switch (message)
{
case WM_CREATE:
SetTimer(hWnd,1,2000,NULL);
return 0;
case WM_TIMER:
hdc=GetDC(hWnd);
GetClientRect(hWnd,&rect);
if(i==0)
hbr=CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255));
else
hbr=CreateHatchBrush(i,RGB(rand()%255,rand()%255,rand()%255));

FillRect(hdc,&rect,hbr);
return 0;

case WM_LBUTTONDOWN:
if(i<5)
{
i++;
}
else
{
i=0;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

Comments

Popular posts from this blog

Uploading Image to Sql Server Image Datatype in asp.net using fileupload Control

Get Running Sum of Query SQL Query