Monday, November 21, 2011

Draw a 3D Chess Board using OpenGL utility toolkits (GLUT), a graphics project with source code

This program  may help you in graphics project of your college.I simply  tries to draw the 3D Chess Board.  For this our main goal is to draw white and black rectangular box alternately along both x and y-axis.Drawing rectangular box is simple ,it is drawn by providing all side co-ordinates with the help of glVertex3f function and only top face is assign with black or white color and other face with brown color with the help of glColor3f function. I have made two function void draw_BlackArea() and void draw_whiteArea() to draw black and white square box respectively .Inside two for loop I have call these function by creating displaylist and with the help of glTranslatef(GLfloat x,GLfloat y,GLfloat z) function I draw  alternatively by translating their position.

Tuesday, November 15, 2011

Draw Reflection of Object on the floor using OpenGL Utility Toolkit (GLUT)

Drawing reflection capture the extra realism of the Object in 3D programming.For example Bouncing ball having its reflection on the floor can make the bouncing scenario more beautiful and realistic. So,OpenGL has all the features needed to render fast high-quality reflections on planar surfaces.
        Reflection technique is not so hard its pretty simple.If you want to draw reflection on floor then suppose your floor is in x-z plane and your object along positive y-axis above the plane then for reflection of object draw the copy of object along the negative y-axis vertically below the plane or floor.Your floor must look like the reflecting surface to see the object which is below the floor for this we use alpha blending which make the floor transparent by certain percent say 40% then it is specified to be 40% the color of the floor and 60% the color of the reflection or object.But only alpha blending doesn’t make the reflection real because the reflected copy of the object may leak outside or bottom of the floor so to fixed this problem we actually going to use the stencil buffer concept.With OpenGL stenciling, we can "pre-draw" the floor into the stencil buffer without updating the color or depth buffers. Then when we go to draw the reflection,  just only allow the reflection to update pixels marked as belonging to the floor's stencil value. The floor can then be any complex (but coplanar) polygon and the reflection only shows up in the floor.

Drawing a Bitmapped Character or string in OpenGL sample example

A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window. Suppose you're drawing a bitmap and that the current raster color is red. Wherever there's a 1 in the bitmap, the corresponding pixel is replaced by a red pixel and If there's a 0 in the bitmap, the contents of thepixel are unaffected. The most common use of bitmaps is for drawing characters on the screen.
            In the simple example we use two main function glBitmap and glRasterPos2i function.
The glBitmap function draws a bitmap.

Saturday, November 12, 2011

Rotate an Object in OpenGL(GLUT) sample example with source

In GLUT we rotate the object by glRotate3f(angle_rotation,GLfloat x, GLfloat y ,GLfloat z) function angle_rotation parameter is value of angle to rotate and x,y,z co-ordinate are axis of rotation.But it does not rotate object continuously for that we have to change angle of rotation by small amount of increment. We do this by using timer thread with the help of glutTimerFunc function.Here is the sample source code copy and compile it.

Friday, November 11, 2011

How to change the color of object in OpenGL(GLUT) using keyboard function

If you have problem in changing color of object in OpenGL using keyboard while running program then this article may help you.Simply we can’t change the color of object while running for this we have to create a timer thread by using
Void  glutTimerFunc(unsigned int msecs,void (*func(int value),value)  function or other techinque can also be use.
Parameter:
msecs

Number of milliseconds to pass before calling the callback.

func

The timer callback function.

value

Integer value to pass to the timer callback.

Saturday, November 5, 2011

TCP Client and Server sample example with source code for Beginners in C#.

Welcome to this page who want to start writing  their own program communication through socket API using C# .Net framework.
The .NET framework provides two classes specifically for TCP: TcpClient and TcpListener.These classes provide a higher level abstraction of the Socket class, but as we will see there are instances when advanced functionality is available only through direct use of the Socket class.

In this article I have shared the simple client server program before but many visitor comment me about bad indentation of code.That's why I removed previous code completely and  started to write the series of article related TCP/IP Socket in C#.
The list of chapter:
1. Basic TCP Socket program
2. Basic UDP Socket program
3. Basic .Net Socket progarm

Note: Chapters in advanced topic will be updated soon.

How to display IPAddress of hosts using c#

This sample program demonstrates the use of the Dns, IPAddress, and IPHostEntry classes. The program takes a list of names or IP addresses as command-line parameters and prints the name and an IP address of the local host, followed by the names and IP addresses of the hosts specified on the command line.
The Dns class has several methods for resolving IP addresses. The GetHostName() method takes no arguments and returns a string containing the local host name. The GetHostByName() and Resolve() methods are basically identical; they take a string argument containing the host name to be looked up and returns the IP address and host name information for the supplied input in the form of an IPHostEntry class instance. The GetHostByAddress() method takes a string argument containing the dotted-quad string representation of an IP address and also returns host information in an IPHostEntry instance.

Friday, October 14, 2011

Simple Multithreading Application sample source code in pure C

In our general program we can’t run two process at same time for e.g we can’t run two for loop at same time.For running two process at same time we need Multithreading.In C we do it by the _beginthread and
_endthread run time  library function.All the above c run time library functions are in the process.h header file.

Header
process.h

Prototype

unsigned long _beginthread(void(* func)(void*), unsigned stack_size, void *arg);

Description

Thursday, October 13, 2011

Generate random number in C++

Random number is generated by using srand(time(NULL)) and rand() function.For time we have to include time.h and for srand() and rand function we have to include stdlib.h.Here is the simple program which generate 10 random number.
#include<iostream>
#include<time.h>
#include<stdlib.h>
#define MAX_NUM 10
using namespace std;

Tuesday, October 11, 2011

Conversion of infix operation to postfix and simple calculator

This code is to convert infix operation to postfix operation .This is the application of stack.Example infix  8*5+(5-3+1) converted to 85*53-1++ and result is 43.This program can be use as a simple calculator where user can calculate any result only in single step.
Copy the code and compile it in codeblock.

Monday, October 10, 2011

Winsock Programming sample project cyber management system.

 Cyber Management System is a program which interconnects different computers which allows users to communicate over the computer network and provide security from unauthorized users by login system in client server.
The project is based on the client server architecture and its communication protocols. The project basically is divided into two sections:- Cyber server and Client server. Not only a single, multiple client can connect to cyber server at any time. Cyber server has the full control over Client server. Client server is password protected user has to login to access internet and other services. New user can signup for username and password. Price rate and services is fixed by cyber server. Client can request any service sending message to cyber server.

Major component


socket API

syntax:
int socket( int domain , inttype , intprotoco ) ;

Scanning pdf file in hard drive or folder source code in c++

This program use the batch processing.For batch processing we use Frofiles.exe command.
Syntax
FORFILES [/p Path] [/m Mask] [/s] [/c Command] [/d [+ | -] {dd/MM/yyyy | dd}]   

Parameter List:
    /P    pathname      Indicates the path to start searching.
                        The default folder is the current working directory (.).


    /M    searchmask    Searches files according to a searchmask. The default searchmask is '*' .

    /S                  Instructs forfiles to recurse into subdirectories. Like "DIR /S".

    /C    command       Indicates the command to execute for each file.
                        Command strings should be wrapped in double quotes.

                        The default command is "cmd /c echo @file".


Sunday, October 9, 2011

Playing sound source code in C++

This source code is not for playing songs or sound clips from your hard drive only to play  sound by using windows function Beep(int dwFreq [in],int dwDuration [in]) .
Parameters are
dwFreq [in] 
                    The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767                      (0x25 through 0x7FFF)
 dwDuration [in]
                       The duration of the sound, in milliseconds.
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.
This source code play the music “twinkle twinkle little star” using windows command Beep.Here is the source code copy it and compile and run in code::blocks IDE.

Monday, September 19, 2011

Analog Clock source code using c++ and winBGI graphics

This code does not run directly in code::blocks because winBGIm graphics is for turbo compiler where you can run this code directly and we don’t have to setup library but in code::block you have to setup.To setup WinBGIm graphics library you can see my previous post here .If you setup then now you are ready to compile this code.
Copy the code below and compile it in code::block.While compiling if you got error message in line 320 of graphics.h :” redefination of int right” then change int right=0 to int top = 0.Although,you got other error then leave the message.

How to setup winBGIm library in codeblock

BGI (Borland Graphics Interface) is ancient as is turbo c++ IDE but nevertheless they are still used in our schools and colleges. Plus they do not work in windows environment (support for native DOS has been completely removed in windows vista/7).If you try to compile the source code with including “graphics.h” in code::blocks IDE then is show error because “graphics.h” only run in turbo.For code::blocks you have to setup winBGIm library.
There are many alternative to winBGIm ,But BGI is good for beginners because you don’t have to worry about whole new fancy functions,classes etc.
WinBGIm is BGI graphics library ported to computer by by Michael Main at the University of Colorado.
Before i start, i must tell you that this guide is written in accordance with code::blocks IDE.

Lets get started:
  1. First download WinBGIm from http://winbgim.codecutter.org/
  2. Extract it.
  3. Copy graphics.h and winbgim.h files in include folder of your compiler directory
  4. Copy libbgi.a to lib folder of your compiler directory
  5. In code::blocks open Settings >> Compiler and debugger >>linker settings
  6. click Add button  in link libraries part and browse and select libbgi.a file
  7. In right part (ie. other linker options) paste commands
  8. -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  9. click Ok
Finally, you can now compile source code using “graphics.h”.You can try this by creating "anlog clock" and you can copy source code from my post  here . The WinBGIm library gives you an alternative as I hope, you found this guide helpful and incase you need my help just leave a message.

Thursday, September 15, 2011

“Contacts Manager” mini project in C with source code

Contacts Manager is a simple mini project code in C.This is similar to contact manager in Mobile phones.You can add contacts,remove contacts,edit contacts,search contacts and view all contacts.Graphics is not used just a console application suitable for learning purpose for beginner and can be used as a reference for college mini project.In this project you learning file handling ,how to write data,delete data and search data form file.I hope my post may help you and you can send email for further help.
Copy the source code below or Download from GitHub and compile it in Code::Blocks.

Create a Matching Game using visual studio

In this tutorial, you build a matching game, where the player must match pairs of hidden icons. You learn how to:
  • Hold objects using a List object.
  • Use a foreach loop in Visual C# or a For Each loop in Visual Basic.
  • Keep track of a form's state using reference variables.
  • Build an event handler that you can use with multiple objects.
  • Make a timer fire exactly once when started.
Copy this code and create project on visual studio or Download complete project from GitHub.

Tuesday, July 12, 2011

Sample Project Math Quiz Game in windows form application

Hi! friends this is another sample project in windows form application.I have created simple Math Quiz Game 
in which players must give answer within 30 seconds.This game may not be suitable to play for entertainment but this is very helpful for reading and creating project in windows form.
     In this tutorial, I build a timed math quiz game, where the player must answer four random arithmetic problems within a specified time. You learn how to:
  • Generate random numbers using the Random class.
  • Trigger events using a Timer control.
  • Control program flow using if else statements.
  • Perform basic arithmetic operations.
In game when player fill all four answer within specific time the message box display's congratulation message if not then display's sorry message.


Here is a source code written in c sharp  copy each block of code and save them in separate file and create new project on windows form application and compile it or Download complete project from GitHub.

Tuesday, July 5, 2011

Sample project Maze game in windows form application source code

Hi! friends this is another sample project in windows form application.I have created simple Maze Game by using only labels and panel.Maze is  design by dragging and dropping in visual studio 2010.I have added start sound and game end sound also.
    In this project, user has to move the mouse pointer from the start to the finish without touching any of the walls. At the end of these project you learn how to:

  • Lay out a form using a Panel container.
  • Build a maze using Label controls.
  • Write code to show a message box.
  • Set up event handlers for mouse events.
  • Play sounds in your program.
  • Organize your code using classes.
Here's how the maze will work: The mouse pointer starts at the upper-left corner of the maze. The user navigates through the maze, being careful not to touch any of the walls with the pointer. If the pointer touches one of the walls, it automatically jumps back to the start. But if the pointer reaches the Finish label at the end of the maze, a "Congratulations" message box opens, and the game ends.


Here is a source code written in c sharp copy each block of code and save them in separate file and create new project on windows form application and compile it or Download complete project from GitHub.

Image viewer in windows form application with visual studio sample project source code


Hi! friends this is another sample project in windows form application.I have created simple image viewer project by using imageBox,checkBox,openFileDialog ,colorDialog and buttons.All these items are design by dragging and droping with visual studio 2010.Here is a source code written in c sharp copy each block of code and save them in separate file and create new project windows form application and compile it.
    In this project you can add additional feature like auto resize of image,adding next button to display next image.
Download complete from GitHub.

|--------------------------------------------------------------------------|
|                                  Program.cs                                                            |
|                                                                                                               |
|--------------------------------------------------------------------------|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

Thursday, June 30, 2011

Sample Calculator with windows form application in c# sharp using visual studio source code

Hi! friends do you want to learn windows form application in visual studio then this sample calculator project may provide hits and idea about event handling in windows form application.Code is written in c#.Here is there file for this copy one by one or Download complete project from GitHub.
You can also see other sample projects here the lists of other projects.
List of windows form sample projects.


BItmap maping and texture map in OpenGL

This the sample code for texture map in teapot and bit map is used to draw chess board.Code is compiled in codeblocks you can copy and paste this code for your study or project.Please use your own image for texture map.Image must be in bmp formate.


#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
GLuint texture[2];
GLint slices=16;
GLint stacks=16;
struct Image {
    unsigned long sizeX;
    unsigned long sizeY;
    char *data;
};
typedef struct Image Image;

Saturday, June 25, 2011

wxWidget sample project Puzzel source code

This is interesting game developed using wxWidget graphic library and c++ programming language compiled in gcc compiler with code::blocks IDE. You can download the complete project.At first to run this project you have to setup the wxWidget graphics library in code::blocks. All the instruction for wxWidget setup is given in this article setup wxWidget .You can make this game as your college mini projects.wxWidget is very old and popular GUI graphics library and knowledge of its is very important for student. Other GUI like windows form where you can drag and drops the control directly which make designing easy but we can't understand the actual programming so by using wiWidget we can understand complete GUI design and add the method for event handling.GUI of  Code::Blocks IDE which we use is also design in wxWidget. In this program wxWidget library is used to make a game rather than for GUI.
you can  download sourcecode here all the image file required for the project is also provide.This game is built in code::blocks IDE using C++ with wxWidget library.

Thursday, June 23, 2011

Mini project tic-tac-toe game source code in C

Hi this is a tic-tac-toe game you can copy sourcecode here or Download from GitHub.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <windows.h>

Tuesday, June 21, 2011

mini project "Quiz" in C


In this mini project I didn't use file handling for storing  and reading question .I have used file only for storing score won by players so it is not good Idea. Anyway this project may guide you to create Quiz game by using file handling for storing and reading question . Download Project from Github


#include<stdio.h>
#include<conio.h>
#include <windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void displayscore()
{
char name[20];
float s;
FILE *f;
system("cls");
f=fopen("score.txt","r");
fscanf(f,"%s%f",&name,&s);
printf("\n\n\t\t ");
printf("\n\n\t\t %s has secured the Highest Score %.2f",name,s);
printf("\n\n\t\t ");
fclose(f);
getch();
}

mini project Department store source code


This mini project is about department store all features required for department store are added in this programe.You can copy the source code and compile it in a code block.This project is perfect for your college mini project in C. Download Project from Github


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>

#define ANS 15
#define ACS 4
 COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y)
{
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
/*declaration of checking functions*/
void c_code(char[]);
int check(char[]);

/*structure declaration*/
typedef struct{
char name[ANS],code[ACS];
float rate;
int quantity;
}rec;
rec item;

/*declaration of display functions*/
void curser(int);
void dbill();
void d_mainmenu();
void display(rec *,int,int);
void window(int,int,int,int);
void dis_con();
void d_search();
void highlight(int,int);

/*declaration of main menu functions*/
void bill() ;
void edit();
void add();
void del();
void exit();

/*declaration of display submenu functions*/
void d_code();
void d_rate();
void d_quan();
void d_all();

/*start of main*/
int main()
{
d_mainmenu();
return 0;
}

Sunday, June 19, 2011

Mini project snake game in c

Mini project in C many Student do management project like library management ,Hotel management etc.But Snake Game is mini project of first semester build by my friend which is very different.It is console application without graphic library that's why it is more interesting.This game is perfect without any error and better user interface.It is complied in code::block using c language.Here goes a source code you can copy and compiled it in code::block.I hope it can help and become a reference for your project. Download Project from Github.

Friday, June 17, 2011

Video game teheran in OpenGL

Teheran is importantor 3D game.You can donwload it source code form this link  download .For teheran you have to use gray code image.All source is written in c++ using OpenGL library.

Mini project "3D Bounce " in OpenGL

This project is my second-year mini-project. I have use the GLUT(OpenGL) library in c++.3D Bounce is a game in which we have to bounce the ball to collect the floating star,after collecting all star then a door opens for the next room. Due to lack of time, I can't complete this project but all image drawing part is completed and I hope you will complete it for your collage project.You can download it source code from this link http://www.4shared.com/file/J-cjGaN-/bounce.html .This program is written in complete object oriented environment ,I have made different class in different file and It's code is very lengthy so  I can't give source code here.

Wednesday, June 15, 2011

Drawing a snowman using OpenGL source code


This source code is written in c using the OpenGL library. This program is just a demo to draw a different shape object and I draw a man like an object in this program. I have also added a keyboard event in this program.

#include <math.h>
#include <GL/glut.h>
#include <stdio.h>
#include <string.h>
//#include <cstdlib>
//if you got error in exit() by compiler then does not incluede stdlib.h because //exit() is also defined in glut.h file.

float angle=0.0,deltaAngle = 0.0,ratio;
float x=0.0f,y=1.75f,z=5.0f;
float lx=0.0f,ly=0.0f,lz=-1.0f;
int deltaMove = 0,h,w;
int font=(int)GLUT_BITMAP_8_BY_13;
static GLint snowman_display_list;
int bitmapHeight=13;

int frame,time,timebase=0;
char s[30];

void initWindow();

void changeSize(int w1, int h1)
{

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h1 == 0)
h1 = 1;

w = w1;
h = h1;
ratio = 1.0f * w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set the viewport to be the entire window
    glViewport(0, 0, w, h);

// Set the clipping volume
gluPerspective(45,ratio,0.1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x, y, z,
     x + lx,y + ly,z + lz,
 0.0f,1.0f,0.0f);


}


Sunday, June 12, 2011

Mouse event handling source code in OpenGL



This source code is written in C++ with OpenGL.It is just a demo for mouse event handling you can use this code for your project. In this example void motionPassive(int x, int y) to find out the cursor position in the window. By finding the difference between the previous and initial position the direction of the camera is changed.

Texture map in solid sphere using GLUT(OpenGL)


This source code is written in C used to draw a solid sphere using OpenGL and you can map texture in it. Create a project for OpenGL and copy and paste this code and use your desire image file for texture mapping.

//main.c

#include <GL/gl.h>
#include <GL/glut.h>
#include <windows.h>
#include <stdio.h>
#include <math.h>
GLuint texture;
double angle = 0;
typedef struct
{
    int X;
    int Y;
    int Z;
    double U;
    double V;
}VERTICES;

const double PI = 3.1415926535897;
const int space = 10;
const int VertexCount = (90 / space) * (360 / space) * 4;
VERTICES VERTEX[VertexCount];
GLuint LoadTextureRAW( const char * filename );

Saturday, March 19, 2011

Digital clock source code


This is a source code for time. It will display in 24-hour formate hr/min/sec. You can use this source code for timing in your game in a separate thread.

#include <stdio.h>
#include <time.h>         //this is header file for time
#include <windows.h>
void ClearConsoleToColors(int ForgC, int BackC);
COORD coord = {0, 0};
void gotoxy (int x, int y)
{
    coord.X = x; coord.Y = y; // X and Y coordinates
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void delay(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}

int main()
{

    long i = 0;                      /* Loop counter              */
    clock_t now = 0;                 /* Holds initial clock time  */
    int interval = 1;                /* Seconds interval for o/p  */
    int elapsed = 0;
    int min=0,MIN=0,hrs=0,sec=0;
    int d=0,f=0;
    now = clock();
    ClearConsoleToColors(2,1);               /* Get current clock time    */

Move console windows using C++ and windows function.

You can move your console windows at your desired location on-screen and also resize the size of console windows by using this source code in code::block.

#include <windows.h>
#include<stdio.h>
HWND WINAPI GetConsoleWindowNT(void)
{
    // declare function pointer type

    typedef HWND WINAPI (*GetConsoleWindowT)(void);

    // declare one such function pointer

    GetConsoleWindowT GetConsoleWindow;

    // get a handle on kernel32.dll

    HMODULE hK32Lib = GetModuleHandle(TEXT("KERNEL32.DLL"));

    // assign procedure address to function pointer

    GetConsoleWindow = (GetConsoleWindowT)GetProcAddress(hK32Lib,TEXT("GetConsoleWindow"));

    // check if the function pointer is valid

    // since the function is undocumented

    if ( GetConsoleWindow == NULL ) {
         return NULL;
    }

    // call the undocumented function

    return GetConsoleWindow();
}



int main()
{
    HWND hWnd=GetConsoleWindowNT();
    MoveWindow(hWnd,1230,750,200,100,TRUE);

}

Change console windows background color in code::block



Use this source code to change console windows background color in code::block.
Pass integer value range 0 to 256 in ClearConsoleToColors(  x, y) function.

#include <windows.h>          //header file for windows
#include <stdio.h>

void ClearConsoleToColors(int ForgC, int BackC);
int main()
{
    ClearConsoleToColors(0,1);
    Sleep(1000);
    return 0;
}
void ClearConsoleToColors(int ForgC, int BackC)
{
     WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
                   //Get the handle to the current output buffer...
     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
                         //This is used to reset the carat/cursor to the top left.
     COORD coord = {0, 0};
                      //A return value... indicating how many chars were written
                        //   not used but we need to capture this since it will be
                          //   written anyway (passing NULL causes an access violation).
     DWORD count;

                                   //This is a structure containing all of the console info
                          // it is used here to find the size of the console.
     CONSOLE_SCREEN_BUFFER_INFO csbi;
                     //Here we will set the current color
     SetConsoleTextAttribute(hStdOut, wColor);
     if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
     {
                              //This fills the buffer with a given character (in this case 32=space).
          FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);

          FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
                              //This will set our cursor position for the next print statement.
          SetConsoleCursorPosition(hStdOut, coord);
     }
     return;
}


Text background color of console windows using C in code::block


Use this source code to change the text background color of console windows in code::block

#include <windows.h>
#include <stdio.h>
void SetColorAndBackground(int ForgC, int BackC);
int main()
{
    SetColorAndBackground(5,1);   //color value range 0 up-to 256
    printf("what is text background color");
    Sleep(1000);
    return 0;
}
void SetColorAndBackground(int ForgC, int BackC)
{
     WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
     return;
}

changing text color in codeblock


If you want to change the color of the text in console windows without using graphic then you can use this code in code::blocks.

#include <windows.h>         //header file for windows
#include <stdio.h>                          //C standard library
void SetColor(int ForgC);
int main()
{
    SetColor(34);
    printf("test clour");
    return 0;
}
void SetColor(int ForgC)
{
     WORD wColor;
                          //We will need this handle to get the current background attribute
     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
     CONSOLE_SCREEN_BUFFER_INFO csbi;

                           //We use csbi for the wAttributes word.
     if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
     {
                     //Mask out all but the background attribute, and add in the forgournd color
          wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
          SetConsoleTextAttribute(hStdOut, wColor);
     }
     return;
}


you can change your desire  text color by passing integer value range 0 up-to 256 in SetColor( ) function.

Thursday, March 17, 2011

gotoxy in code::block

gotoxy(int x,int y) is a very important function which helps to move the cursor at our desire location of screen .gotoxy(int x,int y)  is built-in function of turbo c  but in gcc compiler, it won't work. If you are using code::blocks IDE then you may get an error with gotoxy. We have to add code for gotoxy in gcc or codeblocks. This code used windows.h header file in another word we can say its not the c code it is the widows' code. It won't work in the Linux machine because there is no windows.h library.




source code(or download)  for gotoxy is as follows:
 #include<windows.h> //  header file for gotoxy
 #include <stdio.h>     //header file for standard input output

  COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left corner of the screen
 void gotoxy(int x,int y)
 {
   coord.X=x;
 coord.Y=y;
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
 }
  int main()
{

  //calling these function
  gotoxy(20,20);printf("This is demo of gotoxy function");
            
   return 0;
  }

Sunday, March 13, 2011

Mini project "library management" in C programming


      This is my college 1st-semester mini-project “library management “ in C programming language. This is a console application without graphics and compiled in code::block with GCC compiler. I hope it will help you to develop your own project similar project related to file handling for example “Banking “,” customer records”,” student records" etc.
I have divided my project into many functions and I will describe each of them which may help you to understand better.


Sunday, February 27, 2011

Setup GLFW project in code::block

TO create GLFW (OpenGL Framework) Project in code::block, at first you have to download the GLFW framework from this website http://sourceforge.net/projects/glfw/files/glfw/2.7/glfw-2.7.bin.WIN32.zip/download?use_mirror=space for windows. If you are running another machine then download for that machine from glfw.org.

Let's create a GLFW project
step 1:

first, unzip the zip file
step 2:
copy the glfw.h file from the include folder of unzip file of step 1
and paste to the folder "C:\Program Files\CodeBlocks\MinGW\include\GL"
again copy all file (libglfw.a and libglfwdll.a ) from the lib_mingw folder of unzip file of step 1
and paste to the folder "C:\Program Files\CodeBlocks\MinGW\lib"
also, copy the glfw.dll file from the lib_mingw folder of unzip the file and paste it
inside "C:\Windows\System32" folder.
step 3:
Open the code block you will see window as below and click on create new 
project link






Friday, February 25, 2011

Features of code::block


Features

Highlights:

  • Open Source! GPLv3, no hidden costs.
  • Cross-platform. Runs on Linux, Mac, Windows (uses wxWidgets).
  • Written in C++. No interpreted languages or proprietary libs needed.
  • Extensible through plugins

Compiler:

  • Multiple compiler support:
    • GCC (MingW / GNU GCC)
    • MSVC++
    • Digital Mars
    • Borland C++ 5.5
    • Open Watcom
    • ...and more
  • Very fast custom build system (no makefiles needed)
  • Support for parallel builds (utilizing your CPU's extra cores)
  • Multi-target projects
  • Workspaces to combine multiple projects
  • Inter-project dependencies inside a workspace
  • Imports MSVC projects and workspaces (NOTE: assembly code not supported yet)
  • Imports Dev-C++ projects

Tuesday, February 22, 2011

Setup wxWidget in code::block


TO create Wxwidget Project in code::block, at first you have to download the wxPack_v2.2.10.06.exe windows installer from this website   http://www.wxwidgets.org/downloads/.for windows.

Let's create Wxwidget project
step 1:
run .exe file that you have downloaded
Click next


Setup OpenGL(glut) in code::block



Download the glut library from the website http://code.google.com/p/rawvideoplayer/downloads/detail?name=glut-3.7.6-bin.zip&can=2&q= for windows.

Steps to create glut project in Code::block.
Step 1: Extract the downloaded zip file.

Step 2: Browse extracted files. Copy the glut.h file and paste it into the directory "C:\ProgramFiles(x86)\CodeBlocks\MinGW\include\GL". Copy glut.lib file and paste it into the directory "C:\Program Files(x86)\CodeBlocks\MinGW\lib". Also, copy the glut.dll and paste it into
the directory "C:\Windows\System32".

Monday, February 21, 2011

Setup SDL 1.2 version in code::block


Visit SDL download page https://www.libsdl.org/download-1.2.php. Download file SDL-devel-1.2.15-mingw32.tar.gz (Mingw32) from Development Libraries section for your respective machine Win32/Linux. If you are using Visual C++ compiler in Code:blocks then download another file for Visual C++. Required links are highlighted in screen shot below:



Steps to create SDL project in Code::blocks:
Step 1: Extract downloaded  zip file (SDL2-devel-x.x.x-mingw.tar).

Step 2: Create folder in any directory and give a name SDL 1.2 (eg. c:\SDL 1.2).