no more /UNLOAD with new plug-in api

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5844 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2008-12-12 19:31:52 +00:00
parent 06ab0c6314
commit 3db2839a3c
9 changed files with 65 additions and 36 deletions

View file

@ -98,10 +98,17 @@ DWORD WINAPI BannerThread(LPVOID lpParameter)
return 0; return 0;
} }
void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) static UINT_PTR PluginCallback(enum NSPIM msg)
{
return 0;
}
void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{ {
EXDLL_INIT(); EXDLL_INIT();
extra->RegisterPluginCallback(hInstance, PluginCallback);
{ {
DWORD dwThreadId; DWORD dwThreadId;
DWORD dwMainThreadId = GetCurrentThreadId(); DWORD dwMainThreadId = GetCurrentThreadId();

View file

@ -9,9 +9,9 @@ OutFile "Banner Test.exe"
ShowInstDetails show ShowInstDetails show
Function .onInit Function .onInit
Banner::show /NOUNLOAD "Calculating important stuff..." Banner::show "Calculating important stuff..."
Banner::getWindow /NOUNLOAD Banner::getWindow
Pop $1 Pop $1
again: again:

View file

@ -8,9 +8,9 @@ There are three functions - show, getWindow and destroy.
Usage Usage
----- -----
Banner::show /NOUNLOAD "Text to show" Banner::show "Text to show"
[optional] Banner::getWindow /NOUNLOAD [optional] Banner::getWindow
Banner::destroy Banner::destroy
@ -21,7 +21,7 @@ Modern UI
The Modern UI has two labels on the IDD_VERIFY dialog. To change all the texts, use: The Modern UI has two labels on the IDD_VERIFY dialog. To change all the texts, use:
Banner::show /NOUNLOAD /set 76 "Text 1 (replaces Please wait while Setup is loading...)" "Normal text" Banner::show /set 76 "Text 1 (replaces Please wait while Setup is loading...)" "Normal text"
Custom UI Custom UI
--------- ---------
@ -30,7 +30,7 @@ If you have more labels on your IDD_VERIFY dialog, you can use multiple /set par
Example: Example:
Banner::show /NOUNLOAD /set 76 "bah #1" /set 54 "bah #2" "Normal text" Banner::show /set 76 "bah #1" /set 54 "bah #2" "Normal text"
The second parameter for /set is the ID of the control. The second parameter for /set is the ID of the control.
@ -39,7 +39,7 @@ Some More Tricks
If you use /set to set the main string (IDC_STR, 1030) you can specify a different string for the window's caption and for the main string. If you use /set to set the main string (IDC_STR, 1030) you can specify a different string for the window's caption and for the main string.
If you use an empty string as the main string (Banner::show /NOUNLOAD "") the banner window will not show on the taskbar. If you use an empty string as the main string (Banner::show "") the banner window will not show on the taskbar.
Credits Credits
------- -------

View file

@ -8,7 +8,7 @@
g_stringsize=string_size; \ g_stringsize=string_size; \
g_stacktop=stacktop; } g_stacktop=stacktop; }
#define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) #define NSISFunc(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
char szTemp[2048]; char szTemp[2048];
HWND hWndImage, hWndParent; HWND hWndImage, hWndParent;
@ -61,11 +61,24 @@ HBITMAP __stdcall LoadBitmapFile(long right, long bottom, BITMAP *bBitmap);
COLORREF GetColor(); COLORREF GetColor();
void __stdcall GetXY(LPPOINT lpPoint); void __stdcall GetXY(LPPOINT lpPoint);
NSISFunc(Destroy);
static UINT_PTR PluginCallback(enum NSPIM msg)
{
if (msg == NSPIM_GUIUNLOAD)
{
Destroy(0, 0, 0, 0, 0);
}
return 0;
}
BOOL bReturn; BOOL bReturn;
NSISFunc(SetReturn) { NSISFunc(SetReturn) {
EXDLL_INIT(); EXDLL_INIT();
extra->RegisterPluginCallback(g_hInstance, PluginCallback);
popstring(szTemp); popstring(szTemp);
bReturn = !lstrcmpi(szTemp, "on"); bReturn = !lstrcmpi(szTemp, "on");
} }
@ -83,6 +96,8 @@ static void __stdcall my_pushstring(char *str)
NSISFunc(SetBg) { NSISFunc(SetBg) {
EXDLL_INIT(); EXDLL_INIT();
extra->RegisterPluginCallback(g_hInstance, PluginCallback);
ECS(); ECS();
if (!hWndImage) { if (!hWndImage) {
@ -335,7 +350,7 @@ NSISFunc(Destroy) {
SendMessage(hWndImage, WM_CLOSE, 0, 0); SendMessage(hWndImage, WM_CLOSE, 0, 0);
hWndImage = 0; hWndImage = 0;
oldProc = NULL; oldProc = NULL;
Clear(0, 0, 0, 0); Clear(0, 0, 0, 0, 0);
UnregisterClass("NSISBGImage", g_hInstance); UnregisterClass("NSISBGImage", g_hInstance);
} }

View file

@ -20,15 +20,10 @@ Usage
Notes Notes
~~~~~ ~~~~~
* All but the last used function (which should be Destroy) must use /NOUNLOAD so the image window won't be destroyed before it should. * This plugin requires NSIS 2.42 and above.
* This plugin requires NSIS 2.0b4 and above.
* Do not call SetBg (which creates the window) from a section or a function called by a section. * Do not call SetBg (which creates the window) from a section or a function called by a section.
* Never use /NOUNLOAD in .onInstSuccess and .onInstFailed. Failing to do so will cause the installer to crash.
This means you should not call Destroy from .onInstSuccess or .onInstFailed.
Available functions Available functions
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~

View file

@ -22,32 +22,32 @@ Function .onGUIInit
!ifdef DEBUG !ifdef DEBUG
# turn return values on if in debug mode # turn return values on if in debug mode
BgImage::SetReturn /NOUNLOAD on BgImage::SetReturn on
!endif !endif
# set the initial background for images to be drawn on # set the initial background for images to be drawn on
# we will use a gradient from drak green to dark red # we will use a gradient from drak green to dark red
BgImage::SetBg /NOUNLOAD /GRADIENT 0 0x80 0 0x80 0 0 BgImage::SetBg /GRADIENT 0 0x80 0 0x80 0 0
!insertmacro GetReturnValue !insertmacro GetReturnValue
# add an image @ (150,0) # add an image @ (150,0)
BgImage::AddImage /NOUNLOAD $PLUGINSDIR\2.bmp 150 0 BgImage::AddImage $PLUGINSDIR\2.bmp 150 0
!insertmacro GetReturnValue !insertmacro GetReturnValue
# add the same image only transparent (magenta wiped) @ (150,16) # add the same image only transparent (magenta wiped) @ (150,16)
BgImage::AddImage /NOUNLOAD /TRANSPARENT 255 0 255 $PLUGINSDIR\2.bmp 150 16 BgImage::AddImage /TRANSPARENT 255 0 255 $PLUGINSDIR\2.bmp 150 16
!insertmacro GetReturnValue !insertmacro GetReturnValue
# create the font for the following text # create the font for the following text
CreateFont $R0 "Comic Sans MS" 50 700 CreateFont $R0 "Comic Sans MS" 50 700
# add a blue shadow for the text # add a blue shadow for the text
BgImage::AddText /NOUNLOAD "Testing 1... 2... 3..." $R0 0 0 255 48 48 798 198 BgImage::AddText "Testing 1... 2... 3..." $R0 0 0 255 48 48 798 198
!insertmacro GetReturnValue !insertmacro GetReturnValue
# add a green shadow for the text # add a green shadow for the text
BgImage::AddText /NOUNLOAD "Testing 1... 2... 3..." $R0 0 255 0 52 52 802 202 BgImage::AddText "Testing 1... 2... 3..." $R0 0 255 0 52 52 802 202
!insertmacro GetReturnValue !insertmacro GetReturnValue
# add the text # add the text
BgImage::AddText /NOUNLOAD "Testing 1... 2... 3..." $R0 255 0 0 50 50 800 200 BgImage::AddText "Testing 1... 2... 3..." $R0 255 0 0 50 50 800 200
!insertmacro GetReturnValue !insertmacro GetReturnValue
# show our creation to the world! # show our creation to the world!
BgImage::Redraw /NOUNLOAD BgImage::Redraw
# Refresh doesn't return any value # Refresh doesn't return any value
FunctionEnd FunctionEnd
@ -60,7 +60,7 @@ Section
StrCmp $0 "" skipSound StrCmp $0 "" skipSound
moreSounds: moreSounds:
StrCmp $1 "" noMoreSounds StrCmp $1 "" noMoreSounds
BgImage::Sound /NOUNLOAD /WAIT $WINDIR\Media\$1 BgImage::Sound /WAIT $WINDIR\Media\$1
# Sound doesn't return any value either # Sound doesn't return any value either
MessageBox MB_YESNO "Another sound?" IDNO noMoreSounds MessageBox MB_YESNO "Another sound?" IDNO noMoreSounds
FindNext $0 $1 FindNext $0 $1
@ -71,32 +71,30 @@ Section
skipSound: skipSound:
# change the background image to Mike, tiled # change the background image to Mike, tiled
BgImage::SetBg /NOUNLOAD /TILED $PLUGINSDIR\1.bmp BgImage::SetBg /TILED $PLUGINSDIR\1.bmp
!insertmacro GetReturnValue !insertmacro GetReturnValue
# we have to redraw to reflect the changes # we have to redraw to reflect the changes
BgImage::Redraw /NOUNLOAD BgImage::Redraw
MessageBox MB_OK "Mike the llama" MessageBox MB_OK "Mike the llama"
# clear everything # clear everything
BgImage::Clear /NOUNLOAD BgImage::Clear
# Clear doesn't return any value # Clear doesn't return any value
# set another gradient # set another gradient
BgImage::SetBg /NOUNLOAD /GRADIENT 0xFF 0xFA 0xBA 0xAA 0xA5 0x65 BgImage::SetBg /GRADIENT 0xFF 0xFA 0xBA 0xAA 0xA5 0x65
!insertmacro GetReturnValue !insertmacro GetReturnValue
# add some text # add some text
BgImage::AddText /NOUNLOAD "A Desert for Mike" $R0 0 0 0 50 50 800 150 BgImage::AddText "A Desert for Mike" $R0 0 0 0 50 50 800 150
!insertmacro GetReturnValue !insertmacro GetReturnValue
# add mike as an image # add mike as an image
BgImage::AddImage /NOUNLOAD $PLUGINSDIR\1.bmp 50 150 BgImage::AddImage $PLUGINSDIR\1.bmp 50 150
!insertmacro GetReturnValue !insertmacro GetReturnValue
# again, we have to call redraw to reflect changes # again, we have to call redraw to reflect changes
BgImage::Redraw /NOUNLOAD BgImage::Redraw
SectionEnd SectionEnd
Function .onGUIEnd Function .onGUIEnd
# Destroy must not have /NOUNLOAD so NSIS will be able to unload
# and delete BgImage before it exits
BgImage::Destroy BgImage::Destroy
# Destroy doesn't return any value # Destroy doesn't return any value
FunctionEnd FunctionEnd

View file

@ -1508,11 +1508,18 @@ extern "C" void __declspec(dllexport) dialog(HWND hwndParent, int string_size,
showCfgDlg(); showCfgDlg();
} }
static UINT_PTR PluginCallback(enum NSPIM msg)
{
return 0;
}
extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_size, extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop) char *variables, stack_t **stacktop,
extra_parameters *extra)
{ {
hMainWindow=hwndParent; hMainWindow=hwndParent;
EXDLL_INIT(); EXDLL_INIT();
extra->RegisterPluginCallback(m_hInstance, PluginCallback);
if (initCalled) { if (initCalled) {
pushstring("error"); pushstring("error");
return; return;

View file

@ -33,7 +33,7 @@ To set properties of the controls on the page, such as colors and fonts use Init
and Show instead of Select. Init will push the HWND of the page on the stack, and Show instead of Select. Init will push the HWND of the page on the stack,
or an error string. For example: or an error string. For example:
StartMenu::Init /NOUNLOAD "Test" StartMenu::Init "Test"
Pop $0 Pop $0
IntCmp $0 0 failed IntCmp $0 0 failed
GetDlgItem $0 $0 1003 GetDlgItem $0 $0 1003

View file

@ -29,6 +29,11 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK ParentWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK ParentWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
void AddFolderFromReg(int nFolder); void AddFolderFromReg(int nFolder);
static UINT_PTR PluginCallback(enum NSPIM msg)
{
return 0;
}
void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{ {
HWND hwStartMenuSelect; HWND hwStartMenuSelect;
@ -39,6 +44,8 @@ void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variable
EXDLL_INIT(); EXDLL_INIT();
extra->RegisterPluginCallback(g_hInstance, PluginCallback);
{ {
hwChild = GetDlgItem(hwndParent, 1018); hwChild = GetDlgItem(hwndParent, 1018);
if (!hwChild) if (!hwChild)