Persistent background image plugin
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1627 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
b2261023af
commit
204ad0ad15
6 changed files with 404 additions and 0 deletions
213
Contrib/BgImage/BgImage.cpp
Normal file
213
Contrib/BgImage/BgImage.cpp
Normal file
|
@ -0,0 +1,213 @@
|
|||
#include <Windows.h>
|
||||
#include <Mmsystem.h>
|
||||
#include "exdll.h"
|
||||
|
||||
int x, y;
|
||||
char temp[MAX_PATH];
|
||||
HBITMAP hBitmap;
|
||||
HWND hWndImage;
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
|
||||
void *oldProc;
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
int myatoi(char *s);
|
||||
extern "C" void __declspec(dllexport) SetImage(HWND hwndParent, int string_size, char *variables, stack_t **stacktop);
|
||||
|
||||
extern "C" void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
SetImage(hwndParent, string_size, variables, stacktop);
|
||||
|
||||
WNDCLASSEX wc = {
|
||||
sizeof(WNDCLASSEX),
|
||||
CS_VREDRAW|CS_HREDRAW,
|
||||
WndProc,
|
||||
0,
|
||||
0,
|
||||
g_hInstance,
|
||||
LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(103)),
|
||||
0,
|
||||
(HBRUSH)GetStockObject(WHITE_BRUSH),
|
||||
0,
|
||||
"NSISBGImage",
|
||||
0
|
||||
};
|
||||
if (!RegisterClassEx(&wc)) {
|
||||
pushstring("can't register class");
|
||||
return;
|
||||
}
|
||||
|
||||
hWndImage = CreateWindowEx(
|
||||
WS_EX_TOOLWINDOW,
|
||||
"NSISBGImage",
|
||||
0,
|
||||
WS_VISIBLE,
|
||||
(GetSystemMetrics(SM_CXSCREEN)-x)/2,
|
||||
(GetSystemMetrics(SM_CYSCREEN)-y)/2,
|
||||
x,
|
||||
y,
|
||||
0,
|
||||
0,
|
||||
g_hInstance,
|
||||
0
|
||||
);
|
||||
if (!hWndImage) {
|
||||
pushstring("can't create window");
|
||||
return;
|
||||
}
|
||||
|
||||
SetWindowLong(hWndImage, GWL_STYLE, WS_VISIBLE);
|
||||
|
||||
oldProc = (void *)SetWindowLong(g_hwndParent, GWL_WNDPROC, (long)WndProc);
|
||||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) SetImage(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
EXDLL_INIT();
|
||||
|
||||
popstring(temp);
|
||||
if (!lstrcmp(temp, "/FILLSCREEN")) {
|
||||
x = GetSystemMetrics(SM_CXSCREEN);
|
||||
y = GetSystemMetrics(SM_CYSCREEN);
|
||||
popstring(temp);
|
||||
}
|
||||
else x = y = 0;
|
||||
|
||||
BITMAP bitmap;
|
||||
|
||||
if (hBitmap) DeleteObject((HGDIOBJ)hBitmap);
|
||||
hBitmap = (HBITMAP)LoadImage(0, temp, IMAGE_BITMAP, x, y, LR_LOADFROMFILE);
|
||||
if (!hBitmap) {
|
||||
pushstring("can't load bitmap");
|
||||
return;
|
||||
}
|
||||
|
||||
GetObject(hBitmap, sizeof(bitmap), (LPSTR)&bitmap);
|
||||
x = x ? x : bitmap.bmWidth;
|
||||
y = y ? y : bitmap.bmHeight;
|
||||
|
||||
if (hWndImage) {
|
||||
SetWindowPos(
|
||||
hWndImage,
|
||||
g_hwndParent,
|
||||
(GetSystemMetrics(SM_CXSCREEN)-x)/2,
|
||||
(GetSystemMetrics(SM_CYSCREEN)-y)/2,
|
||||
x,
|
||||
y,
|
||||
SWP_NOACTIVATE
|
||||
);
|
||||
RedrawWindow(hWndImage, 0, 0, RDW_INVALIDATE);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) Destroy(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
SendMessage(hWndImage, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) Sound(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
g_stacktop=stacktop;
|
||||
popstring(temp);
|
||||
PlaySound(temp, 0, SND_ASYNC|SND_FILENAME|SND_NODEFAULT);
|
||||
}
|
||||
|
||||
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||
g_hInstance=hInst;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int myatoi(char *s)
|
||||
{
|
||||
unsigned int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
{
|
||||
s+=2;
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
{
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int sign=0;
|
||||
if (*s == '-') { s++; sign++; }
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++ - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
if (sign) return -(int) v;
|
||||
}
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
if (hWndImage && hwnd != hWndImage) {
|
||||
if (message == WM_WINDOWPOSCHANGED) {
|
||||
LPWINDOWPOS wp = (LPWINDOWPOS) lParam;
|
||||
if (!(wp->flags & SWP_NOZORDER)) {
|
||||
CallWindowProc(
|
||||
(long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))oldProc,
|
||||
hwnd,
|
||||
message,
|
||||
wParam,
|
||||
lParam
|
||||
);
|
||||
SetWindowPos(hWndImage, g_hwndParent, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return CallWindowProc(
|
||||
(long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))oldProc,
|
||||
hwnd,
|
||||
message,
|
||||
wParam,
|
||||
lParam
|
||||
);
|
||||
}
|
||||
switch (message) {
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hwnd, &ps);
|
||||
HDC cdc = CreateCompatibleDC(hdc);
|
||||
HGDIOBJ hOldObject = SelectObject(cdc, hBitmap);
|
||||
RECT cRect;
|
||||
GetClientRect(hwnd, &cRect);
|
||||
BitBlt(hdc, cRect.left, cRect.top, cRect.right - cRect.left, cRect.bottom - cRect.top, cdc, 0, 0, SRCCOPY);
|
||||
SelectObject(cdc, hOldObject);
|
||||
DeleteDC(cdc);
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_WINDOWPOSCHANGING:
|
||||
{
|
||||
LPWINDOWPOS wp = (LPWINDOWPOS) lParam;
|
||||
wp->flags |= SWP_NOACTIVATE;
|
||||
wp->hwndInsertAfter = g_hwndParent;
|
||||
break;
|
||||
}
|
||||
case WM_DESTROY:
|
||||
SetWindowLong(g_hwndParent, GWL_WNDPROC, (long)oldProc);
|
||||
default:
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
78
Contrib/BgImage/BgImage.dsp
Normal file
78
Contrib/BgImage/BgImage.dsp
Normal file
|
@ -0,0 +1,78 @@
|
|||
# Microsoft Developer Studio Project File - Name="BgImage" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=BgImage - WIN32 RELEASE
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "BgImage.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "BgImage.mak" CFG="BgImage - WIN32 RELEASE"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "BgImage - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BgImage_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "WIN32_LEAN_AND_MEAN" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BgImage_EXPORTS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib winmm.lib gdi32.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /opt:nowin98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Target
|
||||
|
||||
# Name "BgImage - Win32 Release"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BgImage.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\exdll.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
29
Contrib/BgImage/BgImage.dsw
Normal file
29
Contrib/BgImage/BgImage.dsw
Normal file
|
@ -0,0 +1,29 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "BgImage"=".\BgImage.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
35
Contrib/BgImage/BgImage.txt
Normal file
35
Contrib/BgImage/BgImage.txt
Normal file
|
@ -0,0 +1,35 @@
|
|||
BgImage.DLL - NSIS extension DLL
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Displays an image behind the NSIS window.
|
||||
Can also play WAVs.
|
||||
|
||||
Note
|
||||
~~~~
|
||||
|
||||
All but the last used function (which should be Destroy) must use /NOUNLOAD so the image window won't be destroyed before it should. Therefore, this DLL requires NSIS 2.0a7 and above.
|
||||
|
||||
Available functions
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Init path_to_bitmap [/FILLSCREEN]
|
||||
Create a new image window
|
||||
Use /FILLSCREEN to make the image fill the screen
|
||||
Do not use in .onInit!
|
||||
|
||||
SetImage path_to_bitmap [/FILLSCREEN]
|
||||
Sets a new image to the current timage window
|
||||
Use /FILLSCREEN to make the image fill the screen
|
||||
Do not use in .onInit!
|
||||
|
||||
Destroy
|
||||
Destroys the current image window
|
||||
|
||||
Sound path_to_wav [/WAIT]
|
||||
Plays a wave file
|
||||
Use /WAIT to wait for the sound to finish playing
|
||||
|
||||
Credits
|
||||
~~~~~~~
|
||||
|
||||
Coded by Amir Szekely, aka KiCHiK
|
49
Contrib/BgImage/exdll.h
Normal file
49
Contrib/BgImage/exdll.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef _EXDLL_H_
|
||||
#define _EXDLL_H_
|
||||
|
||||
// only include this file from one place in your DLL.
|
||||
// (it is all static, if you use it in two places it will fail)
|
||||
|
||||
#define EXDLL_INIT() { \
|
||||
g_hwndParent=hwndParent; \
|
||||
g_stringsize=string_size; \
|
||||
g_stacktop=stacktop; \
|
||||
/*g_variables=variables;*/ }
|
||||
|
||||
|
||||
typedef struct _stack_t {
|
||||
struct _stack_t *next;
|
||||
char text[1]; // this should be the length of string_size
|
||||
} stack_t;
|
||||
|
||||
|
||||
static int g_stringsize;
|
||||
static stack_t **g_stacktop;
|
||||
static HWND g_hwndParent;
|
||||
|
||||
static int popstring(char *str); // 0 on success, 1 on empty stack
|
||||
static void pushstring(char *str);
|
||||
|
||||
// utility functions (not required but often useful)
|
||||
static int popstring(char *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop || !*g_stacktop) return 1;
|
||||
th=(*g_stacktop);
|
||||
lstrcpy(str,th->text);
|
||||
*g_stacktop = th->next;
|
||||
GlobalFree((HGLOBAL)th);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pushstring(char *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return;
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
||||
lstrcpyn(th->text,str,g_stringsize);
|
||||
th->next=*g_stacktop;
|
||||
*g_stacktop=th;
|
||||
}
|
||||
|
||||
#endif//_EXDLL_H_
|
BIN
Plugins/BgImage.dll
Normal file
BIN
Plugins/BgImage.dll
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue