Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2002.04.29;
Скачать: [xml.tar.bz2];

Вниз

Системный таймер   Найти похожие ветки 

 
Sniffer   (2002-04-13 22:25) [0]

Привет всем! Кто нить скажет, чё ето за штуковина и как её юзать.
В моём разумении системный таймер, ет выполняет те же самые ф-ции как и стандартный дельфийский компонент......исправте если ошибаюсь. Усем сенкс!


 
Anatoly Podgoretsky   (2002-04-13 22:45) [1]

Это оболочка над системным таймером


 
Sniffer   (2002-04-13 22:52) [2]

А как яё юзать?


 
Sniffer   (2002-04-13 23:03) [3]

Я имел в виду можно ли етот самый системный таймер юзать, обходя компонент?


 
Anatoly Podgoretsky   (2002-04-13 23:30) [4]

Посмотри исходники TTimer


 
Sniffer   (2002-04-13 23:39) [5]

Чёрт............не могу найти


 
Oleg_Gashev   (2002-04-14 02:10) [6]

Timer Functions

The following functions are used with timers.

KillTimer
QueryPerformanceCounter
QueryPerformanceFrequency
SetTimer
TimerProc

Timer Messages

The following message is used with timers.

WM_TIMER



 
Oleg_Gashev   (2002-04-14 02:11) [7]

Using Timer Functions to Create a Mousetrap

Sometimes it is necessary to prevent more input while you have a cursor on the screen. One way to accomplish this is to create a special routine that traps mouse input until a specific event occurs. Many developers refer to this routine as "building a mousetrap."

The following example uses the SetTimer and KillTimer functions to create a simple mousetrap. SetTimer creates a timer that sends a WM_TIMER message every 10 seconds. Each time the application receives a WM_TIMER message, it records the cursor location. If the current location is the same as the previous location and the application"s main window is minimized, the application moves the cursor to the icon. When the application closes, KillTimer stops the timer.

HICON hIcon1; // icon handle
POINT ptOld; // previous cursor location
UINT uResult; // SetTimer"s return value
HINSTANCE hinstance; // handle of current instance

//
// Perform application initialization here.
//

wc.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(400));
wc.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(200));

// Record the initial cursor position.

GetCursorPos(&ptOld);

// Set the timer for the mousetrap.


uResult = SetTimer(hwnd, // handle of main window
IDT_MOUSETRAP, // timer identifier
10000, // 10-second interval
(TIMERPROC) NULL); // no timer callback

if (uResult == 0)
{
ErrorHandler("No timer is available.");
}

LONG APIENTRY MainWndProc(
HWND hwnd, // handle of main window
UINT message, // type of message
UINT wParam, // additional information

LONG lParam) // additional information
{

HDC hdc; // handle of device context
POINT pt; // current cursor location
RECT rc; // location of minimized window

switch (message)
{
//
// Process other messages.
//

case WM_TIMER:
// If the window is minimized, compare the current
// cursor position with the one from 10 seconds
// earlier. If the cursor position has not changed,

// move the cursor to the icon.

if (IsIconic(hwnd))
{
GetCursorPos(&pt);

if ((pt.x == ptOld.x) && (pt.y == ptOld.y))
{
GetWindowRect(hwnd, &rc);
SetCursorPos(rc.left, rc.top);
}
else
{
ptOld.x = pt.x;
ptOld.y = pt.y;
}

}

return 0;

case WM_DESTROY:

// Destroy the timer.

KillTimer(hwnd, IDT_MOUSETRAP);
PostQuitMessage(0);
break;

//
// Process other messages.
//

}




 
Oleg_Gashev   (2002-04-14 02:11) [8]

Although the following example also creates a mousetrap, it processes the WM_TIMER message through the application-defined callback function MyTimerProc, rather than through the application"s message queue.

UINT uResult; // SetTimer"s return value
HICON hIcon1; // icon handle
POINT ptOld; // previous cursor location
HINSTANCE hinstance; // handle of current instance

//
// Perform application initialization here.
//

wc.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(400));
wc.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(200));

// Record the current cursor position.

GetCursorPos(&ptOld);

// Set the timer for the mousetrap.


uResult = SetTimer(hwnd, // handle of main window
IDT_MOUSETRAP, // timer identifier
10000, // 10-second interval
(TIMERPROC) MyTimerProc); // timer callback

if (uResult == 0)
{
ErrorHandler("No timer is available.");
}

LONG APIENTRY MainWndProc(
HWND hwnd, // handle of main window
UINT message, // type of message
UINT wParam, // additional information
LONG lParam) // additional information

{

HDC hdc; // handle of device context

switch (message)
{
//
// Process other messages.
//

case WM_DESTROY:
// Destroy the timer.

KillTimer(hwnd, IDT_MOUSETRAP);
PostQuitMessage(0);
break;

//
// Process other messages.
//

}

// MyTimerProc is an application-defined callback function that
// processes WM_TIMER messages.


VOID CALLBACK MyTimerProc(
HWND hwnd, // handle of window for timer messages
UINT message, // WM_TIMER message
UINT idTimer, // timer identifier
DWORD dwTime) // current system time
{

RECT rc;
POINT pt;

// If the window is minimized, compare the current
// cursor position with the one from 10 seconds earlier.
// If the cursor position has not changed, move the
// cursor to the icon.


if (IsIconic(hwnd))
{
GetCursorPos(&pt);

if ((pt.x == ptOld.x) && (pt.y == ptOld.y))
{
GetWindowRect(hwnd, &rc);
SetCursorPos(rc.left, rc.top);
}
else
{
ptOld.x = pt.x;
ptOld.y = pt.y;
}
}
}


(C) Borland Help



 
SoftOne   (2002-04-14 03:19) [9]

Ранее принято было под "системным таймером" понимать таймер, который вызывает, периодически, прерывание 8.
"Обходя компонент", следует ловить WM_TIMER.
Или задать "CallBack" функцию.
Все это описано в Хэлпе. См. например, функцию SetTimer.


 
Sniffer   (2002-04-14 15:19) [10]

Усем сенкс, сча попробую


 
Sniffer   (2002-04-14 15:48) [11]

У мене проблем.........Почему такое не хотит пахать :
function TForm1.Kiss : Pointer;
begin
................
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetTimer(Application.Handle, null, 1, Kiss)
end;
Дельфа ругается говорит :
Invalid variant type conversion



 
Sniffer   (2002-04-14 16:07) [12]

Кстати ещё вопрос по теме, в хелпе написяно :
TIMERPROC lpTimerFunc // address of timer procedure
Как тогда можно узнать адрес процедуры Timer Proc?


 
Sniffer   (2002-04-14 16:07) [13]

Кстати ещё вопрос по теме, в хелпе написяно :
TIMERPROC lpTimerFunc // address of timer procedure
Как тогда можно узнать адрес процедуры TimerProc?


 
Anatoly Podgoretsky   (2002-04-14 16:13) [14]

null это вариант, тебе нужно использовать 0


 
Sniffer   (2002-04-14 18:04) [15]

Не усё равно не пашет, я думаю, что надо указать адрес процедуры,
например Time, но я не знаю как ето сделать. Может кто-нить знает?


 
ION T   (2002-04-14 18:32) [16]

1.Адрес и надо передавать;
2.Насколько я знаю, коллбэк не может быть методом;
3.И вообще это процедура должна быть

Так шо оно должно быть типа:

procedure Kiss(Wnd: hWnd; uMsg, idEvent: cardinal; dwTime: LongWord); stdcall;
begin
beep;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SetTimer(Application.Handle, 0, 1000, @Kiss)
end;


 
Sniffer   (2002-04-14 19:37) [17]

>>Ion T
Обьявление SetTimer(Application.Handle, 0, 1000, @Kiss) вызывает ошибку :
[Error] Unit1.pas(39): Variable required


 
Sniffer   (2002-04-14 21:07) [18]

Народ? Чё в облом мозгами пошевилить?


 
Biorobot   (2002-04-14 21:14) [19]

Таймер что-то делает через определённый промежуток времени, например через кааждые 1 секунду. Выполняет событие онТаймер


 
Sniffer   (2002-04-14 21:19) [20]

Прелестно! Ты меня просвятил, а я ведь не знал чё делает таймер OnTimer! Мне всё же интересно, почему такое бьявление :
SetTimer(Application.Handle, 0, 1000, @Kiss)
взывает ошибку : [Error] Unit1.pas(39): Variable required %(


 
Anatoly Podgoretsky   (2002-04-14 21:20) [21]

Кто то обязан? Будещь требовать, будут вообще молчать.
У тебя ощибка в другои месте


 
Sniffer   (2002-04-14 21:27) [22]

>>Anatoly Podgoretsky
Никто не обязан, просто.........гм да лодно.........извиняюсь, если кого обидел. А где ошибка то?


 
Sniffer   (2002-04-14 21:28) [23]

>>Anatoly Podgoretsky
Никто не обязан, просто.........гм да ладно.........извиняюсь, если кого обидел. А где ошибка то?


 
Anatoly Podgoretsky   (2002-04-14 21:39) [24]

Не ясно как у тебя в данный момент объявлен kiss


 
Sniffer   (2002-04-14 21:44) [25]

Как обычно,
procedure Kiss; stdcall;
begin
...........
end;


 
Anatoly Podgoretsky   (2002-04-14 22:04) [26]

Вообще то надо так, procedure Kiss(Wnd: hWnd; uMsg, idEvent: cardinal; dwTime: LongWord); stdcall;

Но это не принципиально для ошибки, я ее не вижу.


 
ION T   (2002-04-14 22:07) [27]

Шо у тебя за Дельфи?


 
Aleks1   (2002-04-15 05:38) [28]

2 Sniffer (14.04.02 19:37)
Вот читаю я хэлп Д4:

UINT SetTimer(

HWND hWnd, // handle of window for timer messages
UINT nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc // address of timer procedure
);


Parameters

nIDEvent

Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored.
А у тебя там ноль!?


 
Anatoly Podgoretsky   (2002-04-15 10:18) [29]

Aleks1 (15.04.02 05:38)
Для начала смотрим, что там не 0, а Application.Handle, затем
срочно идем в СРР и узнаем что такое UINT, и что такое NULL, после этого возрвращаемя сюда и говорим, что писать в данном случае нужно 0


 
Sniffer   (2002-04-15 18:25) [30]

Так в гле ошибка то?


 
Sniffer   (2002-04-15 20:40) [31]

Так в где ошибка то?


 
kull   (2002-04-15 22:02) [32]

У меня вот это дело прекрасно работает:


procedure Kiss(Wnd: hWnd; uMsg, idEvent: cardinal; dwTime: LongWord); stdcall;
begin
beep;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SetTimer(Application.Handle, 0, 1000, @Kiss)
end;


может стоит посмотреть внематочно на код, может где-то еще?


 
ION T   (2002-04-15 22:55) [33]

Поставь галочку на Ctrl+Shift+F11->Compiler->Extended Syntax


 
Sniffer   (2002-04-15 23:01) [34]

Я пересмотрел код........... Кому интиресно вот он :
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Kiss; stdcall;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.Kiss; stdcall;
begin
beep
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetTimer(Application.Handle, 0, 1000, @Kiss)
end;
end.
После нажатия F9 выделяет строку
SetTimer(Application.Handle, 0, 1000, @Kiss)
и говорит :
[Error] Unit1.pas(37): Variable required
Поясните плиз чё здесь я не так написал


 
Sniffer   (2002-04-15 23:04) [35]

>> ION T
Поставил, ноль на массу :((, та же ошибка :
[Error] Unit1.pas(37): Variable required


 
Anatoly Podgoretsky   (2002-04-15 23:07) [36]

У тебя нет процедуры, а есть метод класа, хотя в ответ на прямой вопрос Anatoly Podgoretsky © (14.04.02 21:39) ты привел недостоверную информацию Sniffer (14.04.02 21:44)


 
kull   (2002-04-15 23:09) [37]

Так вот, есть разница между
procedure Kiss;
и
procedure TForm1.Kiss;
?

этот пример работает с процедурой.


 
Sniffer   (2002-04-15 23:10) [38]

>> Anatoly Podoretsky
А не очень понял, то что вы написали.......... Не могли бы вы более детально пояснить?


 
Anatoly Podgoretsky   (2002-04-15 23:14) [39]

А правильный ответ тебе трижды дали
ION T © (14.04.02 18:32)
Anatoly Podgoretsky © (14.04.02 22:04)
kull © (15.04.02 22:02)


 
Sniffer   (2002-04-15 23:15) [40]

>> kull
Ты хочешь сказать, что такой код работает?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Kiss; stdcall;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure Kiss; stdcall;
begin
beep
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetTimer(Application.Handle, 0, 1000, @Kiss)
end;
end.



 
kull   (2002-04-15 23:23) [41]

да.


 
kull   (2002-04-15 23:25) [42]

Насчет работы в Runtime не проверял, но при компиляции ошибок не выдает.


 
Sniffer   (2002-04-15 23:27) [43]

>> kull
Вот блин! Нивезуха! У всех усё пашет, а умене точно такой же код даже не компилируется! У мене всё та же дурацкая ошибка :
[Error] Unit1.pas(37): Variable required !!!!!!!!!!!!!!!!!!!!!!!!!


 
kull   (2002-04-15 23:36) [44]

Слушай,ну не знаю, у меня Delphi6


 
Sniffer   (2002-04-15 23:41) [45]

Всё сенкс! До жирафа дошло!
>> Анатолий Подгоретский
Я понял, о чём вы говорили, я чуток лопухнулся сорри.
>> kull
Я тя наверно чуток достал, извени :))
>> Всем всем
Спасибо!!!!!!!!!!!!!


 
Anatoly Podgoretsky   (2002-04-15 23:45) [46]

Ну тебе сказали же, это не может быть методом класса, а только отдельной процедурой, а ты продолжаешь настаивать, вон и kull(а) уже запутал, хотя сначала он тебе правильно указал на эту ошибку.


 
Aleks1   (2002-04-16 02:58) [47]

> Anatoly Podgoretsky © (15.04.02 10:18)

>>Aleks1 (15.04.02 05:38)
>>Для начала смотрим, что там не 0, а Application.Handle, затем
>>срочно идем в СРР и узнаем что такое UINT, и что такое NULL, >>после этого возрвращаемя сюда и говорим, что писать в данном >>случае нужно 0

UINT - это и ежу ясно - Unsigned Integer;
Другое дело, что, по-моему, хэлп Д4 виноват!
Написано:
nIDEvent
Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored.

Должно быть:
nIDEvent
Specifies a nonzero timer identifier. If the hWnd parameter is NOT NULL, this parameter is ignored.



Страницы: 1 2 вся ветка

Форум: "Основная";
Текущий архив: 2002.04.29;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.56 MB
Время: 0.007 c
1-94497
Ptushenko Denis
2002-04-16 15:33
2002.04.29
Кто знает как проигрывать MP3 ?


1-94494
Ptushenko Denis
2002-04-16 15:13
2002.04.29
Кто знает как убрать в РичЭдите мигаюший курсор и запретить...


3-94282
Igor65
2002-04-08 14:54
2002.04.29
Как импортировать информацию из txt файла в базу


4-94644
alexey111111
2002-02-27 12:42
2002.04.29
WIN API


7-94600
kioto
2002-01-27 10:59
2002.04.29
Отображение содержимого окна при перетаскивании





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский