WndSubclass plug-in: Difference between revisions
(v0.0.4) |
m (Don't force include dir) |
||
(One intermediate revision by the same user not shown) | |||
Line 16: | Line 16: | ||
==Examples== | ==Examples== | ||
The following example mimics the behavior of EM_SETCUEBANNER | 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). | 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). | ||
Line 22: | Line 22: | ||
<highlight-nsis> | <highlight-nsis> | ||
!include "nsDialogs.nsh" | !include "nsDialogs.nsh" | ||
!include "winmessages.nsh" | !include "winmessages.nsh" | ||
!include "logiclib.nsh" | !include "logiclib.nsh" | ||
!include "MUI2.nsh" | !include "MUI2.nsh" | ||
Line 36: | Line 31: | ||
OutFile "test.exe" | OutFile "test.exe" | ||
Page Custom CustomPage | Page Custom CustomPage | ||
var NSD_TextField | var NSD_TextField | ||
var TextFieldSubProc | var TextFieldSubProc | ||
Function CustomPage | Function CustomPage | ||
nsDialogs::Create 1018 | nsDialogs::Create 1018 | ||
Pop $ | Pop $0 | ||
${NSD_CreateText} 0 0 100% 8% "Password" | ${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% "" | ${NSD_CreateLabel} 0 10% 100% 8% "" | ||
Pop $0 | |||
nsDialogs::Show | nsDialogs::Show |
Latest revision as of 13:23, 12 July 2018
Author: Anders (talk, contrib) |
Download
WndSubclass.zip (7 KB)
Info
- Version: v0.0.4 (Experimental)
- Type: Runtime plugin
- Targets: x86-ansi, x86-unicode, amd64-unicode
- Minimum OS: Win95/NT4
- Minimum NSIS Version: 2.43
- License: Freeware
This plug-in will let you subclass any window in the NSIS process.
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.
!include "nsDialogs.nsh" !include "winmessages.nsh" !include "logiclib.nsh" !include "MUI2.nsh" !include "WndSubclass.nsh" OutFile "test.exe" Page Custom CustomPage var NSD_TextField var TextFieldSubProc Function CustomPage nsDialogs::Create 1018 Pop $0 ${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 $0 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"