Question
please help me with this computer graphics question
Tasks:Graphics program with GDI should be implemented with VC++2010. The graphics shoul have lines, filled polygons, text.(3+
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Steps to create a Graphics project

1.Create a new Win32 project by following the below steps in VS2013

New->Project->Visual C++ -> Win32 Project-> Name the Project ->Finish

2.include following headers in .cpp file

#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus; 

3.Write the required code in OnPaint function of . cpp file

Code :

#include <stdafx.h>
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")

VOID OnPaint(HDC hdc)
{
   Graphics graphics(hdc);
   //Graphics draw Text
   SolidBrush brushText(Color(255, 0, 0));
   FontFamily fontFamily(L"Arial");
   Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);
   PointF pointF(100.0f, 0.0f);
   graphics.DrawString(L"Welcome to Graphics World!", -1, &font, pointF, &brushText);

   //to draw lines
   Pen linePen(Color(34, 139, 34));
   // Create an array of Point objects that define the lines to draw.
   Point point1(200, 300);
   Point point2(400, 200);
   Point point3(500, 50);
   Point point4(200, 300);
   Point points[4] = { point1, point2, point3, point4 };
   Point* linePoints = points;
   graphics.DrawLines(&linePen, linePoints, 4);

   //Draw Filled Polygon
   SolidBrush blackBrush(Color(128, 0, 128));
   // Create an array of PointF objects that define the polygon.
   PointF pointPolygon1(100.0f, 100.0f);
   PointF pointPolygon2(200.0f, 130.0f);
   PointF pointPolygon3(150.0f, 200.0f);
   PointF pointPolygon4(50.0f, 200.0f);
   PointF pointPolygon5(0.0f, 130.0f);
   PointF pointsPolygon[5] = { pointPolygon1, pointPolygon2, pointPolygon3, pointPolygon4, pointPolygon5 };

   // Fill the polygon.
   graphics.FillPolygon(&blackBrush, pointsPolygon, 5);

  
}


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

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
{
   HWND hWnd;
   MSG msg;
   WNDCLASS wndClass;
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;

   // Initialize GDI+.
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   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 = TEXT("GraphicsExample");

   RegisterClass(&wndClass);

   hWnd = CreateWindow(
       TEXT("GraphicsExample"), // window class name
       TEXT("GraphicsExample"), // window caption
       WS_OVERLAPPEDWINDOW, // window style
       CW_USEDEFAULT, // initial x position
       CW_USEDEFAULT, // initial y position
       CW_USEDEFAULT, // initial x size
       CW_USEDEFAULT, // initial y size
       NULL, // parent window handle
       NULL, // window menu handle
       hInstance, // program instance handle
       NULL); // creation parameters

   ShowWindow(hWnd, iCmdShow);
   UpdateWindow(hWnd);

   while (GetMessage(&msg, NULL, 0, 0))
   {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
   }

   GdiplusShutdown(gdiplusToken);
   return msg.wParam;
} // WinMain

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

   switch (message)
   {
   case WM_PAINT:
       hdc = BeginPaint(hWnd, &ps);
       OnPaint(hdc);
       EndPaint(hWnd, &ps);
       return 0;
   case WM_DESTROY:
       PostQuitMessage(0);
       return 0;
   default:
       return DefWindowProc(hWnd, message, wParam, lParam);
   }
} // WndProc

Output:GraphicsExample Welcome to Graphics World!

Add a comment
Know the answer?
Add Answer to:
please help me with this computer graphics question Tasks:Graphics program with GDI should be implemented with VC++2010. The graphics shoul have lines, filled polygons, text.(3+3+4marks) Task...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me answer this question. Thank you so much 04-BS-15 Engineering Graphics & Design Process...

    Please help me answer this question. Thank you so much 04-BS-15 Engineering Graphics & Design Process May 2014 2. Sketch an isometric pictorial of the following orthographic projection not draw. Do not use a straight edge. Sketch. Do Criterion Grade Isometric pictorial 4: Correct angles of horizontal lines 3: Near correct angles of horizontal lines 0: Not an isometric pictorial 4: Flawless 3: Minor errors 2: One or more significant omissions 1/0: Part could not be manufactured projection Penalties -10:...

  • I got help with task 1 and 2 . can you help me with task 3 and 4 of this question. please help me...

    I got help with task 1 and 2 . can you help me with task 3 and 4 of this question. please help me step for step thanks. A signal x[n] modulated by multiplying it by a carrier wave cos(2*p1"/cm) to form the signal z[n] = cos(2"p1"Vcm)x[n] ·The modulated signal z[n] multiplies with the same carrier wave to give the signal y[n]=cos(2*pi"Vcm)z[n] and filters with an LT-system to give x-hat [n] . all this are described by the picture below...

  • Please help me write this Java program. I had posted this question before, but got an...

    Please help me write this Java program. I had posted this question before, but got an answer that was totally wrong. We are using the latest version of Java8. Thank You! -------------------------------------------------------------------------------------- Write a Java program that can successfully DECRYPT a string inputted by the user which has been encrypted using a Caesar Cipher with a unknown shift value(key). You can use brute force to do a for loop through all the 26 shift values, however, your program should only...

  • please kindly help me solve this Human computer Interaction question. Thank you so much Good day,...

    please kindly help me solve this Human computer Interaction question. Thank you so much Good day, kindly Help me to solve this Human Computer Interaction Questions. Thank you Question 3 (20 marks): Evaluate and Redesigning Application Interfaces you think are Bad Designs Choose any IT garget, an application or a website of your interest. Study and evaluate the interface of this chosen application or website applying the concepts you have learnt in the HCI class. Redesign the interface, detailing things...

  • 11 : 3 : Please help me answer this question: Item 3 Part A Where should...

    11 : 3 : Please help me answer this question: Item 3 Part A Where should w object be placed in front of a concave mirror so that it produces en image at the swne location as the object? Use r for radius of curvature Express your answer in terms of r. d0 = Part B Is the image reel or virtual? real virtual Part C Is the image inverted or upright? inverted upright Part D Whet is the magnification...

  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint:...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint: the number array in task 2 is work for task 3 in figure 1.   Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i...

  • Please help with all the questions. These question are for autocad users. CIVILEN 2405-COMPUTER GRAPHICS for...

    Please help with all the questions. These question are for autocad users. CIVILEN 2405-COMPUTER GRAPHICS for CIVIL ENGINEERS QUIZ 2 Each question is worth 5 points for a total of 50 points 1. AutoCAD's object snap feature allows you to: Name 6. Which of the following commands would you most A. B. C. D. snap to end points of lines snap to the midpoints of lines snap to the centers of circles all of the above likely use to remove...

  • Please help me out.. A and C Question. 5. (30 points) Consider a computer with byte...

    Please help me out.. A and C Question. 5. (30 points) Consider a computer with byte addressable main memory bytes, and the block size is 8 bytes. Assume that a direct mapping cache consisting 32 lines is used with this machine. (a) (5 points) How many bits are required to hold a memory address? (b) (5 points) How many total bytes of memory can be stored in the cache? 256 bytes (C) (10 points) How is that memory address divided...

  • can you help me with these 3 please D Question 4 Models should be made to scale by size. True False Question 5 "If u...

    can you help me with these 3 please D Question 4 Models should be made to scale by size. True False Question 5 "If using a video, ensure that it is short in duration." True False Question 6 Charts are used to illustrate number sets and lists. True False

  • Hello! Please help me with this question!! I'm desperate and have the AP test this week....

    Hello! Please help me with this question!! I'm desperate and have the AP test this week. A letter answer and short explanation would be so so helpful! next five questions, numbered 121-125, require numeric answers Determine the Use the following guidelines for entering your answers he correct answer for each question and enter it in the grid on page 3 of the answer sheet Start your answer in any column, space permitting. Unused columas Start your answer in any columa....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT