indent -nut -kr -bli0 -i2

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3847 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2005-01-08 13:30:33 +00:00
parent c6dc4d76fe
commit 3b5782aa07

View file

@ -13,155 +13,165 @@ BITMAP bm;
HBITMAP g_hbm; HBITMAP g_hbm;
int g_rv; int g_rv;
int resolution; int resolution;
int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50, alphaparam; int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50,
const char classname[4]="_sp"; alphaparam;
const char classname[4] = "_sp";
typedef BOOL (_stdcall *_tSetLayeredWindowAttributesProc)(HWND hwnd, // handle to the layered window typedef BOOL(_stdcall * _tSetLayeredWindowAttributesProc) (HWND hwnd, // handle to the layered window
COLORREF crKey, // specifies the color key COLORREF crKey, // specifies the color key
BYTE bAlpha, // value for the blend function BYTE bAlpha, // value for the blend function
DWORD dwFlags // action DWORD dwFlags // action
); );
_tSetLayeredWindowAttributesProc SetLayeredWindowAttributesProc; _tSetLayeredWindowAttributesProc SetLayeredWindowAttributesProc;
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; PAINTSTRUCT ps;
RECT r; RECT r;
HDC curdc = NULL; HDC curdc = NULL;
HDC hdc; HDC hdc;
HBITMAP oldbm; HBITMAP oldbm;
switch (uMsg) switch (uMsg) {
{ case WM_CREATE:
case WM_CREATE: SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); SetWindowLong(hwnd, GWL_STYLE, 0);
SetWindowLong(hwnd,GWL_STYLE,0); SetWindowPos(hwnd, NULL,
SetWindowPos(hwnd,NULL, r.left + (r.right - r.left - bm.bmWidth) / 2,
r.left+(r.right-r.left-bm.bmWidth)/2, r.top + (r.bottom - r.top - bm.bmHeight) / 2,
r.top+(r.bottom-r.top-bm.bmHeight)/2, bm.bmWidth, bm.bmHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
bm.bmWidth,bm.bmHeight, return 0;
SWP_NOZORDER | SWP_SHOWWINDOW);
return 0;
case WM_PAINT: case WM_PAINT:
curdc=BeginPaint(hwnd,&ps); curdc = BeginPaint(hwnd, &ps);
hdc=CreateCompatibleDC(curdc); hdc = CreateCompatibleDC(curdc);
GetClientRect(hwnd,&r); GetClientRect(hwnd, &r);
oldbm = SelectObject(hdc, g_hbm); oldbm = SelectObject(hdc, g_hbm);
BitBlt(curdc,r.left,r.top,r.right-r.left,r.bottom-r.top,hdc,0,0, SRCCOPY); BitBlt(curdc, r.left, r.top, r.right - r.left, r.bottom - r.top, hdc,
0, 0, SRCCOPY);
SelectObject(hdc,oldbm);
DeleteDC(hdc);
EndPaint(hwnd,&ps);
case WM_CLOSE: SelectObject(hdc, oldbm);
return 0; DeleteDC(hdc);
EndPaint(hwnd, &ps);
case WM_TIMER: case WM_CLOSE:
case WM_LBUTTONDOWN: return 0;
g_rv=(uMsg == WM_LBUTTONDOWN);
DestroyWindow(hwnd); case WM_TIMER:
break; case WM_LBUTTONDOWN:
} g_rv = (uMsg == WM_LBUTTONDOWN);
return DefWindowProc(hwnd,uMsg,wParam,lParam); DestroyWindow(hwnd);
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
} }
void SetTransparentRegion(HWND myWnd) void SetTransparentRegion(HWND myWnd)
{ {
HDC dc; HDC dc;
int x, y; int x, y;
HRGN region, cutrgn; HRGN region, cutrgn;
BITMAPINFO bmi; BITMAPINFO bmi;
int size = bm.bmWidth * bm.bmHeight*4; int size = bm.bmWidth * bm.bmHeight * 4;
int *bmp = GlobalAlloc(GPTR, size); int *bmp = GlobalAlloc(GPTR, size);
bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = bm.bmHeight; bmi.bmiHeader.biHeight = bm.bmHeight;
bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = bm.bmWidth; bmi.bmiHeader.biWidth = bm.bmWidth;
bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0; bmi.bmiHeader.biClrImportant = 0;
dc = CreateCompatibleDC(NULL); dc = CreateCompatibleDC(NULL);
SelectObject(dc, g_hbm); SelectObject(dc, g_hbm);
x = GetDIBits(dc, g_hbm, 0, bm.bmHeight, bmp, &bmi, DIB_RGB_COLORS); x = GetDIBits(dc, g_hbm, 0, bm.bmHeight, bmp, &bmi, DIB_RGB_COLORS);
region = CreateRectRgn(0,0,bm.bmWidth,bm.bmHeight); region = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight);
// Search for transparent pixels // Search for transparent pixels
for (y = bm.bmHeight-1; y >= 0; y--) for (y = bm.bmHeight - 1; y >= 0; y--) {
for (x = 0; x < bm.bmWidth; ) for (x = 0; x < bm.bmWidth;) {
if ((*bmp & 0xFFFFFF) == keycolor) if ((*bmp & 0xFFFFFF) == keycolor) {
{ int j = x;
int j = x; while ((x < bm.bmWidth) && ((*bmp & 0xFFFFFF) == keycolor)) {
while ((x < bm.bmWidth) && ((*bmp & 0xFFFFFF) == keycolor)) bmp++, x++; bmp++, x++;
// Cut transparent pixels from the original region
cutrgn = CreateRectRgn(j, y, x, y+1);
CombineRgn(region, region, cutrgn, RGN_XOR);
DeleteObject(cutrgn);
} else bmp++, x++;
// Set resulting region.
SetWindowRgn(myWnd, region, TRUE);
DeleteObject(region);
DeleteObject(dc);
GlobalFree(bmp);
}
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
g_hInstance=hInst;
return TRUE;
}
void CALLBACK TimeProc(
UINT uID,
UINT uMsg,
DWORD dwUser,
DWORD dw1,
DWORD dw2)
{
int call = -1;
switch (state)
{
// FadeIN
case 0: if (timeleft == 0)
{
timeleft = sleep_val;
state++;
if (nt50) call = 255;
} else { call = ((fadein_val-timeleft)*255)/fadein_val; break; }
// Sleep
case 1: if (timeleft == 0)
{
timeleft = fadeout_val;
state++;
// fadeout
} else break;
// FadeOUT
case 2: if (timeleft == 0)
{
PostMessage((HWND)dwUser, WM_TIMER, 0, 0);
return;
} else { call = ((timeleft)*255)/fadeout_val; break; }
} }
// Transparency value aquired, and could be set...
if ((call >= 0) && nt50) // Cut transparent pixels from the original region
SetLayeredWindowAttributesProc((HWND)dwUser, keycolor, cutrgn = CreateRectRgn(j, y, x, y + 1);
call, CombineRgn(region, region, cutrgn, RGN_XOR);
alphaparam); DeleteObject(cutrgn);
} else {
// Time is running out... bmp++, x++;
timeleft--; }
}
}
// Set resulting region.
SetWindowRgn(myWnd, region, TRUE);
DeleteObject(region);
DeleteObject(dc);
GlobalFree(bmp);
}
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call,
LPVOID lpReserved)
{
g_hInstance = hInst;
return TRUE;
}
void CALLBACK TimeProc(UINT uID,
UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
int call = -1;
switch (state) {
// FadeIN
case 0:
if (timeleft == 0) {
timeleft = sleep_val;
state++;
if (nt50)
call = 255;
} else {
call = ((fadein_val - timeleft) * 255) / fadein_val;
break;
}
// Sleep
case 1:
if (timeleft == 0) {
timeleft = fadeout_val;
state++;
// fadeout
} else
break;
// FadeOUT
case 2:
if (timeleft == 0) {
PostMessage((HWND) dwUser, WM_TIMER, 0, 0);
return;
} else {
call = ((timeleft) * 255) / fadeout_val;
break;
}
}
// Transparency value aquired, and could be set...
if ((call >= 0) && nt50)
SetLayeredWindowAttributesProc((HWND) dwUser, keycolor,
call, alphaparam);
// Time is running out...
timeleft--;
} }
int myatoi(char *s); int myatoi(char *s);
void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) void __declspec(dllexport) show(HWND hwndParent, int string_size,
char *variables, stack_t ** stacktop)
{ {
DEVMODE dm; DEVMODE dm;
char fn[MAX_PATH]; char fn[MAX_PATH];
@ -185,136 +195,142 @@ void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variable
dm.dmSize = sizeof(DEVMODE); dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
// Check for winXP/2k at 32 bpp transparency // Check for winXP/2k at 32 bpp transparency
nt50 = (LOBYTE(LOWORD(GetVersion())) >= 5) && !((dm.dmBitsPerPel < 32) && (keycolor != -1)); nt50 = (LOBYTE(LOWORD(GetVersion())) >= 5) && !((dm.dmBitsPerPel < 32)
if (!nt50) && (keycolor != -1));
{ if (!nt50) {
// 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;
sleep_val = 1; sleep_val = 1;
} else } else {
{ // div them by resolution
// div them by resolution sleep_val >>= 5;
sleep_val >>= 5; fadein_val >>= 5;
fadein_val >>= 5; fadeout_val >>= 5;
fadeout_val >>= 5;
alphaparam = LWA_ALPHA | ((keycolor == -1)?(0):(LWA_COLORKEY)); alphaparam = LWA_ALPHA | ((keycolor == -1) ? (0) : (LWA_COLORKEY));
keycolor = ((keycolor & 0xFF) << 16) + (keycolor & 0xFF00) + ((keycolor & 0xFF0000) >> 16); keycolor =
((keycolor & 0xFF) << 16) + (keycolor & 0xFF00) +
((keycolor & 0xFF0000) >> 16);
} }
if (fn[0] && ((sleep_val+fadein_val+fadeout_val)>0)) if (fn[0] && ((sleep_val + fadein_val + fadeout_val) > 0)) {
{
MSG msg; MSG msg;
static WNDCLASS wc; static WNDCLASS wc;
wc.lpfnWndProc = WndProc; wc.lpfnWndProc = WndProc;
wc.hInstance = g_hInstance; wc.hInstance = g_hInstance;
wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = classname; wc.lpszClassName = classname;
if (RegisterClass(&wc)) if (RegisterClass(&wc)) {
{
char fn2[MAX_PATH]; char fn2[MAX_PATH];
lstrcpy(fn2,fn); lstrcpy(fn2, fn);
lstrcat(fn,".bmp"); lstrcat(fn, ".bmp");
lstrcat(fn2,".wav"); lstrcat(fn2, ".wav");
g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE); g_hbm =
if (g_hbm) LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0,
{ LR_CREATEDIBSECTION | LR_LOADFROMFILE);
HWND myWnd; if (g_hbm) {
UINT timerEvent; HWND myWnd;
UINT timerEvent;
// Get Bitmap Information // Get Bitmap Information
GetObject(g_hbm, sizeof(bm), (LPSTR)&bm); GetObject(g_hbm, sizeof(bm), (LPSTR) & bm);
myWnd = CreateWindowEx(WS_EX_TOOLWINDOW | ((nt50)?(WS_EX_LAYERED):(0)),classname,classname, myWnd =
0,0,0,0,0,(HWND)hwndParent,NULL,g_hInstance,NULL); CreateWindowEx(WS_EX_TOOLWINDOW |
((nt50) ? (WS_EX_LAYERED) : (0)), classname,
classname, 0, 0, 0, 0, 0, (HWND) hwndParent,
NULL, g_hInstance, NULL);
// Set transparency / key color // Set transparency / key color
if (nt50) if (nt50) {
{ // Get blending proc address
// Get blending proc address HANDLE user32 = GetModuleHandle("user32");
HANDLE user32 = GetModuleHandle("user32"); SetLayeredWindowAttributesProc =
SetLayeredWindowAttributesProc = (_tSetLayeredWindowAttributesProc) GetProcAddress(user32, "SetLayeredWindowAttributes"); (_tSetLayeredWindowAttributesProc) GetProcAddress(user32,
// Use win2k method "SetLayeredWindowAttributes");
SetLayeredWindowAttributesProc(myWnd, keycolor, // Use win2k method
(fadein_val > 0)?(0):(255), SetLayeredWindowAttributesProc(myWnd, keycolor,
alphaparam); (fadein_val > 0) ? (0) : (255),
} else alphaparam);
if (keycolor != -1) } else if (keycolor != -1) {
{ // transparency mode
// transparency mode SetTransparentRegion(myWnd);
SetTransparentRegion(myWnd); }
}
PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME|SND_NODEFAULT);
// Start up timer... PlaySound(fn2, NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
state = 0; timeleft = fadein_val;
timerEvent = timeSetEvent(resolution, RESOLUTION/4, TimeProc, (DWORD_PTR)myWnd, TIME_PERIODIC);
while (IsWindow(myWnd) && GetMessage(&msg,myWnd,0,0)) // Start up timer...
{ state = 0;
timeleft = fadein_val;
timerEvent =
timeSetEvent(resolution, RESOLUTION / 4, TimeProc,
(DWORD_PTR) myWnd, TIME_PERIODIC);
while (IsWindow(myWnd) && GetMessage(&msg, myWnd, 0, 0)) {
DispatchMessage(&msg); DispatchMessage(&msg);
} }
// Kill the timer... // Kill the timer...
timeKillEvent(timerEvent); timeKillEvent(timerEvent);
// Stop currently playing wave, we want to exit // Stop currently playing wave, we want to exit
PlaySound(0,0,0); PlaySound(0, 0, 0);
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, g_hInstance);
} }
} }
wsprintf(temp,"%d",g_rv); wsprintf(temp, "%d", g_rv);
pushstring(temp); pushstring(temp);
} }
int myatoi(char *s) int myatoi(char *s)
{ {
unsigned int v=0; unsigned int v = 0;
if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) {
{ s += 2;
s+=2; for (;;) {
for (;;) int c = *s++;
{ if (c >= '0' && c <= '9')
int c=*s++; c -= '0';
if (c >= '0' && c <= '9') c-='0'; else if (c >= 'a' && c <= 'f')
else if (c >= 'a' && c <= 'f') c-='a'-10; c -= 'a' - 10;
else if (c >= 'A' && c <= 'F') c-='A'-10; else if (c >= 'A' && c <= 'F')
else break; c -= 'A' - 10;
v<<=4; else
v+=c; break;
v <<= 4;
v += c;
} }
} } else if (*s == '0' && s[1] <= '7' && s[1] >= '0') {
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
{
s++; s++;
for (;;) for (;;) {
{ int c = *s++;
int c=*s++; if (c >= '0' && c <= '7')
if (c >= '0' && c <= '7') c-='0'; c -= '0';
else break; else
v<<=3; break;
v+=c; v <<= 3;
v += c;
} }
} } else {
else int sign = 0;
{ if (*s == '-') {
int sign=0; s++;
if (*s == '-') { s++; sign++; } sign++;
for (;;)
{
int c=*s++ - '0';
if (c < 0 || c > 9) break;
v*=10;
v+=c;
} }
if (sign) return -(int) v; for (;;) {
int c = *s++ - '0';
if (c < 0 || c > 9)
break;
v *= 10;
v += c;
}
if (sign)
return -(int) v;
} }
return (int)v; return (int) v;
} }