VB icon

Console SetPixel

Email
Submitted on: 1/8/2015 1:01:00 PM
By: T J Betsworth (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: C++ (general)
Views: 2719
 
     using SetPixel function with the gdi link for graphical use in a console window.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Console SetPixel
// Description:using SetPixel function with
the gdi link for graphical use
in a console window.
// By: T J Betsworth (from psc cd)
//
// Assumes:Requires win32 console project.
Requires libgdi32.a 
Add libgdi32.a to linker via
project options/parameters/linker.
//**************************************

#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <math.h>
using namespace std;
int main(){ 
int i,x,y;
SetConsoleTitle("Console SetPixel");
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {95, 40}; 
SMALL_RECT rec = {0,0,0,0};
SetConsoleScreenBufferSize(hout, coord);
rec.Right = coord.X -1; 
rec.Bottom = coord.Y -1;
SetConsoleWindowInfo(hout,TRUE,&rec);
CONSOLE_CURSOR_INFO cci;
cci.dwSize = 25;
cci.bVisible = FALSE;
SetConsoleCursorInfo(hout, &cci);
COORD coord1; coord1.X = 0; coord1.Y= 0; DWORD wr; 
FillConsoleOutputAttribute( hout,255,95*40,coord1,&wr);
 
HWND hWnd = FindWindow(NULL, "Console SetPixel");
HDC hdc = GetDC(hWnd); 
for(i = 0;i <9000;i++){
x=rand () %480; y=rand ()%480;
SetPixel(hdc, x, y, RGB(rand() % 255, rand() % 255, rand() % 255));
}
for(i = 0;i <1257;i++){
x=(int)(200* cos(6.28*i/1257)+240);
y=(int)(200* sin(6.28*i/1257)+240);
SetPixel(hdc, x, y, RGB( 255,0,0));
 }
for(x = 0; x < 760; x+=3){
y = 240;
SetPixel(hdc, x, y, RGB(255,0,0));
}
for(y = 0; y < 480; y+=3){
x = 240;
SetPixel(hdc, x, y, RGB(255,0,0));
}
for(x = 44; x < 437; x++){
y = (int)(76.4*sin(x/76.4) * cos(x/76.4) + 240);
SetPixel(hdc, x, y, RGB(0,0,255));
}
for(y = 44; y < 437; y++){
x = (int)(75.8*sin(y/75.8) * cos(y/75.8) + 240);
SetPixel(hdc, x, y, RGB(0,0,255)); 
}
 HFONT font;
 font = CreateFont(30, 0, 90, 0, 0, TRUE,0,0,0,0,0,0,0,"Dotum");
 SelectObject(hdc, font);
 SetBkColor(hdc,RGB(255,255,255));
 SetTextColor(hdc, RGB(0, 0, 255));
 TextOut(hdc, 555,100, "Console", 7);
 TextOut(hdc, 557,140, "SetPixel", 8);
 DeleteObject(font);
 ReleaseDC(hWnd, hdc);
 DeleteDC(hdc);
COORD coord2 = {62, 29};
SetConsoleCursorPosition(hout, coord2);
SetConsoleTextAttribute(hout,249); 
system("PAUSE");	
return 0;
}


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.