WndSubclass plug-in: Difference between revisions
(added an example) |
m (Fixed download) |
||
Line 3: | Line 3: | ||
==Download== | ==Download== | ||
<attach>WndSubclass.zip</attach> | |||
==Info== | ==Info== |
Revision as of 20:03, 15 July 2011
Author: Anders (talk, contrib) |
Download
WndSubclass.zip (7 KB)
Info
This plug-in will let you subclass any window in the NSIS process (Not thread safe ATM)
Examples
The following example mimics the behavior of EM_SETCUEBANNER, but can be used on older windows versions, multi-line textboxes and Windows XP with asian language support without problems.
The code essentially displays an Edit (text) field with custom colors (grey on white) and the string "Password". When the user sets focus to this field (via mouse or keyboard), and its content is "Password", its content is cleared and the control colors set to another set of custom colors (black on white). When the user removes focus from this field (via mouse or keyboard), and its content is empty, the 'Password' text and grey on white colors are restored. If the field is not empty, the string the user has entered remains.
!addplugindir "." !addplugindir ".\release\" !addincludedir "." !include "nsDialogs.nsh" !include "winmessages.nsh" !include "logiclib.nsh" !include "MUI2.nsh" !include "WndSubclass.nsh" OutFile "test.exe" var dialog Page Custom CustomPage var NSD_TextField var NSD_Label var TextFieldSubProc Function CustomPage nsDialogs::Create 1018 Pop $dialog ${NSD_CreateText} 0 0 100% 8% "Password" Pop $NSD_TextField SetCtlColors $NSD_TextField 0x888888 0xffffff ${WndSubclass_Subclass} $NSD_TextField TextFieldSubProc $TextFieldSubProc $TextFieldSubProc ${NSD_CreateLabel} 0 10% 100% 8% "" Pop $NSD_Label nsDialogs::Show FunctionEnd Function TextFieldSubProc ${If} $2 = ${WM_SETFOCUS} ${NSD_GetText} $NSD_TextField $R0 ${If} $R0 == "Password" ${NSD_SetText} $NSD_TextField "" SetCtlColors $NSD_TextField 0x000000 0xffffff ${EndIf} ${ElseIf} $2 = ${WM_KILLFOCUS} ${NSD_GetText} $NSD_TextField $R0 ${If} $R0 == "" ${NSD_SetText} $NSD_TextField "Password" SetCtlColors $NSD_TextField 0x888888 0xffffff ${EndIf} ${EndIf} FunctionEnd Section SectionEnd !insertmacro MUI_LANGUAGE "English"