From 204ad0ad157f9046f2a6fcf8e13ea0747a60f7d6 Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 8 Nov 2002 20:41:47 +0000 Subject: [PATCH] Persistent background image plugin git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1627 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/BgImage/BgImage.cpp | 213 ++++++++++++++++++++++++++++++++++++ Contrib/BgImage/BgImage.dsp | 78 +++++++++++++ Contrib/BgImage/BgImage.dsw | 29 +++++ Contrib/BgImage/BgImage.txt | 35 ++++++ Contrib/BgImage/exdll.h | 49 +++++++++ Plugins/BgImage.dll | Bin 0 -> 4608 bytes 6 files changed, 404 insertions(+) create mode 100644 Contrib/BgImage/BgImage.cpp create mode 100644 Contrib/BgImage/BgImage.dsp create mode 100644 Contrib/BgImage/BgImage.dsw create mode 100644 Contrib/BgImage/BgImage.txt create mode 100644 Contrib/BgImage/exdll.h create mode 100644 Plugins/BgImage.dll diff --git a/Contrib/BgImage/BgImage.cpp b/Contrib/BgImage/BgImage.cpp new file mode 100644 index 00000000..03fc9b07 --- /dev/null +++ b/Contrib/BgImage/BgImage.cpp @@ -0,0 +1,213 @@ +#include +#include +#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; +} \ No newline at end of file diff --git a/Contrib/BgImage/BgImage.dsp b/Contrib/BgImage/BgImage.dsp new file mode 100644 index 00000000..662b6832 --- /dev/null +++ b/Contrib/BgImage/BgImage.dsp @@ -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 diff --git a/Contrib/BgImage/BgImage.dsw b/Contrib/BgImage/BgImage.dsw new file mode 100644 index 00000000..8a22263c --- /dev/null +++ b/Contrib/BgImage/BgImage.dsw @@ -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> +{{{ +}}} + +############################################################################### + diff --git a/Contrib/BgImage/BgImage.txt b/Contrib/BgImage/BgImage.txt new file mode 100644 index 00000000..14cc3e56 --- /dev/null +++ b/Contrib/BgImage/BgImage.txt @@ -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 \ No newline at end of file diff --git a/Contrib/BgImage/exdll.h b/Contrib/BgImage/exdll.h new file mode 100644 index 00000000..5ecbd013 --- /dev/null +++ b/Contrib/BgImage/exdll.h @@ -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_ \ No newline at end of file diff --git a/Plugins/BgImage.dll b/Plugins/BgImage.dll new file mode 100644 index 0000000000000000000000000000000000000000..c4343d9c7855cb011924d69274c35f1f793c450d GIT binary patch literal 4608 zcmeHKU2GiH6+WAo#2DLb(_O_hO*^hFm15$|kGBmtsW$dbY}2(fc*t%@oRIbI#NK7R zYprL91Eq@OSYJVcp( zcV^dhT9F4{(pI_lxA&g&opbKFXU>dfy7xUzYl)}=a2%o&nAr%szt{gc2fFsFZ`aZr zw|-E6!WaFZ{(-^t2sfP14dfF;Tr!c(<_xZ1v|73G?=>Gj%8C$K)SPHDf-v>t%QDO(zGL&%bA=$V5?J1r61o z-BIQ)P;LEfzI84 zN0egpXN@q?JD9On$Cu=69Es7!w(B3W=0-@t8Vz45AYpMwHgm zg+cIU%^(`rU)+d{A6($<&;#J&nI*-UA7t5Qt~jCZ3fN}8U|@Ra;Qse#-D=d?a-~{e zlr2}s;)N8V*mB_1Fy_K2)bXN?yJ4=PF$zuG3Eqvsc8DDSNBXk#vFglcd$<}7ZP98(B)>&gcDpvvT435lL@8D`&b%J52TW1T*5a-#(LUp*I zzBkcbygyS1Pu#`+Nfxek)~vMUMR#Mnh6QT;HL5X>GeeT~B>XF%Y}c6Q!={5dSgiZ#ZjvEsLGAAi9m z0%M(Ze!GTUf2*@%!JLqP6<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