A callback function that is often processed by a custom View.

Source: Internet
Author: User

A callback function that is often processed by a custom View.

OnFinishInflate () is triggered when all the child controls in the View are mapped to xml

OnMeasure (int, int) determines the size of all child elements

OnLayout (boolean, int, int) is triggered when the View allocates the size and position of all child elements.

OnSizeChanged (int, int) is triggered when the view Size changes

OnDraw (Canvas) view rendering content details

OnKeyDown (int, KeyEvent) is triggered when a key is pressed.

OnKeyUp (int, KeyEvent) triggered when a key is pressed and then popped up

OnTrackballEvent (MotionEvent) trackball event

OnTouchEvent (MotionEvent) touch screen event

OnFocusChanged (boolean, int, Rect) is triggered when the View gets or loses focus.

OnWindowFocusChanged (boolean) is triggered when the view contained in the window gets or loses focus.

OnAttachedToWindow () is triggered when a view is attached to a window.

OnDetachedFromWindow () is triggered when the view leaves the attached window. This method is opposite to onAttachedToWindow.

OnWindowVisibilityChanged (int) is triggered when the visible view contained in the window changes


AS30: Is the callback function related to custom events? How are they used? What are their purposes and benefits,

The callback function is like calling 138 xxxxx after you tell someone what you want to do for me.

This is your callback function.

Callback processing functions, such as XML loading in as2.0 or onLoader onLoadInit in movi1_loader loader, fail to load or complete loading, are executed asynchronously.

The callback function defines the format of input parameters of the function.

A custom event is more flexible than a callback function. It is more like a relationship between the host and the answer.

The host said that the Q & A competition is now in progress. After I finish the question, you can press the Q & A key to answer the question.

At this time, the people who follow this event will register for attention, while those who have nothing to do with Will be able to ignore it.

The respondent pays close attention to the host (the event dispatcher). Once the question is read (the event is distributed), the subject will be handled accordingly.

Event parameters can be carried by the event object itself (event senders package an event object with the event type and corresponding custom carrying data) when the event receiver receives the event, you can view the event object and obtain the data carried in it. Compared with the callback function passing the value through the form parameter, the event is more stable (carried by event-class objects)

Vb callback function example

About callback Functions
---- CallbackFunction is a function provided by an application to a Windows system DLL or called by another DLL. It is generally used to intercept messages, obtain system information, or process asynchronous events. The application tells the DLL the address pointer of the callback function, and the DLL will call the function when appropriate. The callback function must comply with the pre-defined parameter format and transfer method. Otherwise, when the DLL is called, the program or system will crash.
---- Generally, the callback function uses the standard WindowsAPI call method, namely _ stdcall. Of course, the DLL compiler can define the call method by itself, but the client program must comply with the same rules. In the _ stdcall mode, function parameters are pushed to the stack in the order from right to left. Except for specifying a pointer or reference, parameters are passed by value, before the function is returned, the parameter is automatically popped up from the stack. Use function pointer in VB5
---- Assume we have defined the following callback function: ---- PublicfunctionEnumWindowsProc (ByValhwndAsLong, ByVallParamAsLong) AsLong
---- You can use AddressOfEnumWindowsproc to obtain its address. In WIN32, the address length is 32 bits. Because VB does not have the pointer concept, therefore, function pointers are generally stored in a Long variable, which does not cause any problems. ---- There are many restrictions on using function pointers in VB5. First, the function body must be placed in the standard. in the BAS module, but not in the class module or form code. Secondly, AddressOf can only be used for custom processes, functions, or attributes, and cannot be used for external functions declared by the Declare statement, it cannot be used for functions in the Type Library. Finally, the processes, functions, and attributes written after AddressOf must be in the same project with the relevant declarations and procedures. ---- The AddressOf operator can only appear in the parameter list of a function. Some API functions require that the function pointer be stored in a member of a structure and the structure is passed as a parameter, in this case, you cannot directly assign the result obtained by AddressOf to the structure member. Instead, you must use a packaging function to convert the result. The following FnPtrToLong function pointer can be converted to the Long type:
FunctionFnPtrToLong (ByVallngFnPtrAsLong) AsLong
FnPtrToLong = lngFnPtr
EndFunction
The following code puts the EnumWindowsProc function pointer into the structure:
DimmtasMyType
Mt. FnPtr = FnPtrToLong (AddressOfEnumWindowsProc)
Simple example of using a callback function-enumeration window
---- To illustrate how to use the callback function, Let's first look at a simple example of EnumWnd that implements the enumeration window function. ---- There is an EnumWindows function in WIN32API. If you provide a callback function for it, it will enumerate all the top-level windows in the system and call the callback function once each enumeration window, with the window handle passed by EnumWindows, the callback function can understand the title, class name, and whether the window is visible. The EnumWindows function declaration is as follows: ---- DeclareFunctionEnumWindowsLib "user32" (ByVallpEnumFuncAsLong, _ ByVallParamAsLong) AsLong
---- The lParam can be defined by the application itself. We are going to display the title of the window in a list window (ListView). This ListView is displayed in the form of Report, with two columns in total, the hexadecimal window handle and window title are displayed respectively. (For the specific attribute values of ListView, see the complete code of the attached program ). First, the callback function EnumWindowsProc is provided.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.