Search code examples
nsis

NSIS onblur or onfocus event equivalent


I need to be able to fill out a second text box based on content from another (first) text box, and I need to do it when the first text box loses focus (or when the second text box gains focus).

I am not able to do what I need to do using OnChange because it is triggered after every keypress, but the value of the first text box needs to be evaluated only after the user finishes inputting.

How would I do this? There are no OnBlur or OnFocus event handlers, and the existing ones OnChange, OnClick, OnBack, OnNotify can't seem to do the job.


Solution

  • I don't think nsDialogs can handle this, you probably have to use the WndSubclass plug-in:

    Page Custom MyPage
    Page InstFiles
    
    !include LogicLib.nsh
    !include nsDialogs.nsh
    !include WinMessages.nsh
    !include WndSubclass.nsh
    
    Var EditName
    Var EditNick
    Var NickSubProc
    
    Function MyPage
    nsDialogs::Create 1018
    Pop $0
    
    ${NSD_CreateText} 7% 0 77% 12u "Joe Sixpack"
    Pop $EditName
    
    ${NSD_CreateText} 7% 14u 77% 12u ""
    Pop $EditNick
    ${WndSubclass_Subclass} $EditNick NickSubProc $NickSubProc $NickSubProc
    
    nsDialogs::Show
    FunctionEnd
    
    Function NickSubProc
    ${If} $2 = ${WM_SETFOCUS}
        ${If} $3 = $EditName ; $EditName lost focus?
        ${OrIf} $3 = 0 ; or no previous focus?
            ${NSD_GetText} $EditName $4
            ${If} $4 != ""
                ${NSD_SetText} $EditNick "Foo $4 Bar"
                SendMessage $EditNick ${EM_SETSEL} 0 -1
            ${EndIf}
        ${EndIf}
    ${EndIf}
    FunctionEnd
    
    Section
    SectionEnd