You are on page 1of 13

‫السالم عٌيمم م رحمم م م يكاُت ُتم‪..

‬‬

‫ٌفم م ملِئح َوك َوذام‬


‫هذامالد س ٌاح يزمر لمالاكٌح ‪ ¤Timers¤‬حك ُته َو م محكل َولكاِئددُتم حن ُتم م َوي َو‬

‫ك!!‬ ‫رٌ ثمسند س الاكٌح مح نماألس كسم مل ٌسم ض عماألدادم عىمالل مم م‪..‬مح‬

‫الا كٌح ‪ ¤‬الحإقتم‪¤‬مه م رددما قٌتمٌراكجمإلٌهكمالح حجم‪,‬اساعح لمفًماليثٌ محنمال احج‪..‬‬

‫مهًماخصٌص حهعممزحنٌممٌاممحعم َوحضِئ ٌِّ َوهكمإ سكلم سكلم‪ ¤‬القٌ كم عح ل ‪ ¤.‬أيمس ممإ سكلم‬
‫ال سكلم‪.‬‬

‫الاكٌح ‪ٌ ¤ Timer ¤‬عحلم ردد الحٌعٌثكنٌم أيم‪ 1000/ 1‬مث كنٌمم مهًمفا دمصغٌ دمج دا‪..‬‬

‫لينم َوي ًكي مل ٍّل لعا كٌح مرد دمرٌثمأصغ ه كم‪ 1‬حٌعٌثكنٌم مأي هك ‪ 4.294.967.295‬حٌعٌث كنٌم مه م‬
‫حكٌقك بم‪ 50‬مٌ حك!!!‬

‫الاعكحلمحع الاكٌح مٌح م ‪ 3‬ح ارل يحكمٌ ضر مالحخطط‪:‬‬


‫الح رعم األ ل ى‪Alocate Timer :‬‬

‫ح ر عم إنشكءمالاكٌح ‪ ¤Timer¤‬مرجزمحي كنمل مفًمالذاي د‪..‬‬

‫غكل كمحك اي نمهذهمالح رعمم ندمإنشكءمالنكفذدمحثالم ن د‪ WM_INITDIALOG‬أ‬


‫‪WM_CREATE..‬‬

‫فٌاممالرجز حعمّإنشكءمالنكفذدم‪,‬م مهن ككمدالممحسإ لمم نمذلكمهً‪SetTimer‬‬

‫الدالمماؤخذمهذامالشيل‪:‬‬

‫‪http://msdn.microsoft.com/en-us/library/ms644906%28VS.85%29.aspx‬‬

‫هذهمالدالم حنمحيا م ‪User32.dll‬‬

‫مهًمااعكحل حعم رددمرسكبمال قتمالحا اجددمف ً‪ ROM BIOS‬لينم ط ٌقممغٌ مح كش دم‬


‫رٌثمار ل‬

‫إلىمدالم اعحلمارت ‪ Kernel Mode‬لين ملٌسمح ض نكمالٌ مم‪,‬ملعدالم يحكمنالرظم‪4‬‬


‫ك احا ات هً‪:‬‬

‫‪ hWnd :‬مه محق ضملعنكفذدمالاًمن ٌدم ضعمالاكٌح م ه ك‪.‬‬

‫‪ nIDEvent :‬ه م قممالاكٌح مالذيمسنع ف م‪¤‬مهذامال ك احا محهمجدام ندماساخداممأيث محنم‪ 1‬م‬
‫اكٌح ‪¤ .‬‬

‫‪ uElapse :‬مارددمقٌحممالحهعمم‪,‬ميح كمقعنكمس ك قك كلحٌعٌثكنٌم‪.‬‬

‫‪ lpTimerFunc :‬مه محإش منر مالدالم‪.‬‬

‫الح رعممالثكنٌم‪use Timer :‬‬

‫مالحهعم‬
‫‪.‬‬ ‫هذهمالح رعم اخصمإساعحكلمالاكٌح ميحكمقعنكمسك قكمأيمإ سكلم سكلممحعمح‬

‫هذه ال س كلمماسحى ‪WM_TIMER‬‬

‫سكلم‬
‫‪.‬‬ ‫فا دمحعٌنممٌاممإ كددمالقٌكمم كل ظكافم ندماعكمال‬ ‫محعمح‬
‫يحث كلمنضع ش طكم‪,‬م مفًمال ‪ Interval‬ضعنكم‪ 3000‬حٌعٌثكنٌم ‪ ,‬سٌعٌدمال نكحجمالارققمحنم‬
‫الش طمحعمح ميلم‪ 3‬ث ان‪.‬‬

‫الح رعم الثكلثم‪Delete Timer :‬‬

‫ٌمم ماعنًمالاخعصمحنمالاكٌح ‪.‬‬ ‫هذهمالعحعٌم ض‬

‫الاخعصمحن الاكٌح مٌي نمإحكم ؤح محنمالح حجمأ م د ن ‪.‬‬

‫رٌثم ؤح محن الح حجمنعنًم ذلكمأنمالح حجمسٌق مم رذفمالاكٌح م ندماإلناهكءمحنم ظٌلا ‪.‬‬

‫هنك سٌساخدممدالممحسإ لمم نمذلكمهً‪KillTimer‬‬

‫هذهمالدالم يح كمنالرظماؤخذم ك احا ٌنمهح ك‪:‬‬

‫‪ hWnd :‬مه محق ضملعنكفذدمالاًم هكمالاكٌح ‪.‬‬

‫‪ uIDEvent :‬مه م قممالاكٌح مالذيم مااع فمالدالممإلٌ م‪,‬مرسبحكرددنكهمسك قك‪.‬‬


‫‪http://msdn.microsoft.com/en-us/library/ms644903%28VS.85%29.aspx‬‬

‫قعنكمسك قكمأنمالاكٌح ٌرذفمفًميعاكمالركلاٌنمس اءم ؤح محنمالح حجمأ م د ن‬

‫د ن الح حجمالاكٌح مسٌرذفماعقكاٌكم ندمحغكد دمال نكحجم م كلط عمسٌساحلماعقكاٌكمالدالم‬


‫‪KillTimer‬‬

‫عز ُتممحع َوفاُته ك‬


‫ش َوٌكءمال ِّاًم َوٌ َو‬
‫اآلنم عد ا ضٌحمآلٌمم حلمالاكٌح ‪ ¤ Timer ¤‬هن ككماليثِئٌ ُت محن األ ْ‬

‫سنؤاًمأ ال حثكلم سٌطمليٌلٌمماساخداممالاكٌح مح ع ‪ C++‬ط عك‬

‫سنعحلم عى ‪ DevC++ ide‬لاسهٌلماليثٌ محنماألح‬


‫عدهكمإذهب إلى‬

‫‪File==>New==>Project‬‬

‫عدهكمق م حكمٌعً‪:‬‬
‫هذامس س سٌطمي كنمحخزنمحس قكمحعمال نكحج‪:‬‬
‫الرظمهذا الحي كنمفًماألسلل‬

‫هذامحكمٌسحى رعقممال سكالمرٌثمهنكمقعبمال نكحج‬

‫نالرظم ج د سكلمم ارددمهً ‪ WM_DESTROY‬مهًمخكصمم غعق ال ن كحج‬

‫يحكمقعن ك سك قكمسنضٌفم سكلاٌن‬

‫‪ WM_CREATE‬م داخعهكمسنضعمدالممإنشكءمالاكٌح ‪SetTimer‬‬

‫‪ WM_TIMER‬م داخعهكمسنضعمالي دمالخكصم كلاكٌح‬

‫أظنميلمشًء اضحمإلىماآلن‬

‫ميلم‪ 3‬مث ان‬ ‫الرظ امفً الحثكلم ضعتم ع مماظه محعمح‬


‫الناٌجم ساي نمنكفذدم كدٌم‬

‫م‪ 3‬ث ان‬ ‫عدمح‬

‫فقطملعاؤيدمنناظ محددمأط ل‬
‫هنكمأي نمقد ضعتمحثكالم سٌطكملعا ضٌح‬

‫ يحكمقعنكمسك قكملممناخعصمحنمالاكٌح ملذامفسٌاخعصمحن مال نكحجم ندمالخ ج‬: ‫حالرظم‬

‫لينمٌحيننك ا قٌفم حع م إضكفم‬

KillTimer(hwnd,0);

:‫الس س الحساعحلمفًمالحث كلمأ اله‬


#include <windows.h>

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,


HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */


wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */


if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/


hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */


ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */


while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

return messages.wParam;
}

/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{

case WM_CREATE:
SetTimer(hwnd,0,3000,0);
break;

case WM_TIMER:
MessageBox(hwnd,"This is a timer test !!","Information",MB_OK);
break;

case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}

: ‫ مأ مأيث‬2‫اآلن قٌ َوتمط ٌق ممإساخدامماكٌح ٌنم‬

2‫ م م‬1‫عٌن كمأ ال اع ٌ فمثك اٌنمٌرحالنمال ق مم‬

#define TIMER_ONE 1

#define TIMER_TWO 2

SetTimer‫عده ك عٌن كماع ٌفمالاكٌح ٌنم إساخداممالدالم‬

SetTimer (hwnd, TIMER_ONE, 3000, NULL) ;


SetTimer (hwnd, TIMER_TWO, 6000, NULL) ;

:ً‫ث ممناج إلىمرعقممال سكالم منغٌ ميكلاكل‬

case WM_TIMER:
switch (wParam)
{
case TIMER_ONE:
MessageBox(NULL,"This is Timer 1","Timer1",MB_OK);
break ;
case TIMER_TWO:
MessageBox(NULL,"This is Timer 2","Timer2",MB_OK);
break ;
}

‫لٌي ن إجحكلًمحكيا نكه‬


#include <windows.h>
#define TIMER_ONE 1
#define TIMER_TWO 2
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}

/* This function is called by the Windows function DispatchMessage() */


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{

case WM_CREATE:
SetTimer (hwnd, TIMER_ONE, 3000, NULL) ;
SetTimer (hwnd, TIMER_TWO, 6000, NULL) ;
break;

case WM_TIMER:
switch (wParam)
{
case TIMER_ONE:
MessageBox(NULL,"This is Timer 1","Timer1",MB_OK);
break ;
case TIMER_TWO:
MessageBox(NULL,"This is Timer 2","Timer2",MB_OK);
break ;
}
return 0 ;

case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
‫م‬
‫م‬
‫م‬
‫م‬
‫اآلنمحعمالاج ٌ ب‪:‬‬

‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫يآخ مشًءمسؤضعم ٌنمأٌدٌيممحثكالمإلساخدام الاكٌح مفًمحش عم سٌطمحنم حجاًم‪:‬‬

‫‪http://www.startimes2.com/f.aspx?t=20988491‬‬

‫أ ج مأنمأي نم فقتمفًمالش ح‬

‫ًم‪¤‬‬ ‫‪ ¤‬مهذامالد سملنماجدهمفًمأيمح ق عم‬

‫السالمم عٌيم‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬
‫م‬

‫الياكبم مالش حمحنماقدٌممم‪ hSm-iNfO‬م‬


‫م‬
‫اإلٌحٌلم‪:‬م‪ ab.houssem@hotmail.fr‬م‬
‫م‬
‫أليماسالس ك مالماا ددمفًماإلاصكل‬

You might also like