diff --git a/Contrib/nsDialogs/Readme.html b/Contrib/nsDialogs/Readme.html
index 9c797d3f..ad03ec1d 100644
--- a/Contrib/nsDialogs/Readme.html
+++ b/Contrib/nsDialogs/Readme.html
@@ -500,7 +500,7 @@ SectionEnd
OnNotify
nsDialogs::OnNotify control_HWND function_address
-Sets a notification callback function for the given control. Whenever the control receives the WM_NOTIFY message, the function will be called and the control's HWND, notification code and a pointer to the NMHDR structure will be waiting on its stack.
+Sets a notification callback function for the given control. Whenever the control receives the WM_NOTIFY message, the function will be called and the control's HWND, notification code and a pointer to the NMHDR structure will be waiting on its stack. Use ${NSD_Return} to return a value.
Use GetFunctionAddress to get the address of the desired callback function.
Returns nothing.
@@ -559,8 +559,6 @@ SectionEnd
${NSD_OnBack} function_name
See OnBack for more details.
-
-
NSD_OnChange
${NSD_OnChange} control_HWND function_name
See OnChange for more details.
@@ -574,6 +572,10 @@ SectionEnd
${NSD_OnNotify} control_HWND function_name
See OnNotify for more details.
+NSD_Return
+${NSD_Return} value
+Used to return a value back to Windows from a OnNotify callback.
+
NSD_SetFocus
${NSD_SetFocus} control_HWND
Sets focus to a control.
diff --git a/Contrib/nsDialogs/defs.h b/Contrib/nsDialogs/defs.h
index b765f22d..14aa58b9 100644
--- a/Contrib/nsDialogs/defs.h
+++ b/Contrib/nsDialogs/defs.h
@@ -5,7 +5,11 @@
#include
-#define NSDFUNC __stdcall
+#define NSDFUNC WINAPI
+
+#define DlgRet(hDlg, val) ( SetWindowLongPtr((hDlg), DWLP_MSGRESULT, (val)) | TRUE )
+#define StrToIntPtr nsishelper_str_to_ptr
+
typedef int nsFunction;
diff --git a/Contrib/nsDialogs/example.nsi b/Contrib/nsDialogs/example.nsi
index 8a7696bc..55bca4f8 100644
--- a/Contrib/nsDialogs/example.nsi
+++ b/Contrib/nsDialogs/example.nsi
@@ -178,9 +178,10 @@ Function NotifyPage
${NSD_CreateRichEdit} 1 1 -2 -2 ""
Pop $9
${NSD_OnNotify} $9 OnNotify
- ${NSD_RichEd_SetEventMask} $9 ${ENM_LINK}
+ IntOp $8 ${ENM_LINK} | ${ENM_KEYEVENTS}
+ ${NSD_RichEd_SetEventMask} $9 $8
SendMessage $9 ${EM_AUTOURLDETECT} 1 0
- ${NSD_SetText} $9 "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard http://nsis.sf.net\par {\b Click the link}...} "
+ ${NSD_SetText} $9 "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard http://nsis.sf.net\par {\b Click the link!}\par\par Type something and I will block every other character...}"
nsDialogs::Show
FunctionEnd
@@ -189,19 +190,29 @@ Function OnNotify
Pop $1 ; HWND
Pop $2 ; Code
Pop $3 ; NMHDR*
- ${IfThen} $2 <> ${EN_LINK} ${|} Return ${|}
- System::Call '*$3(p,p,p,p.r2,p,p,i.r4,i.r5)' ; Extract from ENLINK*
- ${IfThen} $2 <> ${WM_LBUTTONDOWN} ${|} Return ${|}
- IntOp $2 $5 - $4
- System::Call '*(ir4,ir5,l,&t$2,i)p.r2' ; Create TEXTRANGE and a text buffer
- ${If} $2 P<> 0
- IntPtrOp $3 $2 + 16 ; Find buffer
- System::Call '*$2(i,i,p$3)' ; Set buffer in TEXTRANGE
- SendMessage $1 ${EM_GETTEXTRANGE} "" $2 $4
- ${If} $4 <> 0
- System::Call 'SHELL32::ShellExecute(p$hWndParent, p0, pr3, p0, p0, i 1)'
+ ${If} $2 = ${EN_LINK}
+ System::Call '*$3(p,p,p,p.r2,p,p,i.r4,i.r5)' ; Extract from ENLINK*
+ ${IfThen} $2 <> ${WM_LBUTTONDOWN} ${|} Return ${|}
+ IntOp $2 $5 - $4
+ System::Call '*(ir4,ir5,l,&t$2,i)p.r2' ; Create TEXTRANGE and a text buffer
+ ${If} $2 P<> 0
+ IntPtrOp $3 $2 + 16 ; Find buffer
+ System::Call '*$2(i,i,p$3)' ; Set buffer in TEXTRANGE
+ SendMessage $1 ${EM_GETTEXTRANGE} "" $2 $4
+ ${If} $4 <> 0
+ System::Call 'SHELL32::ShellExecute(p$hWndParent, p0, pr3, p0, p0, i 1)'
+ ${EndIf}
+ System::Free $2
+ ${EndIf}
+ ${ElseIf} $2 = ${EN_MSGFILTER}
+ Var /Global Toggle
+ System::Call '*$3(p,i,i,i.r4)' ; MSGFILTER->msg
+ ${If} $4 = ${WM_CHAR}
+ IntOp $Toggle $Toggle ^ 1
+ ${If} $Toggle & 1
+ ${NSD_Return} 1
+ ${EndIf}
${EndIf}
- System::Free $2
${EndIf}
FunctionEnd
diff --git a/Contrib/nsDialogs/nsDialogs.c b/Contrib/nsDialogs/nsDialogs.c
index 2243b038..7688837d 100644
--- a/Contrib/nsDialogs/nsDialogs.c
+++ b/Contrib/nsDialogs/nsDialogs.c
@@ -19,6 +19,7 @@
HINSTANCE g_hInstance;
struct nsDialog g_dialog;
extra_parameters* g_pluginParms;
+LPTSTR g_var0;
static COLORREF GetLinkColor()
{
@@ -149,6 +150,7 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
{
LPNMHDR nmhdr = (LPNMHDR) lParam;
struct nsControl* ctl = GetControl(nmhdr->hwndFrom);
+ int *pFlag = &g_pluginParms->exec_flags->silent, orgFlag, ret; // The silent flag can only be changed in .onInit and custom pages will not be displayed in silent mode so we can use this flag in the callback
if (ctl == NULL)
break;
@@ -156,11 +158,16 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
if (!ctl->callbacks.onNotify)
break;
+ orgFlag = *pFlag, *pFlag = 0;
pushintptr((INT_PTR) nmhdr);
pushintptr(nmhdr->code);
pushintptr((INT_PTR) nmhdr->hwndFrom);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onNotify - 1, 0);
+ ret = *pFlag, *pFlag = orgFlag;
+ if (ret)
+ return DlgRet(hwndDlg, StrToIntPtr(g_var0));
}
+ break;
// handle links
case WM_DRAWITEM:
@@ -266,6 +273,7 @@ void __declspec(dllexport) Create(HWND hwndParent, int string_size, TCHAR *varia
g_dialog.hwParent = hwndParent;
g_pluginParms = extra;
+ g_var0 = variables;
hwPlacementRect = GetDlgItem(hwndParent, popint());
GetWindowRect(hwPlacementRect, &rcPlacement);
diff --git a/Contrib/nsDialogs/nsDialogs.nsh b/Contrib/nsDialogs/nsDialogs.nsh
index dea99068..1c882862 100644
--- a/Contrib/nsDialogs/nsDialogs.nsh
+++ b/Contrib/nsDialogs/nsDialogs.nsh
@@ -413,6 +413,15 @@ Header file for creating custom installer pages with nsDialogs
!insertmacro __NSD_DefineControlCallback Notify
!insertmacro __NSD_DefineDialogCallback Back
+!define NSD_Return "!insertmacro NSD_Return "
+!macro NSD_Return val
+!if "${val}" != "$0"
+ StrCpy $0 ${val}
+!endif
+SetSilent silent
+Return
+!macroend
+
!define __NSD_MkCtlCmd "!insertmacro __NSD_MkCtlCmd "
!macro __NSD_MkCtlCmd msg wp lp hCtl
diff --git a/Docs/src/history.but b/Docs/src/history.but
index c728fc25..f2bcbbfc 100644
--- a/Docs/src/history.but
+++ b/Docs/src/history.but
@@ -16,6 +16,8 @@ Released on ??? ??th, 20??
\b Added MUI_TEXTCOLOR setting
+\b nsDialogs::OnNotify can now return values back to Windows
+
\b Added LIBRARY_INSTALL_EQUAL_VERSION \R{library_install}{InstallLib} option
\b Added NTMARTA to preload list to fix rare Windows 7 security issue (\W{http://sf.net/p/nsis/bugs/1204}{bug #1204})