Total Pageviews

Saturday, May 21, 2011

delay and gotoxy in c and c++

gotoxy and delay


gotoxy and dealy are two most useful function of c and c++........................


gotoxy use to  position cursor in specified position.................
where position is decided by value of x and y

void gotoxy(int x,int y)



Example

#include<stdio.h>
#include<conio.h>

void main()
{
  clrscr();

  gotoxy(72,10);
  printf("Ashok");

  gotoxy(5,10);
  printf("Prasad");

  gotoxy(25,40);
  printf("soni");

  getch();

}

delay

dealy suspend execution  for specified time interval
 void delay(int millisecond)

Example

 #include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
  clrscr();


  printf("Ashok\n\t");
  delay(2200);
  printf("Prasad\n\t\t");
  delay(2200);

  printf("soni");

  getch();

}

Goto and Delay


#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
  clrscr();

  gotoxy(72,10);
  printf("Ashok\n\t");
  gotoxy(22,5);
  delay(2200);
  printf("Prasad\n\t\t");
  gotoxy(2,30);
  delay(2200);
  printf("soni");

  getch();

}

   
Example

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
  clrscr();
  textmode(BW80);
  textattr(RED);
  textbackground(CYAN);
  gotoxy(72,10);
  cprintf("Ashok");
  gotoxy(22,5);
  delay(2200);
  textattr(BLUE);
  textbackground(WHITE);
  cprintf("Prasad");
  gotoxy(12,17);
  delay(2200);
  textattr(YELLOW);
  textbackground(BLUE);
  cprintf("soni");

  getch();
}

How To Set Font Color in C and C++ in Text Mode

Basilcally  C and C++ Supports two Different Modes.....
1) Text Mode
2) Graphics Mode

(   This Tutorial is all about  text Mode)

Its Very easy to set Font ForegroundColor In c,c++.

 #include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   textattr(RED);      //   This method used to set various type kind of  text attribute
   cprintf("ashoka");
   getch();
}

To Blink it  use this

#include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   textattr(RED+BLINK);    
   cprintf("ashoka");
   getch();
}


Note :-  In c++ Use   cout<<"your text"   in place of  cprintf  function........

 


How To set Text BackgroundColor In  c and c++


#include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   textbackground(BLUE);
   cprintf("ashoka");
   getch();
}



To set Foreground and BackgroundColor Use this............
#include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   textattr(CYAN);
   textbackground(BLUE);
   cprintf("ashoka");
   getch();
}

Note:--Its mandatory to use textattr before textbackground otherwise it will not work.................

One Of the limitation with turboo c++ is that it supports only limited colors (For more colors use dev c++).to see all those colors which are supported by turboo c++ right click in any color name for ex(RED) in turboo c++ editior......

 

To Set Font Size in c and c++


#include<stdio.h>
#include<conio.h>

void main()
{
     clrscr();
    textmode(C40);  //This method used to set font mode
    cprintf("ashoka");
    getch();
}

In place of C40 try this BW80 and C80................


Its important to know that Different Font Mode  and Font Colors Must be written in Capital letters ...
Because they are constant......
and in any programming language Constant are always written in Captial Letters(Naming Convention,To see all  about Naming Convention )

Constant----Whose value cannot be changed(Its mandatory that every Constant must hava an int number)..........


 Example 1
#include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   textmode(C40);
   textattr(CYAN+BLINK);
   textbackground(RED);
   cprintf("Ashoka\r\nSoni");
   getch();
}


Example 2

#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   textmode(C40);
   textattr(CYAN+BLINK);
   textbackground(RED);
   gotoxy(16,12);
   cprintf("Ashoka");
   gotoxy(17,13);
   cprintf("Soni");
   getch();
}

Output:
Output




Well I hope you enjoy this tutorial.......
For further detail join me in orkut idiotboyashok@gmail.com














How TO LOCK A DRIVE IN WINDOWS:

STEPS TO LOCK A DRIVE IN WINDOWS:
  1. First go to Windows Run Command (Windows Key +R) and in the input box type “gpedit.msc” (without quotes) and Press Enter.
  2. It will open configuration window where you will find two options”Computer Configuration” and “User Configuration”. Now click on “User Configuration”.
  3. With in User Configuration now click on “Administrative Templates”. Then go to “Windows Components”.
  4. There you will see a lot of Windows Components. Now Click on ” Windows Explorer”.
  5. Now you will find something like this “Prevent Access To Drives From My Computers” , double click on it . It will open its properties. Now to lock a drive or drives click on “Enabled” radio button. Now from the drop down menu select the drive that you want to lock or block.

  6. After that click on apply and restart your system. Now anyone will not been able to access the particular drive.To unlock the drive again follow the similar procedure and just click on “Not configured” and apply the settings and restart your system.
That’s it; hope you have liked this tip, share your views.

SliverLight 5 Beta - Lets Deal With Its Feature

For Futher Information----Join Me on Orkut  idiotboyashok@gmail.com

In MIX 2011, we can see our very own silverlight new version called Silverlight 5 beta is released. Yes, if you are looking for it, its time to download the beta and try them out. The major goal of Silverlight 5 is to move the silverlight development more towards the WPF and hence releasing some of the benefits that you already enjoy being a WPF developer is now available to silverlight. In this post lets talk about the features that were introduced with Silverlight one by one.

To install Silverlight 5

To try the features, you first need to download the Beta. Lets follow the steps to install silverlight in your machine.

  1. You first need to download Visual Studio 2010 (SP 1) if you didn't have done that already. 
  2. After you install Visual studio update you need Silverlight tools for Visual Studio
  3. Optionally you can also try Silverlight help tools to get started.
Now after you are done with this, lets talk about few basic features introduced in Silverlight 5.

Silverlight 5 Features 

You should notice that there are few major benefits that are not present yet with Silverlight 5 beta, to name a few :
  • Our old requirement to support 64 Bit is not present
  • You still cannot launch external applications (using PInvoke) with elevated trust level
  • DataContextChanged is still not present.
  • Vector Printing


Yet there are few things that you can try now. Lets talk about them.

1. Implicit DataTemplates for Control : 

If you are a WPF developer reading this, you might be thinking that it should be already present before, but it isnt. For Silverlight developers there is a new adjustments made to ensure that DataTemplates are loaded based on Type of Data.

Say you own a ListBox with custom DataTemplate as shown below :

<Grid>
    <Grid.Resources>
        <DataTemplate DataType="local:ashok">
            <Border Background="Red">
                <TextBlock Text="Ashok's Template Selected" />
            </Border>
        </DataTemplate>
        <DataTemplate DataType="local:Abhijit">
            <Border Background="Green">
                <TextBlock Text="Abhijit's Template Selected" />
            </Border>
        </DataTemplate>
    </Grid.Resources>

    <ListBox ItemsSource="{Binding ListofPeople}" Grid.Row="0"/>
</Grid>

Here you can see a new property called DataType which has been already present with WPF earlier but recently added with silverlight, will let you specify the type of the object for which the DataTemplate is associated with.

Now if we create the ListofPeople with both objects of Ashok and Abhijit, it will automatically select the type based on the individual DataType.

public class Model
{
    private List<People> listofPeople;
    public List<People> ListofPeople
    {
        get
        {
            this.listofPeople = this.listofPeople ?? this.LoadListofPeople();
            return this.listofPeople;
        }
    }

    private List<People> LoadListofPeople()
    {
        List<People> peop = new List<People>();
        peop.Add(new Ashok());
        peop.Add(new Abhijit());
        peop.Add(new Ashok());
        return peop;
    }
}

If you force the Model into DataContext, it will choose DataTemplate according to the type passed.

2. AncestorType in RelativeSource

WPF has a facility to search the AncestorType for a control from a child control such that it will find the next parent control that matches the Ancestor Type defined. Silverlight implements this feature to enable you to search your ancestor from child control from your visual tree and bind the child property with it.  Lets take a look into it.

<DataTemplate>
    <TextBox Width="{Binding Width RelativeSource={RelativeSource AncestorType=Border, AncestorLevel=5}} />
</DataTemplate>

Say you have a TextBox defined within the DataTemplate and you want to bind the Width of the TextBox to the width of the control somewhere outside it, you can use RelativeSource Markup extension to find it from the Visual tree.

3. Binding in Style Setters

Silverlight introduces Binding in style Setters. Hence you can use Binding, StaticResource or any markup extension inside the style Setters.

Let you have a class that defines your resource based on some custom logic :

public class MySettings 
{
    public Thickness Margin {get;set;}
}

Now from your style setters you can easily point to the class to get the value of the Thickness.

<local:MySettings x:Key="msettings" />
<Style>
    <Setter Property="Margin" Value="{Binding MyMargin, Source={StaticResource msettings}}" />
</Style>

In the code, it will bind the msettings object and pull the data from MyMargin.


4. ComboBox AutoSelection while Typing

Silverlight introduces a new feature for its existing ComboBox to auto - discover items from the list while the user types text. It has a new property called DisplayMemberPath where Text should be placed which needs to be searched. If you have ever worked with ASP.NET, it would be very easy to grab. 

<ComboBox DisplayMemberPath="YourMember" ItemsSource="{Binding MyItems}" />

The DisplayMemberPath will automatically find YourMember as property from the list of objects associated in MyItems.

Note : To work better, MyItems list should be sorted.

5. RichTextBoxOverflow Control : 

One of the interesting control that was introduced with Silverlight today is the RichTextBoxOverflow control. This control will show up the portion of the RichTextbox which is overflown to it. A special property called OverflowContentTarget is added to the RichTextBox control to specify the Overflow control.

<RichTextBox OverflowContentTarget="{Binding MyOverflowControl}" />
<RichTextBoxOverflow x:Name="MyOverflowControl" 
                     OverflowContentTarget="{Binding MyOverflowControl2}"/>
<RichTextBoxOverflow x:Name="MyOverflowControl2" />

From the code, you will see the First RichTextBox overflows automatically to he overflow control and eventually both control behaves one homogeneous control. It allows you to select the portion overflown to other control and hence these control is actually an option to show up the portion that is not viewed in the original RichTextBox. Cool na.

6. Support for 3D Hardware Accelerated Graphics.

Silverlight now supports 3D Hardware acceleration. 3D graphcs acceleration can be enabled for your Silverlight object using EnableGPUAcceleartation  from the Params of Object tag. Once you enable it, you can use GraphicsDevice in your system to draw 3D objects on the DrawingSurface.


Even though there are lot more changes to talk about, but I want to leave them for some other time.

If you are dying to know all of them, get into "Silverlight 5.0 features" to read more.

Conclusion

The primary goal of this release is to lead close parity between existing silverlight with WPF development and hence giving better developer experience by better tooling support and line of business. I am sure you would love to play around with it.

Learn Advance .Net