C ++中子类系统类的最佳实践

时间:2013-09-02 10:23:53

标签: c++ winapi subclass edit subclassing

我正在使用Win32包装器类。我最初通过以下方式对EditBox进行了子类化:

// Create the Edit Box
Edit_hWnd = CreateWindowEx(.., "Edit", ...);

Edit_OldProc = (WNDPROC)GetWindowLongPtr(Edit_hWnd, GWLP_WNDPROC);
SetWindowLongPtr(Edit_hWnd, GWLP_WNDPROC, (LONG_PTR)EditWndProc);

// Then in EditWndProc(...):

return CallWindowProc(Edit_OldProc, hWnd, Message, wParam, lParam);

我刚刚遇到一个新方法,它设置了Window System with System Class'。这会是一个更优选的方法吗?我真的很惊讶我从未见过这个,因为我已经超过了数百个子类来源。

新方法:

WNDCLASS wc;

GetClassInfoEx(hInstance, "Edit", &wc);
wc.lpszClassName = L"NewEditClass";
Edit_OldProc     = wc.lpfnWndProc;
wc.lpfnWndProc   = EditWndProc
RegisterClassEx(&wc);

// Create the Edit Box
CreateWindowEx(.., "NewEditClass", ...);

// Then in EditWndProc(...):

return Edit_OldProc(hWnd, Message, lParam, wParam);

0 个答案:

没有答案
相关问题