Friday, August 31, 2007

Interview with George Hotz

George Hotz or geohot, is now 17 years old guy, and he is the world's first full hardware unlock of the Apple iPhone if you didn’t see iPhone before play the next video.

Really I saw this Arabic article on BBCArabic, and the topic attracted me.

So I get you this article about the topic. And I hope you enjoy the next interview with this respectful guy.

Also he published the full story of success on his blog, … he deserve to be tracked.

You can also see the end of a successful summer vacation

Wednesday, August 15, 2007

Event Synchronization : only on thread can excute

Code snippet

#include "Windows.h"
#include
using namespace std;

HANDLE thread1;
HANDLE thread2;
HANDLE mEvent;    
char x;

// Test thread routine.
DWORD WINAPI F1(LPVOID lpParameter)
{
bool *bRunning = reinterpret_cast(lpParameter);
while(true)
{
if(x=='q')
{
*bRunning = false;
break;
}
WaitForSingleObject (mEvent,INFINITE);//nonsignaled = wait
cout <<"Start F1\n";
cout <<"Working F1 \n";
cout <<"any service from me if so press any key [q to quit]\n";
cin>>x;
cout <<"Thank you\nEnd F1\n\n";
SetEvent(mEvent); //signaled = finished work
}
return 0;
}

// Test thread routine.
DWORD WINAPI F2(LPVOID lpParameter)
{
bool *bRunning = reinterpret_cast(lpParameter);
while(true)
{
if(x=='q')
{
*bRunning = false;
break;
}

WaitForSingleObject (mEvent,INFINITE);//nonsignaled = wait
cout <<"Start F2\n";
cout <<"Working F2 \n";
cout <<"any service from me if so press any key [q to quit]\n";
cin>>x;
cout <<"Thank you\nEnd F2\n\n";
SetEvent(mEvent); //signaled = finished work
}
return 0;
}



void main()
{

bool bRunning = true;
mEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
thread1 = CreateThread(NULL, 0, F1, static_cast(&bRunning), 0, NULL);
thread2 = CreateThread(NULL, 0, F2, static_cast(&bRunning), 0, NULL);
while(bRunning)
{
}
CloseHandle(thread1);
CloseHandle(thread2);
CloseHandle(mEvent);

}

MFC code snippet

#include "stdafx.h"
#include "CEvent.h"
#include "conio.h"
#include "afxmt.h"

using namespace std;

HANDLE thread1;
HANDLE thread2;
CEvent mCEvent(TRUE,FALSE);
char x;

// Test thread routine.
DWORD WINAPI F1(LPVOID lpParameter)
{
bool *bRunning = reinterpret_cast(lpParameter);
while(true)
{
if(x=='q')
{
*bRunning = false;
break;
}
WaitForSingleObject (mCEvent,INFINITE);//nonsignaled = wait
cout <<"Start F1\n";
cout <<"Working F1 \n";
cout <<"any service from me if so press any key [q to quit]\n";
cin>>x;
cout <<"Thank you\nEnd F1\n\n";
SetEvent(mCEvent); //signaled = finished work
}
return 0;
}

// Test thread routine.
DWORD WINAPI F2(LPVOID lpParameter)
{
bool *bRunning = reinterpret_cast(lpParameter);
while(true)
{
if(x=='q')
{
*bRunning = false;
break;
}

WaitForSingleObject (mCEvent,INFINITE);//nonsignaled = wait
cout <<"Start F2\n";
cout <<"Working F2 \n";
cout <<"any service from me if so press any key [q to quit]\n";
cin>>x;
cout <<"Thank you\nEnd F2\n\n";
SetEvent(mCEvent); //signaled = finished work
}
return 0;
}



int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
bool bRunning = true;
thread1 = CreateThread(NULL, 0, F1, static_cast(&bRunning), 0, NULL);
thread2 = CreateThread(NULL, 0, F2, static_cast(&bRunning), 0, NULL);
while(bRunning)
{
}
CloseHandle(thread1);
CloseHandle(thread2);
}
return nRetCode;
}

Download source without using MFC
Download source using MFC

Sunday, August 12, 2007

Handling on resize event in Java Script

Code Snippet

window.onresize= message;
function message()
{
alert("The window has been resized!");
}

View Sample[^]
Dwonload Sample

Get window dimensions by java script

Code Snippet


function DisplayWindowDimensions()
{
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' )
{
myWidth = window.innerWidth; myHeight = window.innerHeight;
}
else if( document.documentElement && (document.documentElement.clientWidth||document.documentElement.clientHeight ) )
{
myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
{
myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
}
window.alert( 'Window Width = ' + myWidth + ' and Window height = ' + myHeight );
}

View Sample[^]
Download Source