我需要获取当前的WndProc及其消息和配置,并向其中添加自己的代码。我为什么需要这个?因为我在一个使用WndProc定义窗口(及其子控件)的IDE下工作,所以我需要对其进行修改,因为它包含与每个控件相关的所有 Action 。如果我将控件指向自定义WndProc,则该控件会丢失IDE设置的所有操作和配置。有什么建议吗?

方案:

HWND button; //My Button
LONG_PTR wndProc = GetWindowLongPtr(button, GWL_WNDPROC); //Getting the WndProc

wndProc -> Get this `WndProc` source code

LRESULT CALLBACK WndProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){

    wndProc (all the data);
    + my messages

}

最佳答案

您当然无法获得“旧” WndProc的源代码,但是可以在新的wnd proc中使用CallWindowProc()对其进行调用。查看这篇文章:

When you subclass a window, it's the original window procedure of the window you subclass you have to call when you want to call the original window procedure

引用:

关于c++ - C++ Winapi HWND获取WndProc配置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31650118/

10-10 21:36