none
graphics in c++

    Question

  • Hello everyone

    anyone can give example of graphics programme in vc++ in visual studio 2010 or 

    source code and path of using graphics library of   WINBGIM or WINBGI or recent graphics library  in visual studio 2010 ??

    Monday, July 19, 2010 2:16 PM

Answers

  • Hi f_prog,


    The document below shows how to use WINBGI library in Visual Studio 2005 and 2008, but Visual Studio 2010 is not supported from now on:
    http://www.cs.colorado.edu/~main/bgi/visual/
    You need to download the source file and build the .obj file by yourself(the header file should be OK except the line 302 needs to be modified as following:
    int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX

    You could also use DevC++ to develop with the WINBGIM library. Please search 'How do I use Borland Graphics Interface (graphics.h)?' in the document below: http://www.uniqueness-template.com/devcpp/
    It is constructed successful based on my testing except the 320 line of graphics.h needs to be modified too.

    On the other hand, if you want to develop a basic graphics program in windows, it is suggested using GDI or GDI+, they are old and mature, as well as profressional. You could create a simple Win32 empty project and add the code snippet below to a Cpp file. It will draw a triangle and an ellipse in desktop.

    /* *********************************************
    * A simple gdi program
    * ***********************************************/
    
    #include <Windows.h>
    
    void GdiOut(HDC hdc);
    
    int WINAPI WinMain(
      HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpCmdLine,
      int nCmdShow
      )
    {
     HDC hdc = GetDC(NULL);
     GdiOut(hdc);
     ReleaseDC(NULL, hdc);
    
     return 0;
    }
    
    /* Show how to use the basic GDI functions */
    void GdiOut(HDC hdc)
    {
     HPEN hPen, hPenOld;
     HBRUSH hBrush, hBrushOld;
    
     //Initial colors
     BYTE bRed = 0;
     BYTE bGreen = 0;
     BYTE bBlue = 0;
    
     //Pen color
     COLORREF cPen = RGB(bRed, bGreen, bBlue);
     //Set the brush color based on the pen color. It is purple partial to blue.
     COLORREF cBrush = RGB(233,GetGValue(cPen), 255);
     //Create the pen.
     hPen = CreatePen(PS_SOLID, 10, cPen);
     //Create the brush.
     hBrush = CreateSolidBrush(cBrush);
     //Select the pen and brush. Just like set the drawing arguments.
     hPenOld = (HPEN)SelectObject(hdc, hPen);
     hBrushOld = (HBRUSH)SelectObject(hdc, hBrush);
    
     //Draw a triangle
     MoveToEx(hdc, 30, 10, NULL);
     LineTo(hdc, 10, 50);
     LineTo(hdc, 50, 50);
     LineTo(hdc, 30, 10);
     //Use the old pen
     SelectObject(hdc,hPenOld);
     //Draw and fill an ellipse
     Ellipse(hdc, 10, 60, 110, 160);
    
     //Release the resources
     DeleteObject(hPen);
     SelectObject(hdc, hBrushOld);
     DeleteObject(hBrush);
    
    }
    
    
    

    You could get more about GDI from:
    http://msdn.microsoft.com/en-us/library/ms533798(VS.85).aspx

    By the way, a new graphics architecture is released since Windows 7, which is called Direct2D. You could take a look at the document below to know more about it:
    http://msdn.microsoft.com/en-us/magazine/dd861344.aspx

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Friday, July 23, 2010 7:01 AM
    Moderator