2002-10-02 19:54:16 +00:00
|
|
|
// For layered windows
|
|
|
|
#define _WIN32_WINNT 0x0500
|
|
|
|
|
|
|
|
#include <windows.h>
|
2003-09-12 14:01:29 +00:00
|
|
|
#include <windowsx.h>
|
|
|
|
#include "..\exdll\exdll.h"
|
2002-10-02 19:54:16 +00:00
|
|
|
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
#define RESOLUTION 32 // 30 fps ;) (32? I like SHR more than iDIV ;)
|
2002-10-02 19:54:16 +00:00
|
|
|
|
|
|
|
BITMAP bm;
|
|
|
|
HBITMAP g_hbm;
|
2003-09-12 14:01:29 +00:00
|
|
|
int g_rv;
|
|
|
|
int resolution;
|
2002-10-02 19:54:16 +00:00
|
|
|
int sleep_val, fadein_val, fadeout_val, state, timeleft, keycolor, nt50, alphaparam;
|
2003-09-12 14:01:29 +00:00
|
|
|
const char classname[4]="_sp";
|
2002-10-02 19:54:16 +00:00
|
|
|
|
2002-11-19 15:54:03 +00:00
|
|
|
typedef BOOL (_stdcall *_tSetLayeredWindowAttributesProc)(HWND hwnd, // handle to the layered window
|
2002-10-02 19:54:16 +00:00
|
|
|
COLORREF crKey, // specifies the color key
|
|
|
|
BYTE bAlpha, // value for the blend function
|
|
|
|
DWORD dwFlags // action
|
|
|
|
);
|
2002-11-19 15:54:03 +00:00
|
|
|
_tSetLayeredWindowAttributesProc SetLayeredWindowAttributesProc;
|
|
|
|
|
2002-10-02 19:54:16 +00:00
|
|
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT r;
|
2003-09-12 14:01:29 +00:00
|
|
|
HDC curdc = NULL;
|
|
|
|
HDC hdc;
|
2002-10-02 19:54:16 +00:00
|
|
|
HBITMAP oldbm;
|
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_CREATE:
|
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
|
|
|
|
SetWindowLong(hwnd,GWL_STYLE,0);
|
|
|
|
SetWindowPos(hwnd,NULL,
|
|
|
|
r.left+(r.right-r.left-bm.bmWidth)/2,
|
|
|
|
r.top+(r.bottom-r.top-bm.bmHeight)/2,
|
|
|
|
bm.bmWidth,bm.bmHeight,
|
|
|
|
SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
curdc=BeginPaint(hwnd,&ps);
|
|
|
|
hdc=CreateCompatibleDC(curdc);
|
|
|
|
GetClientRect(hwnd,&r);
|
|
|
|
|
|
|
|
oldbm = SelectObject(hdc, g_hbm);
|
|
|
|
BitBlt(curdc,r.left,r.top,r.right-r.left,r.bottom-r.top,hdc,0,0, SRCCOPY);
|
2002-10-02 19:54:16 +00:00
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
SelectObject(hdc,oldbm);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
EndPaint(hwnd,&ps);
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
g_rv=(uMsg == WM_LBUTTONDOWN);
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DefWindowProc(hwnd,uMsg,wParam,lParam);
|
2002-10-02 19:54:16 +00:00
|
|
|
}
|
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
void SetTransparentRegion(HWND myWnd)
|
2002-10-02 19:54:16 +00:00
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
HDC dc;
|
|
|
|
int x, y;
|
|
|
|
HRGN region, cutrgn;
|
|
|
|
BITMAPINFO bmi;
|
|
|
|
int size = bm.bmWidth * bm.bmHeight*4;
|
|
|
|
int *bmp = GlobalAlloc(GPTR, size);
|
|
|
|
bmi.bmiHeader.biBitCount = 32;
|
|
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
bmi.bmiHeader.biHeight = bm.bmHeight;
|
|
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmi.bmiHeader.biWidth = bm.bmWidth;
|
|
|
|
bmi.bmiHeader.biClrUsed = 0;
|
|
|
|
bmi.bmiHeader.biClrImportant = 0;
|
|
|
|
|
|
|
|
dc = CreateCompatibleDC(NULL);
|
|
|
|
SelectObject(dc, g_hbm);
|
|
|
|
|
|
|
|
x = GetDIBits(dc, g_hbm, 0, bm.bmHeight, bmp, &bmi, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
region = CreateRectRgn(0,0,bm.bmWidth,bm.bmHeight);
|
|
|
|
|
|
|
|
// Search for transparent pixels
|
|
|
|
for (y = bm.bmHeight-1; y >= 0; y--)
|
|
|
|
for (x = 0; x < bm.bmWidth; )
|
|
|
|
if ((*bmp & 0xFFFFFF) == keycolor)
|
|
|
|
{
|
|
|
|
int j = x;
|
|
|
|
while ((x < bm.bmWidth) && ((*bmp & 0xFFFFFF) == keycolor)) 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);
|
2002-10-02 19:54:16 +00:00
|
|
|
}
|
|
|
|
|
2003-11-12 20:24:53 +00:00
|
|
|
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
2002-10-02 19:54:16 +00:00
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
g_hInstance=hInst;
|
|
|
|
return TRUE;
|
2002-10-02 19:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK TimeProc(
|
|
|
|
UINT uID,
|
|
|
|
UINT uMsg,
|
|
|
|
DWORD dwUser,
|
|
|
|
DWORD dw1,
|
|
|
|
DWORD dw2)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
int call = -1;
|
2002-10-02 19:54:16 +00:00
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
// FadeIN
|
|
|
|
case 0: if (timeleft == 0)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
timeleft = sleep_val;
|
2002-10-02 19:54:16 +00:00
|
|
|
state++;
|
2003-09-12 14:01:29 +00:00
|
|
|
if (nt50) call = 255;
|
2002-10-02 19:54:16 +00:00
|
|
|
} else { call = ((fadein_val-timeleft)*255)/fadein_val; break; }
|
|
|
|
// Sleep
|
|
|
|
case 1: if (timeleft == 0)
|
|
|
|
{
|
|
|
|
timeleft = fadeout_val;
|
2003-09-12 14:01:29 +00:00
|
|
|
state++;
|
|
|
|
// fadeout
|
2002-10-02 19:54:16 +00:00
|
|
|
} else break;
|
|
|
|
// FadeOUT
|
|
|
|
case 2: if (timeleft == 0)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
PostMessage((HWND)dwUser, WM_TIMER, 0, 0);
|
|
|
|
return;
|
2002-10-02 19:54:16 +00:00
|
|
|
} else { call = ((timeleft)*255)/fadeout_val; break; }
|
|
|
|
}
|
|
|
|
// Transparency value aquired, and could be set...
|
|
|
|
if ((call >= 0) && nt50)
|
|
|
|
SetLayeredWindowAttributesProc((HWND)dwUser, keycolor,
|
|
|
|
call,
|
2003-09-12 14:01:29 +00:00
|
|
|
alphaparam);
|
|
|
|
|
2002-10-02 19:54:16 +00:00
|
|
|
// Time is running out...
|
|
|
|
timeleft--;
|
|
|
|
}
|
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
int myatoi(char *s);
|
|
|
|
|
2002-10-02 19:54:16 +00:00
|
|
|
void __declspec(dllexport) show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
DEVMODE dm;
|
2002-10-02 19:54:16 +00:00
|
|
|
char fn[MAX_PATH];
|
|
|
|
char temp[64];
|
2003-09-12 14:01:29 +00:00
|
|
|
|
|
|
|
g_rv = -1;
|
|
|
|
resolution = RESOLUTION;
|
2002-10-02 19:54:16 +00:00
|
|
|
|
|
|
|
EXDLL_INIT();
|
|
|
|
|
|
|
|
popstring(temp);
|
2003-09-12 14:01:29 +00:00
|
|
|
sleep_val = myatoi(temp);
|
2002-10-02 19:54:16 +00:00
|
|
|
popstring(temp);
|
2003-09-12 14:01:29 +00:00
|
|
|
fadein_val = myatoi(temp);
|
2002-10-02 19:54:16 +00:00
|
|
|
popstring(temp);
|
2003-09-12 14:01:29 +00:00
|
|
|
fadeout_val = myatoi(temp);
|
2002-10-02 19:54:16 +00:00
|
|
|
popstring(temp);
|
|
|
|
keycolor = myatoi(temp);
|
|
|
|
popstring(fn);
|
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
|
|
|
|
// Check for winXP/2k at 32 bpp transparency
|
|
|
|
nt50 = (LOBYTE(LOWORD(GetVersion())) >= 5) && !((dm.dmBitsPerPel < 32) && (keycolor != -1));
|
2002-10-02 19:54:16 +00:00
|
|
|
if (!nt50)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
// Fading+transparency is unsupported at old windows versions...
|
|
|
|
resolution = sleep_val + fadein_val + fadeout_val;
|
|
|
|
fadeout_val = fadein_val = 0;
|
|
|
|
sleep_val = 1;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// div them by resolution
|
|
|
|
sleep_val >>= 5;
|
|
|
|
fadein_val >>= 5;
|
|
|
|
fadeout_val >>= 5;
|
|
|
|
|
|
|
|
alphaparam = LWA_ALPHA | ((keycolor == -1)?(0):(LWA_COLORKEY));
|
|
|
|
keycolor = ((keycolor & 0xFF) << 16) + (keycolor & 0xFF00) + ((keycolor & 0xFF0000) >> 16);
|
|
|
|
}
|
2002-10-02 19:54:16 +00:00
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
if (fn[0] && ((sleep_val+fadein_val+fadeout_val)>0))
|
2002-10-02 19:54:16 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
static WNDCLASS wc;
|
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.hInstance = g_hInstance;
|
|
|
|
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
|
|
|
|
wc.lpszClassName = classname;
|
|
|
|
if (RegisterClass(&wc))
|
|
|
|
{
|
|
|
|
char fn2[MAX_PATH];
|
|
|
|
lstrcpy(fn2,fn);
|
|
|
|
lstrcat(fn,".bmp");
|
|
|
|
lstrcat(fn2,".wav");
|
|
|
|
g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
|
|
|
|
if (g_hbm)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
HWND myWnd;
|
2002-10-02 19:54:16 +00:00
|
|
|
UINT timerEvent;
|
|
|
|
|
|
|
|
// Get Bitmap Information
|
|
|
|
GetObject(g_hbm, sizeof(bm), (LPSTR)&bm);
|
|
|
|
|
|
|
|
myWnd = 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
|
|
|
|
if (nt50)
|
|
|
|
{
|
|
|
|
// Get blending proc address
|
|
|
|
HANDLE user32 = GetModuleHandle("user32");
|
2002-11-19 15:54:03 +00:00
|
|
|
SetLayeredWindowAttributesProc = (_tSetLayeredWindowAttributesProc) GetProcAddress(user32, "SetLayeredWindowAttributes");
|
2002-10-02 19:54:16 +00:00
|
|
|
// Use win2k method
|
|
|
|
SetLayeredWindowAttributesProc(myWnd, keycolor,
|
|
|
|
(fadein_val > 0)?(0):(255),
|
|
|
|
alphaparam);
|
|
|
|
} else
|
|
|
|
if (keycolor != -1)
|
|
|
|
{
|
2003-09-12 14:01:29 +00:00
|
|
|
// transparency mode
|
|
|
|
SetTransparentRegion(myWnd);
|
|
|
|
}
|
|
|
|
|
2002-11-19 15:54:03 +00:00
|
|
|
PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME|SND_NODEFAULT);
|
|
|
|
|
2002-10-02 19:54:16 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kill the timer...
|
|
|
|
timeKillEvent(timerEvent);
|
|
|
|
|
|
|
|
// Stop currently playing wave, we want to exit
|
|
|
|
PlaySound(0,0,0);
|
|
|
|
|
|
|
|
DeleteObject(g_hbm);
|
|
|
|
}
|
2002-11-19 15:54:03 +00:00
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
// We should UnRegister class, since Windows NT series never does this by itself
|
|
|
|
UnregisterClass(wc.lpszClassName, g_hInstance);
|
2002-10-02 19:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wsprintf(temp,"%d",g_rv);
|
|
|
|
pushstring(temp);
|
|
|
|
}
|
|
|
|
|
2003-09-12 14:01:29 +00:00
|
|
|
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;
|
|
|
|
}
|