procedure TfrmMain.DestroyHidden;
begin
if (fHiddenWnd <> 0)
then
DestroyWindow(fHiddenWnd);
if (fHiddenClass <> 0)
then
Winapi.Windows.UnregisterClass(MakeIntResource(fHiddenClass), HInstance);
fHiddenWnd := 0;
fHiddenClass := 0;
BringToFront;
Application.ProcessMessages;
end;
procedure TfrmMain.CreateHidden(
const Color: TColor = COLOR_WINDOW;
const AlphaBlend: Boolean = True;
const AlphaBlendValue: Integer = 127;
const Transparent: Boolean = True;
const ExcludeBorder: Boolean = True);
function HiddenProc(fWnd: HWND; fMsg: UINT; fWParam: WPARAM; fLParam: LPARAM): LRESULT;
stdcall;
begin
Result := DefWindowProc(fWnd, fMsg, fWParam, fLParam);
end;
var
WndClass: TWndClass;
S:
string;
BorderWidth: Integer;
hMenuHandle: HMENU;
dwExStyle: DWORD;
begin
if ((fHiddenClass <> 0)
or (fHiddenWnd <> 0))
then
DestroyHidden;
BorderWidth := 0;
if (ExcludeBorder)
then
BorderWidth := BorderWidth + GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYEDGE) + GetSystemMetrics(SM_CYBORDER);
FillChar(WndClass, SizeOf(WndClass), 0);
WndClass.style := CS_NOCLOSE
or CS_VREDRAW
or CS_HREDRAW;
WndClass.lpfnWndProc := @HiddenProc;
WndClass.cbClsExtra := 0;
WndClass.cbWndExtra := 0;
WndClass.hInstance := HInstance;
WndClass.hIcon := LoadIcon(0, IDI_APPLICATION);
WndClass.hCursor := LoadCursor(0, IDC_APPSTARTING);
if (Color < 31)
then
WndClass.hbrBackground := GetSysColorBrush(Color)
else
WndClass.hbrBackground := GetSysColorBrush(COLOR_WINDOW);
WndClass.lpszMenuName := '
';
S := Format('
%s@%x', [ExtractFileName(Application.ExeName), GetCurrentThreadId]);
WndClass.lpszClassName := PChar(S);
fHiddenClass :=
Winapi.Windows.RegisterClass(WndClass);
Sleep(1);
dwExStyle := WS_EX_TOOLWINDOW;
if (Transparent)
then
dwExStyle := dwExStyle
or WS_EX_TRANSPARENT;
if (AlphaBlend)
then
dwExStyle := dwExStyle
or WS_EX_LAYERED;
if (fHiddenClass = 0)
then
Exit
else
fHiddenWnd := CreateWindowEx(dwExStyle,
MakeIntResource(fHiddenClass),
PChar(S),
WS_POPUP
or WS_VISIBLE
or WS_CLIPSIBLINGS
or WS_CLIPCHILDREN,
Self.Left + BorderWidth, Self.Top
{+ GetSystemMetrics(SM_CYCAPTION) + BorderWidth},
Self.Width - (BorderWidth * 2), Self.Height - BorderWidth
{- BorderWidth - GetSystemMetrics(SM_CYCAPTION)},
Self.Handle, 0, HInstance,
nil);
if (fHiddenWnd <> 0)
then
begin
if AlphaBlend
then
Winapi.Windows.SetLayeredWindowAttributes(fHiddenWnd, 0, AlphaBlendValue, LWA_ALPHA
or ULW_ALPHA);
EnableWindow(fHiddenWnd, LongBool(
not Transparent));
hMenuHandle := GetSystemMenu(fHiddenWnd, False);
if (hMenuHandle <> 0)
then
begin
DeleteMenu(hMenuHandle, SC_SIZE, MF_BYCOMMAND);
DeleteMenu(hMenuHandle, SC_MAXIMIZE, MF_BYCOMMAND);
DeleteMenu(hMenuHandle, SC_MINIMIZE, MF_BYCOMMAND);
DeleteMenu(hMenuHandle, SC_RESTORE, MF_BYCOMMAND);
DeleteMenu(hMenuHandle, SC_MOVE, MF_BYCOMMAND);
DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND);
DeleteMenu(hMenuHandle, 0, MF_BYCOMMAND);
CloseHandle(hMenuHandle);
end;
end;
Application.ProcessMessages;
end;