Write a Window Program to Create Various Brushes and Change the Background Color to Brushesh on Left Mouse Click.



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

RECT rect;
HBRUSH hbr;
HBITMAP hBitmap;

static int f=0;
static BYTE bits[]={0*51,0*77,0*10,0*00,
0*57,0*77,0*50,0*00,
0*13,0*77,0*50,0*00,
0*51,0*11,0*10,0*00};

hBitmap=CreateBitmap(20,5,1,1,bits);
switch (message)
{

case WM_LBUTTONDOWN:
hdc=GetDC(hWnd);
f++;
if(f>8)
f=1;

GetClientRect(hWnd,&rect);

switch(f)
{
case 1:
hbr=CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255));
break;
case 2:
hbr=CreateHatchBrush(HS_CROSS,RGB(rand()%255,rand()%255,rand()%255));
break;
case 3:
hbr=CreateHatchBrush(HS_BDIAGONAL,RGB(rand()%255,rand()%255,rand()%255));
break;
case 4:
hbr=CreateHatchBrush(HS_DIAGCROSS,RGB(rand()%255,rand()%255,rand()%255));
break;
case 5:
hbr=CreateHatchBrush(HS_FDIAGONAL,RGB(rand()%255,rand()%255,rand()%255));
break;
case 6:
hbr=CreateHatchBrush(HS_HORIZONTAL,RGB(rand()%255,rand()%255,rand()%255));
break;
case 7:
hbr=CreateHatchBrush(HS_VERTICAL,RGB(rand()%255,rand()%255,rand()%255));
break;
case 8:
hbr=CreatePatternBrush(hBitmap);
break;
}
SelectObject(hdc,hbr);
FillRect(hdc,&rect,hbr);

break;

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