WndSubclass plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(added an example)
m (Don't force include dir)
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:


==Download==
==Download==
[http://stashbox.org/358546/WndSubclass%20v0.0.3.zip v0.0.3]
<attach>WndSubclass.zip‎</attach>


==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==
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 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 15: Line 22:


<highlight-nsis>
<highlight-nsis>
!addplugindir "."
!addplugindir ".\release\"
!addincludedir "."
!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 29: Line 31:
OutFile "test.exe"
OutFile "test.exe"


var dialog
 


Page Custom CustomPage
Page Custom CustomPage


var NSD_TextField
var NSD_TextField
var NSD_Label
var TextFieldSubProc
var TextFieldSubProc


Function CustomPage
Function CustomPage
nsDialogs::Create 1018
nsDialogs::Create 1018
Pop $dialog
Pop $0


${NSD_CreateText} 0 0 100% 8% "Password"
${NSD_CreateText} 0 0 100% 8% "Password"
    Pop $NSD_TextField
Pop $NSD_TextField
SetCtlColors $NSD_TextField 0x888888 0xffffff
SetCtlColors $NSD_TextField 0x888888 0xffffff
    ${WndSubclass_Subclass} $NSD_TextField TextFieldSubProc $TextFieldSubProc $TextFieldSubProc
${WndSubclass_Subclass} $NSD_TextField TextFieldSubProc $TextFieldSubProc $TextFieldSubProc
 
${NSD_CreateLabel} 0 10% 100% 8% ""
${NSD_CreateLabel} 0 10% 100% 8% ""
    Pop $NSD_Label
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"