Archive: Refresh Layer


Refresh Layer
  Hello,

I am trying to display a message on a nsis 2.46.5-Unicode MUI2 page while calling a function.
Thing is, the text will only be displayed after the function closes.
The only way I found to avoid this was to include a MessageBox.

Is there a way to 'refresh' the page/layer without using a MultiProcess plugin or a MessageBox?


Example:


"MUI2.nsh"

>!include "nsDialogs.nsh"

>!define PRODUCTNAME "RefreshLayer"
>Name "${PRODUCTNAME}"
>OutFile "${PRODUCTNAME}.exe"

>RequestExecutionLevel user

>!define BLACK "0x000000"
>!define RED "0xFF0000"
>!define GREEN "0x009900"

>!insertmacro MUI_LANGUAGE "English"

>;------------------------
!macro _ConsoleWindowRefresh CONTROL STRING COLOR COLORBACK

ShowWindow${CONTROL} ${SW_HIDE}
SetCtlColors ${CONTROL} "${COLOR}" "${COLORBACK}"
${NSD_SetText} ${CONTROL} "${STRING}"
ShowWindow ${CONTROL} ${SW_SHOW}

!macroend

>!define ConsoleWindowRefresh "!insertmacro _ConsoleWindowRefresh"
>;------------------------

>Page custom nsDialogsMainPage


Section ""
>SectionEnd

>Function nsDialogsMainPage

!insertmacro MUI_HEADER_TEXT $(PAGEMAIN_TITLE) $(PAGEMAIN_SUBTITLE)

nsDialogs::Create 1018
Pop$0

${If} $0 == error
Abort
${EndIf}


${
NSD_CreateLabel} 0 90% 100% 10u ""
Pop $R0

${NSD_CreateButton} 20% 30% 20% 40u "TestWithoutMSGB"
Pop $R1
${NSD_OnClick} $R1 TestWithoutMSGB

${NSD_CreateButton} 60% 30% 20% 40u "TestWithMSGB"
Pop $R2
${NSD_OnClick} $R2 TestWithMSGB


nsDialogs::Show

FunctionEnd

>Function TestWithoutMSGB

${ConsoleWindowRefresh} $R0 " never to be seen... " "${RED}" "${BLACK}"
Sleep 1000
${ConsoleWindowRefresh} $R0 " Ever to be seen... " "${GREEN}" "transparent"

>FunctionEnd

>Function TestWithMSGB

${ConsoleWindowRefresh} $R0 " never to be seen... " "${RED}" "${BLACK}"
MessageBox MB_OK " ... "
${ConsoleWindowRefresh} $R0 " Ever to be seen... " "${GREEN}" "transparent"

>FunctionEnd
>

Lose ShowWindow (don't hide the control) and it will work. But you can't use transparent in the 2nd call because the new text will be drawn on top of the old one, which will remain visible.


MessageBox will pump messages, Sleep does not so no WM_PAINT is processed, you have to force a paint cycle...

!macro _ConsoleWindowRefresh CONTROL STRING COLOR COLORBACK

ShowWindow ${CONTROL} ${SW_HIDE}
SetCtlColors ${CONTROL} "${COLOR}" "${COLORBACK}"
ShowWindow ${CONTROL} ${SW_SHOW}
${NSD_SetText} ${CONTROL} "${STRING}"
System::Call 'USER32::RedrawWindow(i${CONTROL},i0,i0,i0x787)'

!macroend
Switching to and from transparent is problematic so the hide/show hack has to stay.

Thanks a lot!

It works like a charm.