Home > Back-end >  The callback function definition
The callback function definition

Time:11-03

Look for several days the callback function is used, or fog, ask the teachers guidance, class A timer content is as follows:

Cstrings str1=list1. GetItemText (1, 2);
Cstrings str2=list2. GetItemText (0, 2);
If (STR==L "XXX" | | str1==L "XXX")
{
.
}

The above in the timer run once every 100 milliseconds,
But the two cell string is through the edit changes of class B, the opportunity to change is very small,

How to define a callback function in the class B the edit loses focus, run the above code, only the if the judgment to the timer,
Because the edit in class is a custom Shared class, directly in the edit vector coke message function run the above code will affect the use of other,

CodePudding user response:

In a class B additional addCallback function, the parameter is a function pointer, and add a member variable and function pointer (or a set of function Pointers), addCallback function is assigned to the parameters of a function pointer member variables (or appended to the member variables)
In the edit loses focus in the additional message function, to judge if a member variable of function Pointers is not NULL (or collection is not NULL), calls to functions that member variables of a function pointer,
, because other edit objects without calling addCallback function, a member variable is NULL pointer function (or collection is empty), will not perform the callback function, will not affect the other, of course, considering the convenience, you can also add removeCallback function to delete the callback function (these are the latter),

CodePudding user response:

In addition to the second floor said method, also can be in the edit loses focus when send a custom message to the parent window... Use the message mechanism to achieve
  • Related