DispatchMessage 如何决定使用哪个 WndProc?
我正在研究一个开源项目的一些代码,这是我第一次处理 Win32 应用程序(主要是控制台的东西)。我看到代码中的几个函数是 Windows 过程,因为它们返回 LRESULT CALLBACK。
程序员是否需要做一些事情来确保 DispatchMessage 调用正确的 WndProc,或者 DispatchMessage 的编码方式使其可以自行确定正确的 WndProc?
编辑:
我猜测 DispatchMessage(const MSG*) 在应用程序中的不同 WndProc 之间进行选择的方式是基于传递给它的 MSG 对象的窗口句柄成员 (HWND)。[希望之前例如,如果消息是针对应用程序的编辑窗口的(而不是针对其主窗口),则 DispatchMessage 将为特定类选择 WndProc 成员函数编辑窗口是其对象。如果消息是针对主窗口的,那么它将选择主窗口所属的类的 WndProc 成员函数(对我来说,这个类将是 Notepad_plus_Window 类)。但这只是一个想法。我没有找到太多证据来支持它,所以如果有人能证实这一点,我会很高兴。
I'm going through some code for an open source project and this is my first time dealing with a Win32 app (mostly did console stuff). I see that several functions within the code are windows procedures because they return LRESULT CALLBACK.
Is there something the programmer has to do to make sure DispatchMessage invokes the right WndProc or is DispatchMessage coded in a way that it can determine the right WndProc all on its own?
EDIT:
I'm guessing that the way DispatchMessage(const MSG*) chooses between different WndProc's in an application is based on the window handle member (HWND) of the MSG object passed to it.[Hope previous sentence wasn't too confusing.] If the message was for the edit window for an application, for example, (and not for its main window,) then DispatchMessage will choose the WndProc member function for the particular class for which the edit window is an object of. If the message was for the main window, then it would choose the WndProc member function for the class that the main window is an object of (for me, this class would be the Notepad_plus_Window class). This is only a thought, though. I haven't found much to back it up so I'd be glad if anyone could confirm this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你是对的,它使用 MSG.hwnd 将消息发送到正确的窗口。需要注意的一件事是,它将使用与窗口关联的 WndProc,而不是窗口类。窗口是窗口类的实例。
这篇 Microsoft 的“Under The Hood”文章相当详细地说明了这一点< href="http://www.microsoft.com/msj/0397/hood/hoodtextfigs.htm#fig3" rel="nofollow">伪代码 DispatchMessage() 也可能值得一看)
Yes you are right, it uses MSG.hwnd to send the message to the correct window. One thing to be noted, it will use the WndProc associated with the window, not the window class. A window is an instance of a window class.
This article of Microsoft's "Under The Hood" illustrates this with rather detailed pseudo-code of DispatchMessage() that might be worth taking a look as well )