* Checking for SetLayeredWindowAttributes is all we need, no need to check the version.

* Updated readme example


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6652 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2015-12-03 21:18:17 +00:00
parent b81aac947b
commit 7f6735532e
2 changed files with 44 additions and 59 deletions

View file

@ -11,35 +11,22 @@
# define LWA_ALPHA 2 # define LWA_ALPHA 2
#endif #endif
#if defined(_MSC_VER) && !defined(GetVersion)
#if _MSC_VER >= 1500
FORCEINLINE DWORD NoDepr_GetVersion() { __pragma(warning(push))__pragma(warning(disable:4996)) DWORD r = GetVersion(); __pragma(warning(pop)) return r; }
#define GetVersion NoDepr_GetVersion
#endif //~ _MSC_VER >= 1500
#endif //~ _MSC_VER
HINSTANCE g_hInstance;
#define RESOLUTION 32 // 30 fps ;) (32? I like SHR more than iDIV ;) #define RESOLUTION 32 // 30 fps ;) (32? I like SHR more than iDIV ;)
BITMAP bm; HINSTANCE g_hInstance;
HBITMAP g_hbm; HBITMAP g_hbm;
BITMAP bm;
int g_rv; int g_rv;
int resolution; int resolution;
int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50, int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, alphaparam;
alphaparam;
const TCHAR classname[4] = _T("_sp"); const TCHAR classname[4] = _T("_sp");
typedef BOOL(_stdcall * _tSetLayeredWindowAttributesProc) (HWND hwnd, // handle to the layered window typedef BOOL(WINAPI*SetLayeredWindowAttributes_T)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
COLORREF crKey, // specifies the color key SetLayeredWindowAttributes_T SetLayeredWindowAttributesProc;
BYTE bAlpha, // value for the blend function #define IsLayeredWnd() ( SetLayeredWindowAttributesProc != NULL )
DWORD dwFlags // action
);
_tSetLayeredWindowAttributesProc SetLayeredWindowAttributesProc;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
LPARAM lParam)
{ {
PAINTSTRUCT ps; PAINTSTRUCT ps;
RECT r; RECT r;
@ -133,8 +120,7 @@ void SetTransparentRegion(HWND myWnd)
GlobalFree(bmp_orig); GlobalFree(bmp_orig);
} }
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
LPVOID lpReserved)
{ {
g_hInstance = hInst; g_hInstance = hInst;
return TRUE; return TRUE;
@ -149,7 +135,7 @@ void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWO
if (timeleft == 0) { if (timeleft == 0) {
timeleft = sleep_val; timeleft = sleep_val;
state++; state++;
if (nt50) if (IsLayeredWnd())
call = 255; call = 255;
} else { } else {
call = ((fadein_val - timeleft) * 255) / fadein_val; call = ((fadein_val - timeleft) * 255) / fadein_val;
@ -174,9 +160,10 @@ void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWO
} }
} }
// Transparency value aquired, and could be set... // Transparency value aquired, and could be set...
if ((call >= 0) && nt50) if ((call >= 0) && IsLayeredWnd())
SetLayeredWindowAttributesProc((HWND) dwUser, keycolor, {
(BYTE) call, alphaparam); SetLayeredWindowAttributesProc((HWND) dwUser, keycolor, (BYTE) call, alphaparam);
}
// Time is running out... // Time is running out...
timeleft--; timeleft--;
@ -186,8 +173,9 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
TCHAR *variables, stack_t ** stacktop) TCHAR *variables, stack_t ** stacktop)
{ {
DEVMODE dm; DEVMODE dm;
TCHAR fn[MAX_PATH]; TCHAR fn[MAX_PATH], uselayerwnd;
TCHAR temp[64]; TCHAR temp[64];
FARPROC slwa;
g_rv = -1; g_rv = -1;
resolution = RESOLUTION; resolution = RESOLUTION;
@ -206,10 +194,16 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
dm.dmSize = sizeof(DEVMODE); dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
#ifdef _WIN64
slwa = (FARPROC) SetLayeredWindowAttributes;
#else
slwa = GetProcAddress(LoadLibraryA("USER32"), "SetLayeredWindowAttributes");
#endif
// Check for winXP/2k at 32 bpp transparency // Check for winXP/2k at 32 bpp transparency
nt50 = (LOBYTE(LOWORD(GetVersion())) >= 5) && !((dm.dmBitsPerPel < 32) uselayerwnd = slwa && dm.dmBitsPerPel >= 32 && keycolor == -1;
&& (keycolor != -1));
if (!nt50) { if (!uselayerwnd) {
// Fading+transparency is unsupported at old windows versions... // Fading+transparency is unsupported at old windows versions...
resolution = sleep_val + fadein_val + fadeout_val; resolution = sleep_val + fadein_val + fadeout_val;
fadeout_val = fadein_val = 0; fadeout_val = fadein_val = 0;
@ -237,12 +231,13 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
wc.lpszClassName = classname; wc.lpszClassName = classname;
if (RegisterClass(&wc)) { if (RegisterClass(&wc)) {
TCHAR fn2[MAX_PATH]; TCHAR fn2[MAX_PATH];
lstrcpy(fn2, fn);
lstrcat(fn, _T(".bmp")); fn2[0] = _T('\0'), lstrcat(fn2, fn);
lstrcat(fn2, _T(".wav")); lstrcat(fn2, _T(".wav"));
g_hbm = lstrcat(fn, _T(".bmp"));
LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE); g_hbm = LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE);
if (g_hbm) { if (g_hbm) {
HWND myWnd; HWND myWnd;
UINT timerEvent; UINT timerEvent;
@ -250,23 +245,15 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
// Get Bitmap Information // Get Bitmap Information
GetObject(g_hbm, sizeof(bm), & bm); GetObject(g_hbm, sizeof(bm), & bm);
myWnd = myWnd = CreateWindowEx(WS_EX_TOOLWINDOW |
CreateWindowEx(WS_EX_TOOLWINDOW | (uselayerwnd ? (WS_EX_LAYERED) : (0)), classname,
((nt50) ? (WS_EX_LAYERED) : (0)), classname,
classname, 0, 0, 0, 0, 0, (HWND) hwndParent, classname, 0, 0, 0, 0, 0, (HWND) hwndParent,
NULL, g_hInstance, NULL); NULL, g_hInstance, NULL);
// Set transparency / key color // Set transparency / key color
if (nt50) { if (uselayerwnd) {
#ifndef _WIN64 SetLayeredWindowAttributesProc = (SetLayeredWindowAttributes_T) slwa;
// Get blending proc address
HANDLE user32 = GetModuleHandle(_T("user32"));
SetLayeredWindowAttributesProc =
(_tSetLayeredWindowAttributesProc) GetProcAddress(user32,
"SetLayeredWindowAttributes");
#else
#define SetLayeredWindowAttributesProc SetLayeredWindowAttributes
#endif
// Use win2k method // Use win2k method
SetLayeredWindowAttributesProc(myWnd, keycolor, SetLayeredWindowAttributesProc(myWnd, keycolor,
(BYTE) ((fadein_val > 0) ? (0) : (255)), (BYTE) ((fadein_val > 0) ? (0) : (255)),
@ -297,7 +284,7 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
DeleteObject(g_hbm); DeleteObject(g_hbm);
} }
// We should UnRegister class, since Windows NT series never does this by itself // We should UnRegister class, since Windows NT series never does this by itself
UnregisterClass(wc.lpszClassName, g_hInstance); UnregisterClass(wc.lpszClassName, wc.hInstance);
} }
} }
wsprintf(temp, _T("%d"), g_rv); wsprintf(temp, _T("%d"), g_rv);

View file

@ -1,28 +1,26 @@
AdvSplash.dll - small (5.5k), simple plugin that lets you throw AdvSplash.dll - small (5.5k), simple plugin that lets you throw
up a splash screen in NSIS installers with cool fading effects (win2k/xp) up a splash screen in NSIS installers with cool
and transparency. fading effects (Win2000+) and transparency.
To use: To use:
Create a .BMP file of your splash screen. Create a .BMP file of your splash screen.
(optional) Create a .WAV file to play while your splash screen shows. Create a .WAV file to play while your splash screen shows. (optional)
Add the following lines to your .NSI file: Add the following lines to your .NSI file:
Function .onInit Function .onInit
SetOutPath $TEMP InitPluginsDir
File /oname=spltmp.bmp "my_splash.bmp" File "/oname=$PluginsDir\spltmp.bmp" "${NSISDIR}\Contrib\Graphics\Wizard\llama.bmp"
; optional ; optional
; File /oname=spltmp.wav "my_splashsound.wav" ; File /oname=$PluginsDir\spltmp.wav "my_splashsound.wav"
advsplash::show 1000 600 400 -1 $TEMP\spltmp advsplash::show 1000 600 400 -1 $PluginsDir\spltmp
Pop $0 ; $0 has '1' if the user closed the splash screen early, Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normally, and '-1' if some error occurred. ; '0' if everything closed normally, and '-1' if some error occurred.
Delete $TEMP\spltmp.bmp
; Delete $TEMP\spltmp.wav
FunctionEnd FunctionEnd
Calling format Calling format
@ -33,7 +31,7 @@ FadeIn - length to show the fadein scene (in ms) (not included in Delay)
FadeOut - length to show the fadeout scene (in ms) (not included in Delay) FadeOut - length to show the fadeout scene (in ms) (not included in Delay)
KeyColor - color used for transparency, could be any RGB value KeyColor - color used for transparency, could be any RGB value
(for ex. R=255 G=100 B=16 -> KeyColor=0xFF6410), (for ex. R=255 G=100 B=16 -> KeyColor=0xFF6410),
use KeyColor=-1 if there is no transparent color at your image. use KeyColor=-1 if there is no transparent color in your image.
FileName - splash bitmap filename (without the .bmp). The BMP file used will be FileName - splash bitmap filename (without the .bmp). The BMP file used will be
this parameter.bmp, and the wave file used (if present) will be this this parameter.bmp, and the wave file used (if present) will be this
parameter.wav. parameter.wav.