library SplashScreen;
{$R 'Resource.res' 'Resource.rc'}
// [..]
function WndProc(hWnd, uMsg, wParam, lParam: DWORD): LRESULT;
stdcall;
var
ps : TPaintStruct;
dc : HDC;
// [..]
DlgRect : TRect;
DesktopRect : TRect;
begin
Result := 0;
case uMsg
of
WM_DESTROY:
begin
if hBitMap <> 0
then
DeleteObject(hBitMap);
PostQuitMessage(0);
end;
WM_CREATE:
begin
GetWindowRect(hWnd, DlgRect);
GetWindowRect(GetDesktopWindow, DesktopRect);
DlgWidth := DlgRect.right - DlgRect.left;
DlgHeight := DlgRect.bottom - DlgRect.top;
MoveWindow(hWnd, (DesktopRect.right - DlgWidth)
div 2,
(DesktopRect.bottom - DlgHeight)
div 2, DlgWidth, DlgHeight, False);
hBitMap := LoadBitmap(HInstance, BitmapName);
end;
WM_PAINT:
begin
dc := BeginPaint(hWnd, ps);
hMemoryDC := CreateCompatibleDC(
dc);
hOldBmp := SelectObject(hMemoryDC, hBitMap);
GetObject(hBitMap, SizeOf(TBitmap), @bitmap);
StretchBlt(
dc, 0, 0, WndWidth, WndHeight, hMemoryDC, 0, 0, bitmap.bmWidth,
bitmap.bmHeight, SRCCOPY);
SelectObject(hMemoryDC, hOldBmp);
DeleteDC(hMemoryDC);
EndPaint(hWnd, ps);
end;
WM_CLOSE:
DestroyWindow(hWnd);
WM_LBUTTONDOWN:
DestroyWindow(hWnd);
else
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
end;
procedure ShowBitMap;
var
wc : TWndClassEx;
msg : TMsg;
begin
wc.cbSize := SizeOf(TWndClassEx);
wc.style := CS_HREDRAW
or CS_VREDRAW;
// [..]
wc.hIconSm := 0;
RegisterClassEx(wc);
wnd := CreateWindowEx(0, ClassName,
nil, WS_POPUP, Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT), WndWidth, WndHeight, 0, 0, HInstance,
nil);
ShowWindow(wnd, SW_SHOWNORMAL);
while True
do
begin
if not GetMessage(msg, 0, 0, 0)
then
Break;
TranslateMessage(msg);
DispatchMessage(msg);
end;
ExitCode := msg.wParam;
end;
procedure CloseSplashScreen;
begin
DestroyWindow(wnd);
end;
procedure DllEntry(reason: DWORD);
begin
if reason = DLL_PROCESS_ATTACH
then // When the dll is loaded
ShowBitMap;
end;
exports
CloseSplashScreen;
begin
DllProc := @DllEntry;
DllEntry(DLL_PROCESS_ATTACH);
end.