![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Функции SeTimer, KillTimer [D7, WinXP]
ChtoMe © (2005-04-21 17:48:00)У меня проблема с работой функций SetTimer и KillTimer. Проблема в следующем: в моей программе нету формы поэтому код, который не работает слудующий:
program Project1;
uses
windows,messages,sysutils,dialogs;
var
temer,cont:integer;
{$R *.res}
procedure getting(hnd:HWND;uMsg:UINT;tem:UINT;tickt:DWORD);
begin
inc(cont);
inputbox('1','','');
if cont>5 then killtimer(0,temer); //если судить по //документации, то вместо temer можно использовать tem, но толку //от этого мало
end;
begin
cont:=0;
temer:=settimer(0,0,100,@getting);
inputbox(bla-bla-bla','','');
end.
По моей задумке должен вылезти inputbox 5 раз после чего таймер должен убиться функцией killtimer, но inputbox у меня вылазеет гораздо больше чем 5 раз. Короче программа зацикливается.
Подскажите, может я чё-то не так делаю? И если у кого есть пример как правильно работать с таймером без формы скажите где взять плиз или скиньте на jeon@inbox.ru
KosilkA (2005-04-21 18:36:00) [21]
> alpet © (21.04.05 18:28) [11]
прям таки никогда?
ChtoMe (2005-04-21 18:35:00) [22]Спасибо, так работает, но некоторые моменты не понятны. Зачем добавлять stdcall? Чем функция с stdcall отличается от простой?
И вот ещё не ясно:(hwnd, uMsg, nEvent, dwTime: DWORD);?
А где же тут тип передаваемыхь переменных? Ваще не врублюсь...
alpet (2005-04-21 18:28:00) [23]KosilkA © (21.04.05 18:20) [10]
а ты пробовал? =))
нет, и дисскусию прекращаем. Всего что не хватает ChtoMe - умения пользоваться отладчиком. Управление ветке if count > 5 ни когда не передается из-за вызова модального диалога.
KosilkA (2005-04-21 18:20:00) [24]
> alpet © (21.04.05 18:19) [8]
а ты пробовал? =))
KosilkA (2005-04-21 18:20:00) [25]да и вообще, чего париться, если в uses стоит dialogs то не грех и forms добавить и таймер с палитры кинуть, все равно на весе уже не сэкономишь =))))
alpet (2005-04-21 18:19:00) [26]KosilkA © (21.04.05 18:17) [7]
Очень смешно :-). Только не будет работать.
KosilkA (2005-04-21 18:17:00) [27]
>
> ChtoMe (21.04.05 17:48)
може так...
procedure getting(hnd:HWND;uMsg:UINT;tem:UINT;tickt:DWORD);
begin
KillTimer(temer); inc(cont);
inputbox('1','','');
if cont>5 then killtimer(0,temer) else
temer:=SetTimer(0,0,100,@getting);
end;
alpet (2005-04-21 18:15:00) [28]Если уж совсем точно - то без разницы какой, если не указано окно, но есть callback фукнция.
alpet (2005-04-21 18:13:00) [29]alpet © (21.04.05 18:08) [2]
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.
Вернее наоборот, нулевой когда hWnd = 0. Сам ошибся.
alpet (2005-04-21 18:11:00) [30]+ про соглашение stdcall как всегда забыл.
В C++:
VOID CALLBACKTimerProc(HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime
);
В Delphi должно быть как:
procedure (hwnd, uMsg, nEvent, dwTime: DWORD); stdcall;
begin
end;
Digitman (2005-04-21 18:09:00) [31]ты, чудо, вообще-то титал описание ф-ции SetTimer в стандартной справке ?
alpet (2005-04-21 18:08:00) [32]Второй Параметр должен быть не нулевой.
nIDEvent
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.
alpet (2005-04-21 18:08:00) [33]Второй Параметр должен быть не нулевой.
nIDEvent
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.