Re: Unicode Button in VB6
- From: "Thorsten Albers" <albersRE@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 15 Apr 2006 08:33:38 -0700
Jérémie Gent <jer_kjr@xxxxxxxxxxx> schrieb im Beitrag
<#xMO6S0XGHA.4768@xxxxxxxxxxxxxxxxxxxx>...
That looks good to me, but isn't detailed enough for me. I don't exactlyI
know how to subclass my window to avoid to conversion Unicode -> Ansi. I
suppose the call to SetWindowLongW might need a special GWL_EXSTYLE, but
don't know which and how.
You are subclassing a window by replacing the original window procedure
with your own window procedure. Therefore to subclass a window you have to
call SetWindowLong() with GWL_WNDPROC as the second and the address of the
new window procedure as the third parameter. There is no need to call
SetWindowLongW() because the VB standard controls are all of ANSI window
classes and not UNICODE window classes.
Your own window procedure has to be in a VB standard module (*.BAS), there
is no other place where you can put it. You retrive the address of the
window procedure with the VB statement AddressOf. E.g.:
----- BAS module:
Public Function MyWindowProc _
( _
ByVal hWnd As Long, _
ByVal lMessage As Long, _
ByVal lWParam As Long, _
ByVal lLParam As Long _
) As Long
....
End Function
----- Form module:
pfnWindowProcPrev = SetWindowLong(...hWnd, GWL_WNDPROC, AddressOf
MyWindowProc)
If pfnWindowProcPrev = 0 Then
' ... Failure
End If
You have to save the value returned by SetWindowLong() which is the address
of the previous window procedure. This address is needed for two reasons:
1. If you application is about to finish, it has to restore the original
window procedure addresses of all subclassed windows (i.e. 'unsubclass'
them). A place where to do this is the QueryUnload or Unload event.
2. Messages not handled by your own window procedure have to be passed to
the original window procedure (CallWindowProc(pfnWindowProcPrev, ...)).
By this it is obvious that pfnWindowProcPrev has to be accessable both in
the form module and the BAS module. A good place to store it therefore is
in a window property of the subclassed window (SetProp(), GetProp(),
RemoveProp()).
After you have successfully subclassed the button window your own window
procedure has to process all window messages that are sent to the button
window in order to (re)paint the button text. To decide how to handle
messages a good approach is reading the chapter "Button Default Message
Processing" in the MSDN. The most important message to be handled by you
own window procedure is of course WM_PAINT.
When subclassing a VB standard control remember that these controls
themselves are already subclassed controls (the VB standard controls do not
subclass the window but the respective standard window class), so their
behaviour may be different from the standard window class they are using.
--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------
.
- Follow-Ups:
- Re: Unicode Button in VB6
- From: Jérémie Gent
- Re: Unicode Button in VB6
- From: Jérémie Gent
- Re: Unicode Button in VB6
- References:
- Unicode Button in VB6
- From: Jérémie Gent
- Unicode Button in VB6
- Prev by Date: Re: Unicode Button in VB6
- Next by Date: Re: Unicode Button in VB6
- Previous by thread: Re: Unicode Button in VB6
- Next by thread: Re: Unicode Button in VB6
- Index(es):