最近发现了一个可怕的问题,我无法理解CALLBACK,谁能给系统的讲解一下它是如何工作的,以及它的来龙去脉。

解决方案 »

  1.   

    A callback function is essentially an event handler that is implemented by an application and called by the system. Microsoft® Windows® applications typically implement multiple callback functions, each one designed for a particular set of events. When an event occurs, the system notifies the application by calling the appropriate callback function. The callback function also usually has a parameter list that the system can use to pass the application more detailed information about the event. The most common example of a callback function is the window procedure. This function is used by the system to pass Windows messages to the applications that owns the window. 
      

  2.   

    不是让你自己在程序里直接调用的,你直接通过WINDOWS系统间接呼叫的函数,譬如你发一个消息给系统,然后系统来调用你的函数.
      

  3.   

    让系统调用自己的回调的一个例子
    UINT_PTR SetTimer(
      HWND hWnd,              // handle to window
      UINT_PTR nIDEvent,      // timer identifier
      UINT uElapse,           // time-out value
      TIMERPROC lpTimerFunc   // timer procedure
    );
    lpTimerFunc 就是指像一个回调函数。
    形势如下
    VOID CALLBACK TimerProc(
      HWND hwnd,         // handle to window
      UINT uMsg,         // WM_TIMER message
      UINT_PTR idEvent,  // timer identifier
      DWORD dwTime       // current system time
    );
      

  4.   

    CALLBACK 是由系统调用的函数,比如窗口函数
      

  5.   

    老大们啊,我对你们的回答不是很满意,要想知其然,会用这些API就可以了,我想知道其所以然。有什么地方有这个的详解吗?
      

  6.   

    我的理解是在callback函数中定义对某消息的接受,当你向系统发送这个消息时,系统就会调用这个函数来执行你的消息。
    --------
    不知道是不是,请大虾指正。《大菜鸟》
      

  7.   

    得到一高手指点,与大家共飨。它是由系统定义了固定的格式,而有你来实现,你将该函数地址传给系统,当系统内部实现某特定操作时,便调用你的函数。该系统不一定是指的windows,也可能是你写的一个dll之类的,从这个方面来理解,我感觉和接口有点像,不知道对不对。希望高手继续指点。