WndSubclass plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Fixed download)
(v0.0.4)
Line 6: Line 6:


==Info==
==Info==
This plug-in will let you subclass any window in the NSIS process (Not thread safe ATM)
* '''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==
==Examples==

Revision as of 00:13, 6 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.

!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"