* 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
#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 ;)
BITMAP bm;
HINSTANCE g_hInstance;
HBITMAP g_hbm;
BITMAP bm;
int g_rv;
int resolution;
int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50,
alphaparam;
int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, alphaparam;
const TCHAR classname[4] = _T("_sp");
typedef BOOL(_stdcall * _tSetLayeredWindowAttributesProc) (HWND hwnd, // handle to the layered window
COLORREF crKey, // specifies the color key
BYTE bAlpha, // value for the blend function
DWORD dwFlags // action
);
_tSetLayeredWindowAttributesProc SetLayeredWindowAttributesProc;
typedef BOOL(WINAPI*SetLayeredWindowAttributes_T)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
SetLayeredWindowAttributes_T SetLayeredWindowAttributesProc;
#define IsLayeredWnd() ( SetLayeredWindowAttributesProc != NULL )
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
RECT r;
@ -133,8 +120,7 @@ void SetTransparentRegion(HWND myWnd)
GlobalFree(bmp_orig);
}
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call,
LPVOID lpReserved)
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
g_hInstance = hInst;
return TRUE;
@ -149,7 +135,7 @@ void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWO
if (timeleft == 0) {
timeleft = sleep_val;
state++;
if (nt50)
if (IsLayeredWnd())
call = 255;
} else {
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...
if ((call >= 0) && nt50)
SetLayeredWindowAttributesProc((HWND) dwUser, keycolor,
(BYTE) call, alphaparam);
if ((call >= 0) && IsLayeredWnd())
{
SetLayeredWindowAttributesProc((HWND) dwUser, keycolor, (BYTE) call, alphaparam);
}
// Time is running out...
timeleft--;
@ -186,8 +173,9 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
TCHAR *variables, stack_t ** stacktop)
{
DEVMODE dm;
TCHAR fn[MAX_PATH];
TCHAR fn[MAX_PATH], uselayerwnd;
TCHAR temp[64];
FARPROC slwa;
g_rv = -1;
resolution = RESOLUTION;
@ -206,10 +194,16 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
dm.dmSize = sizeof(DEVMODE);
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
nt50 = (LOBYTE(LOWORD(GetVersion())) >= 5) && !((dm.dmBitsPerPel < 32)
&& (keycolor != -1));
if (!nt50) {
uselayerwnd = slwa && dm.dmBitsPerPel >= 32 && keycolor == -1;
if (!uselayerwnd) {
// Fading+transparency is unsupported at old windows versions...
resolution = sleep_val + fadein_val + fadeout_val;
fadeout_val = fadein_val = 0;
@ -237,12 +231,13 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
wc.lpszClassName = classname;
if (RegisterClass(&wc)) {
TCHAR fn2[MAX_PATH];
lstrcpy(fn2, fn);
lstrcat(fn, _T(".bmp"));
fn2[0] = _T('\0'), lstrcat(fn2, fn);
lstrcat(fn2, _T(".wav"));
g_hbm =
LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE);
lstrcat(fn, _T(".bmp"));
g_hbm = LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE);
if (g_hbm) {
HWND myWnd;
UINT timerEvent;
@ -250,23 +245,15 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
// Get Bitmap Information
GetObject(g_hbm, sizeof(bm), & bm);
myWnd =
CreateWindowEx(WS_EX_TOOLWINDOW |
((nt50) ? (WS_EX_LAYERED) : (0)), classname,
myWnd = CreateWindowEx(WS_EX_TOOLWINDOW |
(uselayerwnd ? (WS_EX_LAYERED) : (0)), classname,
classname, 0, 0, 0, 0, 0, (HWND) hwndParent,
NULL, g_hInstance, NULL);
// Set transparency / key color
if (nt50) {
#ifndef _WIN64
// Get blending proc address
HANDLE user32 = GetModuleHandle(_T("user32"));
SetLayeredWindowAttributesProc =
(_tSetLayeredWindowAttributesProc) GetProcAddress(user32,
"SetLayeredWindowAttributes");
#else
#define SetLayeredWindowAttributesProc SetLayeredWindowAttributes
#endif
if (uselayerwnd) {
SetLayeredWindowAttributesProc = (SetLayeredWindowAttributes_T) slwa;
// Use win2k method
SetLayeredWindowAttributesProc(myWnd, keycolor,
(BYTE) ((fadein_val > 0) ? (0) : (255)),
@ -297,7 +284,7 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size,
DeleteObject(g_hbm);
}
// 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);

View file

@ -1,28 +1,26 @@
AdvSplash.dll - small (5.5k), simple plugin that lets you throw
up a splash screen in NSIS installers with cool fading effects (win2k/xp)
and transparency.
up a splash screen in NSIS installers with cool
fading effects (Win2000+) and transparency.
To use:
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:
Function .onInit
SetOutPath $TEMP
File /oname=spltmp.bmp "my_splash.bmp"
InitPluginsDir
File "/oname=$PluginsDir\spltmp.bmp" "${NSISDIR}\Contrib\Graphics\Wizard\llama.bmp"
; 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,
; '0' if everything closed normally, and '-1' if some error occurred.
Delete $TEMP\spltmp.bmp
; Delete $TEMP\spltmp.wav
FunctionEnd
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)
KeyColor - color used for transparency, could be any RGB value
(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
this parameter.bmp, and the wave file used (if present) will be this
parameter.wav.