C++ Pixels In Console Window

前端 未结 6 1091
谎友^
谎友^ 2020-12-04 22:27

In C++ using Code::Blocks v10.05, how do I draw a single pixel on the console screen? Is this easy at all, or would it be easier to just draw a rectangle? How do I color it?

6条回答
  •  囚心锁ツ
    2020-12-04 23:14

    windows.h provides a function SetPixel() to print a pixel at specified location of a window. The general form of the function is

    SetPixel(HDC hdc, int x, int y, COLORREF& color);
    

    where, x and y are coordinates of pixel to be display and color is the color of pixel.

    Important: to print the pixel in your machine with Code::blocks IDE, add a link library libgdi32.a (it is usually inside MinGW\lib ) in linker setting.

提交回复
热议问题