Jun 03
Html elements are displayed cascading by default. So every element appears one after the other and it is the same with nested elements. I mean elements within another element.
I want to find the exact absolute position of an element. In other words i want to find the exact x,y of an element in the html page if you could consider the html page as a graph.
I used left and top but it will always give the x and y with respect to the parent and not to the window or the body tag which is the first parent for all visible elements. Then i read about the property offsetLeft and offsetTop but this too is with respect to the parent.
So find the parents left + its parent left + its parent till you reach the top then you will get the left of any element. The same way for finding the top that is y. here is the function which will give you the x,y/absolute position of any element.
But when i used float left property i found this function returned a different value so please check when using float left option. anyway …
function findAbsolutePosition(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return [curleft,curtop];
//returns an array
}
…
and to my surprise i found the following link when i tried to find something like this to check my work.
http://www.quirksmode.org/js/findpos.html
I use this site to cross check my snippets in javascript if present. This is one useful site i have found which analyses beyond the scope.
Jun 02
One of my projects was uploaded to a windows hosting and i found server of document root was not working. So i searched and i found the following gimmick of using it in windows hosting.
<?php
if ( ! isset($_SERVER['DOCUMENT_ROOT'] ) )
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(
$_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']) ) );
?>
May 27
In C graphics mode when you initialize the mouse you will can see a mouse pointer which is the default one like in windows. I thought of changing it and searched the books. i found a description in yeshavant kanetkar’s book c graphics. The explanation was very nice. I created a program name mice which with i generate various mouse pointers and i save it as a header file which has codes like the following.
Mice will allow you to save mouse pointers as .h file with any valid ms-dos file name.(you can find the mice program and its partial code in future from my home page links title probably “C Snippets”.
The following code used very long variable names just for the matter of understanding… so dont worry the actual code for this seems very tiny…
The shape structure has two type of data of the mouse bitmap. one for the the foreground and other for the transparency… that is cursor mask and screen mask…
When you’re designing the cursor mask, each bit is 1 if it is displayed,
and 0 if it is not. On the screen mask, bits that are 1 are transparent.
you can assume the concept of GIF file here…
int shape [32] =
{
0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,
0xff3f,0xff3f,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,
0xf00f,0x8001,0x8001,0x8001,
0x0,0x0,0x0,0x180,
0x180,0x0,0x0,0x0,
0x8001,0x8001,0x8001,0xf00f
};
//Call the function from main as change_mouse_pointer(shape);
void change_mouse_pointer(int *shape)
{
union REGS inputregister,outputregister;
struct SREGS segmentregister;
inputregister.x.ax=0;
int86(0x33,&inputregister,&outputregister);
inputregister.x.ax=1;
int86(0x33,&inputregister,&outputregister);
inputregister.x.ax=9;
inputregister.x.bx=0;
inputregister.x.cx=0;
inputregister.x.dx= (unsigned) shape;
segread(&segmentregister);
segmentregister.es=segmentregister.ds;
int86x(0x33,&inputregister,&outputregister,&segmentregister);
}
and when i searched the net at the time of posting this code i found one good article titled “Programming the Microsoft Mouse”. The reason is to see how many such tutorials still exists these days because people almost forgot MS-DOS… but some still had like the universities and other c programmers reference links…
and a news about geocities is that yahoo is going to stop its free web hosting service… so better save a copy of the information whatever you see in geocities…
It has been a very long time since my programming with the MS-DOS mouse… anyway if good then enjoy…
May 27
I found this some where and thought of having a copy of the following so that i can remember. Written by CaioProiete..
1.
Hello guys!
It is possible to remove the category base from the permalink. Well, not on the administration panel, but with a small hack:
On line 371 of the wp-includes/rewrite.php file, you’ll see the code:
$this->category_structure = $this->front . ‘category/’;
Now just remove the “category” from the string, and the code should look like:
$this->category_structure = $this->front . ‘/’;
Done!
Regards,
CaioProiete - WordPress Member
www.pdaexpert.net
2.
another way of doing that is by the following which worked for me so here we go…
Just enter /. as the value for Category base.
——————————————
i found the above two in the following link
http://wordpress.org/extend/ideas/topic.php?id=359
May 27
I wrote a program to draw on the screen using putpixel which will plot a pixel at x,y,colorvalue where x,y is the location which you can get from the mouse interrupts… so my idea is to draw but this approach was not much effective because if you move the mouse fast you will not get the desired shape…
so i read a technique which is actually the original way of drawing using the mouse using the lineto function which will not break the path where as using putpixel will break…
#include<graphics.h>
#include<bios.h>
#include<dos.h>
void getxy();
int prevx,prevy,mousex,mousey,butt=1;
void main()
{
int x=DETECT,y;
initgraph(&x,&y,"");
// path to EGAVGA.BGI if this is not in your current directory
_AX=0;
asm int 33h
setcolor(15);
while(inportb(0x60)!=1)
{
getxy();
if(butt==1)
{
_AX=2;
asm int 33h
line(mousex-1,mousey-1,prevx-1,prevy-1);
}
else
{
_AX=1;
asm int 33h
}
}
closegraph();
}
void getxy()
{
_AX=3;
asm int 33h;
prevx=mousex;
prevy=mousey;
mousex=_CX;
mousey=_DX;
butt=_BX;
gotoxy(2,2);
printf("%3d %3d %2d",mousex,mousey,butt);
}
_AX=0 - Initialize mouse
_AX=1 - show mouse pointer
_AX=2 - hide mouse pointer
_AX=3 - get coordinates and the return values will be in cs and dx.
The while loop executes till the esc key is pressed
May 26
I use inportb macro for keyboard port 60h to get keystrokes from the keyboard buffer directly using a loop.
for example in a loop executes and in that block i will use this function to get the scan codes of keystrokes and use it… like the following
unsigned char key;
while(1)
{
if((key = inportb(0x60))==1)break; // if esc is pressed
printf("\n%d",key);
}
i hope people know why %d is used for a char datatype. But behind this there is a contradiction among many young programmers…
here, your screen will be flooded with scan codes whether or not press any key… that’s the use of inportb…
you press a key and you can see the scan code. if you want the ascii code then you have to issue an interrupt to get both scan codes and ascii code as integer in which the first 8bits and other 8bits will give you the ascii and scan codes…
and the problem is when you press a key and before you release you are sending more than the limit of keystrokes to the the keyboard buffer and to notify this the beep sound beeps… and these extra keystrokes will appear for your next input which is not needed… it is like if you press ‘k’ and then you do some process and then your code again waits for the key strokes now you will get the remaining k’s from the keyboard buffer if it is not flushed…
so here comes the following code which will clear the keyboard buffer for every time it executes…
#include<stdio.h>
#include<dos.h>
void main()
{
int i;
while(1)
{
if(inportb(0x60)==2)break;
printf("\n%d",inportb(0x60));
_AH=0xc;
_AL=0x2;
asm int 21h
}
}
whether or not a key is pressed the buffer is cleared… so from the next stroke i could assume that only one entry will be present in the keyboard buffer before it is read…
and hope people are good in registers of the processor and interrupts to understand the above code which has an inline assembly language code.
21h is for keyboard and other two are sub functions to clear buffer. maybe i should sit a little more to elaborate. déjame ver if i could… .
May 25
This program displays the click event of the mouse in ms dos environment using Turbo C. If you double click on the screen then you will get the message that you have double clicked else none. I wrote this function to use it in the 640×480 16 color graphics mode for a simple my computer program to which detects single click and double click on a file.
If people know about interrupts, ports, scan codes and button states then it might be useful for them if they are trying to under stand the concept of low level input and output. Using this may help them understand the windows env better…
and one more important point is i have used inline asm codes so … be ware…
here i would like to say one thing and that is about the inportb macro… using this i mimicked a multiprocessing program… which displays the time and at the same time it can detect the mouse and keyboard like in windows… i can never forget this word because i have used it very extensively.
anyway here is the code…
Interrupt 33 deals with the mouse and sub function 0 and 1 are for initialize mouse and show mouse pointer respectively… one interesting function i have made among the others… yeeeehaaawww…
#include<time.h>
#include<stdio.h>
#include<dos.h>
char butt;
clock_t start;
void main()
{
void mouse();
void click();
start=clock();
_AX=0;asm int 33h;
_AX=1;asm int 33h;
while(inportb(0x60)!=1)
{
mouse();
if(butt)
{
click();
while(butt)mouse();
}
}
}
void click()
{
float as;
as=(float) start-clock();
gotoxy(50,2);
if(as>-6.&&as<0.)
printf("double click");
else
printf(" ");
start=clock();
}
void mouse()
{
_AX=3;asm int 33h;
butt=_BX;
}
Recent Comments