Saturday, January 31, 2009

VP first two expts

#include

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int nShowCmd)

{

      static char szAppName[]="Mouse";

      WNDCLASS wc;

      HWND hwnd;

      MSG msg;

      wc.style=CS_HREDRAW|CS_VREDRAW;

      wc.lpfnWndProc=(WNDPROC)WndProc;

      wc.cbClsExtra=0;

      wc.cbWndExtra=0;

      wc.hInstance=hInstance;

      wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);

      wc.hCursor=LoadCursor(NULL,IDC_ARROW);

      wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

      wc.lpszMenuName=NULL;

      wc.lpszClassName=szAppName;

      RegisterClass(&wc);

      hwnd=CreateWindow(szAppName,szAppName,WS_OVERLAPPEDWINDOW|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

      UpdateWindow(hwnd);

      while(GetMessage(&msg,NULL,0,0))

      {

            TranslateMessage(&msg);

            DispatchMessage(&msg);

      }

      return msg.wParam;

}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)

{

      HDC hdc;

      switch(message)

      {

      case WM_LBUTTONDOWN:

            InvalidateRect(hwnd,NULL,TRUE);

            return 0;

      case WM_MOUSEMOVE:

            if(wParam && MK_LBUTTON)

            {

                  hdc=GetDC(hwnd);

                                                    SetPixel(hdc,LOWORD(lParam),HIWORD(lParam),RGB(255,0,0));

                  ReleaseDC(hwnd,hdc);

            }

            return 0;

            case WM_LBUTTONUP:

            InvalidateRect(hwnd,NULL,FALSE);

            return 0;

      case WM_DESTROY:

            PostQuitMessage(0);

            return 0;

      }

      return DefWindowProc(hwnd,message,wParam,lParam);

} 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

OUTPUT:     
 
 

Your browser may not support display of this image. 
 
 
 
 
 
 
 
 
 
 
 
 
 

       
 
 
 
 
 
 
 
 

SOURCE CODE:   

#include

#define MAXPOINTS 100

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)

{

PAINTSTRUCT ps;

static POINT PT[MAXPOINTS];

int icount=0;

HDC hdc;

HPEN hPen,hPen1;

HBRUSH hbr;

RECT rect;

switch (message)

{

case WM_PAINT:

hdc=BeginPaint(hwnd,&ps);

GetClientRect(hwnd,&rect);  

hPen1=CreatePen(PS_SOLID,10,1);

hbr=(HBRUSH)GetStockObject(7);

SelectObject(hdc,hPen1);

Rectangle(hdc,100,120,620,300);

hPen=CreatePen(PS_SOLID,3,1);

SelectObject(hdc,hPen);

hbr=CreateHatchBrush(HS_HORIZONTAL,RGB(55,220,0));

SelectObject(hdc,hbr);

Ellipse(hdc,100,120,620,300);

MoveToEx(hdc,100,120,NULL);

LineTo(hdc,165,150);

MoveToEx(hdc,620,120,NULL);

LineTo(hdc,550,150);

MoveToEx(hdc,100,300,NULL);

LineTo(hdc,165,270);

MoveToEx(hdc,620,300,NULL);

LineTo(hdc,550,270);

hbr=CreateHatchBrush(HS_VERTICAL,RGB(155,120,220));

SelectObject(hdc,hbr);

Rectangle(hdc,165,150,550,270);

DeleteObject(hPen);

DeleteObject(hPen1);

DeleteObject(hbr);

EndPaint(hwnd,&ps);

return 0;

case WM_DESTROY:

PostQuitMessage(0);

                                                               

return 0;

}

                                            

return DefWindowProc(hwnd,message,wParam,lParam);

}

                                    

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int nShowCmd)

{

static char szAppName[]="MyApp";

WNDCLASS wc;

HWND hwnd;

MSG msg;

wc.style=CS_HREDRAW|CS_VREDRAW;

wc.lpfnWndProc=(WNDPROC)WndProc;

wc.cbClsExtra=0;

wc.cbWndExtra=0;

wc.hInstance=hInstance;

wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);

wc.hCursor=LoadCursor(NULL,IDC_ARROW)

wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

wc.lpszMenuName=NULL;

wc.lpszClassName=szAppName;

RegisterClass(&wc);

hwnd=CreateWindow(szAppName,szAppName,WS_OVERLAPPEDWINDOW|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

} 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


Your browser may not support display of this image. 
 
 
 
 
 

No comments:

Post a Comment

My Blog List

Wanna play chess?