Using C ++ Builder to perform accuracy

zhaozj2021-02-11  228

Using C Builder to perform accuracy

Although the Win95 is visualized by VC, Delphi, C Builder, there is a dedicated timer control Timer, and it is easy to use, you can implement a certain timing function, but the minimum timing accuracy is only 55ms, and the timer message is operated in multiple tasks. The priority in the system is very low, and it is not possible to respond in time, and it is often not possible to meet the applications in real-time control environments. However, Microsoft has provided users with a set of underlying functions for high-precision timing in the Win32 API library. If the user is used, the timing accuracy can be 1 ms. This timing accuracy can fully meet the requirements for the general real-time system control. The main interface function (function name, parameter, functionality) of the reproduction provided by C Builder 4.0 will now be provided with the following:

1. DWORD TIMEGETTIME (VOID)

Returns the number of milliseconds that started from Windows start. The maximum is 232, about 49.71

day.

2. MMResult Timesetevent (uint udelay, uint uresolution, lptimecallback lptimeproc, dword dwuser, uint fuevent)

This function sets a timing callback event that can be a one-time event or a periodic event. Once the event is activated, the specified callback function is adjusted, and then returns the identifier code of the event, otherwise returns NULL. The parameters are as follows:

Udelay: Specifies the cycle of events in milliseconds.

URESOLUTION: The accuracy of the delay in milliseconds, the smaller the numerical value, the higher the timer event resolution. The default is 1 ms.

LPTIMEPROC: Points a callback function.

Dwuser: Store the callback data provided by the user.

FUEVENT: Specify Timer Event Type:

Time_ONESHOT: UDELAY only one event after milliseconds

Time_periodic: Periodically generate events every Udelay millisecond.

3. MMResult Timekillevent (uint utimerid)

This function cancels a specified timer callback event. UTIMERID identifies an event to be canceled (the identifier returned by the TimeSetEvent function). If success, return Timerr_NoError if the timer time does not exist, returns MMSYSERR_INVALPARAM.

Void Callback TimeProc (Uint UID, UINT UMSG, DWORD DWUSER, DWORD DW1, DWORD DW2);

This function is a callback function defined by an application that is called when a timer event occurs. TimeProc is a placeholder for a function name defined by an application. When using this function, it should be noted that it can only call the following limited set of API functions:

Postmessage,

TimegetsystemTime,

TimegetTime,

TimesetEvent,

TIMEKILLEVENT,

MidiOutshortmsg,

MIDIOUTLONGMSG,

Outputdebugstring.

转载请注明原文地址:https://www.9cbs.com/read-4910.html

New Post(0)