回调消息???(100分)

  • 主题发起人 主题发起人 Faccey
  • 开始时间 开始时间
F

Faccey

Unregistered / Unconfirmed
GUEST, unregistred user!
什么是回调消息??<br>在delphi中,创建了一个窗口类,在窗口过程中处理消息,可是好象总是把消息发给自己(使用API),然后自己又接受<br>那不成了死循环了么?<br>代码简单如下:<br><br>。。。。。。。<br>procedure TAppBar.WndProc(var M: TMessage);<br>var<br>&nbsp; State: UINT;<br>begin<br>&nbsp; if M.Msg = AppBarMsg then<br>&nbsp; begin<br>&nbsp; &nbsp; case M.WParam of<br><br>&nbsp; &nbsp; &nbsp; ABN_STATECHANGE:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; State := SendAppBarMsg(ABM_GETSTATE);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ABS_ALWAYSONTOP and State = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTopMost(False)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTopMost(True);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; ABN_FULLSCREENAPP:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; State := SendAppBarMsg(ABM_GETSTATE);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if M.lParam &lt;&gt; 0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ABS_ALWAYSONTOP and State = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTopMost(False)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTopMost(True);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if State and ABS_ALWAYSONTOP &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTopMost(True);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;ABN_POSCHANGED:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetAppBarEdge(FEdge);<br>&nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; inherited WndProc(M);<br>end;<br><br>function TAppBar.SendAppBarMsg(Msg: DWORD): UINT;<br>begin<br>&nbsp; if csDesigning in ComponentState then Result := 0<br>&nbsp; else Result := SHAppBarMessage(Msg, FABD);<br>end;<br>。。。。。。。<br>procedure TAppBar.CreateWnd;<br>begin<br>&nbsp; inherited CreateWnd;<br>&nbsp; FABD.hWnd := Handle;<br>&nbsp; if not (csDesigning in ComponentState) then<br>&nbsp; begin<br>&nbsp; &nbsp; if SendAppBarMsg(ABM_NEW) = 0 then<br>&nbsp; &nbsp; &nbsp; raise EAppBarError.Create('Failed to create AppBar');<br>&nbsp; &nbsp; &nbsp; &nbsp; SetAppBarEdge(FEdge);<br>&nbsp; end;<br>。。。。。。。
 
你的程序只处理了你需要的消息,大部分消息都由系统缺省的 DefWindowProc 过程去处理<br>了,你调用 SHAppBarMessage 或其它消息分派 API 的时候也把控制转给了系统的,系统<br>获得控制后可以调度让其他的任务得到处理的。系统也可以根据运行时间片强行切换任务<br>的,因为它的优先级高。并且,有些进程可能一段时间都没有消息可处理,处于休眠的状<br>态。
 
To bbkxjy:<br>调用SHAppBarMessage(msg,param1),是把msg发给param1结构参数中的Hwnd,还是发给windows外壳呢??
 
是发给自己的。即 Param1 中的 Hwnd。
 
但是,SendAppBarMsg(ABM_GETSTATE)发给窗口过程,而在窗口过程中又发SendAppBarMsg(ABM_GETSTATE)这不成了循环调用了么???
 
你并没有在响应 ABM_GETSTATE 消息的处理中再次调用 SendAppBarMsg(ABM_GETSTATE),<br>因此没有形成循环调用。AppBar 窗口对该消息的处理是调用了缺省的窗口过程。即最<br>后面的 inherited WndProc(M) 这个调用。
 
回调函数:<br>&nbsp; &nbsp;比如有两歌函数A,B;<br>&nbsp; &nbsp;你用A的地址作为参数传给B,然后B根据这个地址来调用A,这个A就叫回调函数!
 
lentilz, 好人
 
接受答案了.
 
后退
顶部