Quote "Subclassing Controls" document from https://learn.microsoft.com/en-us/windows/win32/controls/subclassing-overview
Disadvantages of the Old Subclassing Approach
The following list points out some of the disadvantages of using the previously described approach to subclassing a control.
- The window procedure can only be replaced once.
- It is difficult to remove a subclass after it is created.
- Associating private data with a window is inefficient.
- To call the next procedure in a subclass chain, you cannot cast the old window procedure and call it, you must call it by using the CallWindowProc function.
this avoids call PointerFromWindow() for every message.
Patch replaced old PASCAL with CALLBACK.
Looking source code for
SetWindowSubclass()at https://gitlab.winehq.org/wine/wine/blob/master/dlls/comctl32/commctrl.c, it's just wrap forSubclassWindow()andCallWindowProc(), maybe inefficient (useGetProp()to retrieve callback function and data).The change also added comctl32.dll dependency for Scintilla.dll, may not a problem for GUI app/lib.
With old approach,
ListBoxX::ControlWndProccan still be eliminate (to avoidPointerFromWindow(::GetParent(hWnd))) with something likeSetWindowLongPtr(lb, DWLP_USER, reinterpret_cast<LONG_PTR>(this)).That is something I'd be worried about as well.
Yes, it would need to be in other Win32 build files like
win32/makefile/There is a possibility of clashing with application code since they may consider themselves the user.
https://stackoverflow.com/questions/117792/best-method-for-storing-this-pointer-for-use-in-wndproc#65876605
I think use
GWLP_USERDATAonlbis fine as it's system ListBox control which private to and used byListBoxX(thewidcontainer).Update
win32/makefile.SciTEWin::AboutMessage()(in SciTEWinDlg.cxx) usesGWLP_WNDPROCandGWLP_USERDATA.I'm not seeing a strong benefit here with a simple use of window bytes replaced by a window property. The disadvantages listed above don't seem relevant. Scintilla never removes the subclass and data is stored in the C++ class so is easy to access. Is there some needed function that can be implemented by application code subclassing the listbox instead of the
ListBoxX?As explained in the above link,
SetWindowSubclassuses aUxSubclassInfoproperty which will be less efficient. Maybe the cost isn't significant.The thunk technique mentioned in the linked message isn't a good direction. While it is efficient and widely used by Microsoft code, it generates code then turns on execution for that code. Executing generated code is similar to malware behaviour so would make Scintilla appear more dangerous.
OK, just fell code with
SetWindowSubclassis clean.SetWindowSubclassseems to be a better approach in more complex situations in applications where there may be multiple features or code sources (like plug-ins and scripting) that need to subclass a window.Applications that use Scintilla will likely be more maintainable if they use
SetWindowSubclasssince there are often multiple reasons to enhance Scintilla. OnceSetWindowSubclassis used for one element, its then more consistent to use it in all cases.s/PASCAL/CALLBACK/is fine although not significant.Changed to
CALLBACKwith [94f6bd] [bbbd84] .Related
Commit: [94f6bd]
Commit: [bbbd84]