我需要获取当前的 WndProc
及其消息和配置,并向其中添加我自己的代码。为什么我需要这个?因为我正在使用 WndProc 定义窗口(及其子控件)的 IDE 下工作,所以我需要修改它,因为它包含与每个控件相关的所有操作。如果我将控件指向自定义 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 过程中使用 CallWindowProc() 来调用它。看看这篇文章:
引用:
... your subclass function should go something like this:
wndProcOrig = (WNDPROC)SetWindowLongPtr(hwndButton, GWLP_WNDPROC, (LONG_PTR)SubclassWndProc); LRESULT CALLBACK SubclassWndProc(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam) { switch (wm) { ... default: return CallWindowProc(wndprocOrig, hwnd, wm, wParam, lParam); } }
关于C++ Winapi HWND 获取 WndProc 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31650118/