Visual C++/Windows SDK Program for the Implementation of Line, Rectangle, Ellipse, Rounded Rectangle Demonstration | CS1255 - Visual Programming Laboratory

AIM:
To write a Visual C++/Windows SDK Program for the Implementation of Line, Rectangle, Ellipse, Rounded Rectangle Demonstration in CS1255 - Visual Programming Lab.

SOURCE CODE:
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
 HWND hwnd;
 MSG msg;
 WNDCLASS wndclass;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
 wndclass.lpfnWndProc=WndProc;
 wndclass.cbClsExtra=0;
 wndclass.cbWndExtra=0;
 wndclass.hInstance=hInstance;
 wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
 wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
 wndclass.lpszMenuName=NULL;
 wndclass.lpszClassName="Window Class";
 if(!RegisterClass(&wndclass))

 {
     MessageBox(NULL,"Can not Registered","Window",MB_ICONERROR);
     return 0;
 }
 hwnd=CreateWindow("Window Class","JEBASTIN - LINE DEMO",WS_OVERLAPPEDWINDOW,
                                                                                     10,10,800,600,NULL,NULL,hInstance,NULL);
 ShowWindow(hwnd,iCmdShow);
 UpdateWindow(hwnd);
 while(GetMessage(&msg,NULL,0,0))
 {
     TranslateMessage(&msg);
     DispatchMessage(&msg);
 }
 return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp)
{
    static int CxClient,CyClient;
    HDC hdc;
    PAINTSTRUCT ps;
    switch(message)
    {
    case WM_SIZE:
        CxClient=LOWORD(lp);
        CyClient=HIWORD(lp);
        return 0;
    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        Rectangle(hdc,CxClient/8,CyClient/8,7*CxClient/8,7*CyClient/8);
        MoveToEx(hdc,0,0,NULL);
        LineTo(hdc,CxClient,CyClient);
        MoveToEx(hdc,0,CyClient,NULL);
        LineTo(hdc,CxClient,0);
        Ellipse(hdc,CxClient/8,CyClient/8,7*CxClient/8,7*CyClient/8);
        RoundRect(hdc,CxClient/4,CyClient/4,3*CxClient/4,3*CyClient/4,CxClient/4,CyClient/4);
        EndPaint(hwnd,&ps);
        return 0;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hwnd,message,wp,lp);
}

OUTPUT:

Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: