Wednesday 30 November 2011

Implementing Mouse in Turbo c

Hi friends,
Here I am describing the implementation of mouse in Turbo c compiler.
Turbo c is an old c compiler works based on  Dos operating System.It works
in the text mode.But have little graphical functions.
   Now Turbo C is not using widely,because of it's poor graphical performance and
dos based working.But for students who learn c programming Turbo c is the better choice.
Here is a sample program which implement mouse and handle it well.

int86() is the core function using to implement mouse.It is defined in header file 'dos.h'.

#include<conio.h>
#include<mouse.h>
#include<stdio.h>
union REGS in,out;
  void restrictmouse()
  {
in.x.ax=7;
in.x.cx=0;
in.x.dx=639;
int86(0x33,&in,&out);
in.x.ax=8;
in.x.cx=0;
in.x.dx=479;
int86(0x33,&in,&out);
  }


     void showmouse()
    {
in.x.ax=1;
int86(0x33,&in,&out);
    }

void main()
{
restrictmouse();
do
{
showmouse();
in.x.ax=3;
int86(0x33,&in,&out);
if(out.x.bx==1)
printf("Left button clicked");
if(out.x.bx==2)
printf("Right button clicked");
if(out.x.bx==3)
printf("Middle button clicked");
}while(!kbhit());
}

REGS is an union predefined in Turbo c library.We declare two variables
of REGS type.It defines so many member variables.
x.ax defines which opration to be done by mouse.
For instance if in.x.ax=1 and call int86(0x33,&in,&out) the meanig is
show mouse pointer.
if in.x.ax=0 Detect mouse
in.x.ax=2 Show mouse video
in.x.ax=3 Get x and y cordinates of mouse pointer and button clicked in out.
That is x=out.x.cx
        y=out.x.dx
Button clicked is : out.x.bx

if in.x.ax=4 it mean hide mouse
7&8 for restrict mouse pointer,Restric mouse is means that define the
area in which the mouse pointer will be displayed.
7 is for restrict in x direction and 8 for y direction.
in.x.ax=7;
in.x.cx=x1;
in.x.dx=x2;

in.x.ax=8;
in.x.cx=y1;
in.x.dx=y2;

in.x.ax=7;
in.x.cx=0;
in.x.dx=639;
will restrict the mouse to all 640 pixels in x direction.

in.x.ax=8
in.x.cx=0;
in.x.dx=479;
will restrict the mouse to all 480 pixels in y direction.

Hope that this post will be helpful to you.Continue reading, the coming
post will be more helpful.  Thanks by Sukesh B R

Tuesday 29 November 2011

Change font size of text in HTML page dynamically using php


Here I am discussing about dynamic changes that can be occur in HTML page.
In desk top applications like Visual Basic , we can easily change the font size of a label by clicking
a button if we programed like so.We does not worry about the background processes.
       But in the case of web the html page to be displayed to the user is send by the server.
The user's browser receives thi page and display it.But the server or php running in it can't make any changes to the page which is already
send.So a program which change the font of a text according to button click is not easily possible in php .But javascript can be used to do this.
      Here I am introducing a different trick in which the font size is send as a parameter in URL to the same page.This is just like in my previous post
 "Varying number of text boxes in HTML form by user".

The code is here :

<?php $n=$_GET["num"]; ?>
<label style="color: BLUE; font-size: <?php echo $n ?>pt">You can Increase or Decrease me</label>
<?php
if($n>10)
$nd=$n-10;
$ni=$n+10;




echo "<a href=\"font.php?num=$ni\"><input type=\"button\" value=\"Increase\"> </a>";
echo "<a href=\"font.php?num=$nd\"><input type=\"button\" value=\"Decrease\"> </a>";
?>


A sample screen shot of the resulting page

One thing to be remember is that the name of html page must be "font.php"

You can also read  Pass parameter to another page in PHP
Varying number of text boxes in HTML form  by user in PHP 

Hope that this post is helpful to you.Thanks...

Sunday 27 November 2011

Varying number of text boxes in HTML form by user



Here I am introducing Variable number of text boxes in HTML form.That is a HTML form in which user can add any number of text boxes as options using PHP.Users can also remove added text box if required.


question.php

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      
  </head>
  <body>
     <table  width="100%" height="100%" align="center">
            <tr><td colspan="4">
       
                </td></tr>
           
       
        <form name="q_form" action="question_submit.php" method="post">
       
          
      
<tr height="100">    <td>   Question</td><td colspan="3"><textarea input  rows="4" cols="79" name="question"></textarea></td></tr>
<?php $n=$_GET["num"];

for($i=1;$i<=$n;$i++)
   echo "<tr height=\"50\" ><td>Option $i</td><td><input type=\"text\" name=\"$i\" size=\"58\"></td>";

$na=$n+1;
$nr=$n-1;
echo "<tr><td>";
  echo" <a href=\"question.php?num=$na\">Add</a>";
  if($n>=1)
echo "<a href=\"question.php?num=$nr\">Remove</a>";
  echo "</tr></td>";
?>

    <tr align="center"><td colspan="4" align="center" height="75">    <input type="submit" value="Submit" ></td></tr>
   
           
        </tr>
       
        </form>

     </table>
    </body>
</html>








The resulting HTML page will be look like above.

Here I am using URL to pass the number of text boxes required like this
  echo" <a href=\"question.php?num=$na\">Add</a>";
echo "<a href=\"question.php?num=$nr\">Remove</a>";

the value passed by $na or $nr is in num parameter of URL.It will be like this
http://localhost/survey_queen/question.php?num=5
This 'num' parameter is parsed into $n variable using php like this ,
$n=$_GET["num"];
That is the value we send directly to the URL is treated as form submitted using get method.

Then using a loop display '$n' number of text boxes in the page.
Then execute this code 
$na=$n+1;
$nr=$n-1;

here $na increased by one than $n
but $nr decreased by one than $n.

Then gives to links Add,Remove
echo" <a href=\"question.php?num=$na\">Add</a>";
echo "<a href=\"question.php?num=$nr\">Remove</a>";

That is if user click 'Add' link the 'num' parameter in the URL will be increased by one than the current page.
If  user click 'Remove' link the 'num' parameter in the URL will be decreased by one than the current page.

Thus it will give a flexible page,in which user can add/remove any number of option fields.



One important thing to note that in the first time page is loaded there will be no option text boxes because
the 'num' parameter in URL will be zero.
We can tolerate by call this page URL from another link and put 'num'
as 2.

That is in a new html page type like this
<html>
<a href="answer.php?num=2">Click to next Page </a>
</html>


Where answer.php is the name of html page we created earlier.

You can also see another example like this :-  Change font size of text in HTML page dynamically using php


Hope that this post will be helpful to you.  Thanks... 

Saturday 26 November 2011

Introducing the concept of for loop to beginers

Here i am introducing the logical side of loops.Here I am considering for loop.Coding is in ANSI C standard.

It is mainly for beginers who entering in programing world.

1)printf("#"); displays a # in the screen.

2) for(i=1;i<=4;i++)
{
printf("#");
}
it will display : # # # #

3) If we want to display like this
# # # #
# # # #
# # # #
# # # #

we can use two for loops one is nested in other,

for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
printf("#");
}
printf("\n");
}

'\n' is used to print in the next line or new line.

4) For display like this :-
#
# #
# # #
# # # #

for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("#");
}
printf("\n");
}

5) For display like this :-

# # # #
# # #
# #
#

for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("#");
}
printf("\n");
}

I hope that the post will be helpful to you.Thanks...


Friday 25 November 2011

Swap or Interchange two varibles without using a third variable

I am revealing Swaping two variables without using a third variable.
For readability I am using ANSI C format for coding ,You can use it in any language.

a=5;
b=10;
a=a+b;
b=a-b;
a=a-b;
Now a=10 and b=5.


But in traditional programing logic it will be
a=5
b=10
temp=a;
a=b;
b=temp;
Here using a third variable.It is not a good programming concept.










newprogaminglogics is for introducing new programing logics

The purpose of this blog is introducing  new programing logic for programmers.I will try to solve each and every tricks in programming in a new way,which will be simple.I hope that this will be helpful to not only beginers  but also professionals in programing field.My posts will cover the concepts in C,C++,Visual Basic,C#.Net,java,PHP,Javascript,CSS,WebDesign etc.Please follow my posts.  

Search This Blog