我正在尝试创建一个类似于 Windows UAC 的屏幕储物柜,如本教程中所示。我很难创建背景最大化的窗口,减少光线和桌面的屏幕截图。
这是我到目前为止尝试过的所有代码:
program Project1;
uses
Winapi.Windows, Winapi.Messages, Vcl.Graphics, Vcl.Forms;
function MainWndProc(hWindow: HWND; Msg: UINT; wParam: wParam;
lParam: lParam): LRESULT;
var
ps: TPaintStruct;
ScreenDC: HDC;
ScreenHandle: HWnd;
ScreenBitmap: TBitmap;
begin
Result := 0;
case Msg of
WM_PAINT:
begin
BeginPaint(hWindow, ps);
ScreenHandle := GetDeskTopWindow;
ScreenDC := GetDC(ScreenHandle);
try
ScreenBitmap := TBitMap.Create;
try
ScreenBitmap.Width := Screen.Width;
ScreenBitmap.Height := Screen.Height;
BitBlt(ScreenBitmap.Canvas.Handle, 0, 0,
Screen.Width, Screen.Height, ScreenDC, 0, 0, SRCCOPY);
finally
ScreenBitmap.Free
end
finally
ReleaseDC(ScreenHandle, ScreenDC)
end;
EndPaint(hWindow, ps);
end;
WM_DESTROY: PostQuitMessage(0);
else
begin
Result := DefWindowProc(hWindow, Msg, wParam, lParam);
Exit;
end;
end;
end;
var
wc: TWndClass;
hWindow: HWND;
Msg: TMsg;
begin
wc.lpszClassName := 'App';
wc.lpfnWndProc := @MainWndProc;
wc.Style := CS_VREDRAW or CS_HREDRAW;
wc.hInstance := hInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.hbrBackground := (COLOR_WINDOW + 1);
wc.lpszMenuName := nil;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
RegisterClass(wc);
hWindow := CreateWindowEx(WS_EX_CONTROLPARENT or WS_EX_WINDOWEDGE,
'AppClass',
'CREATE_WND',
WS_VISIBLE or WS_CLIPSIBLINGS or
WS_CLIPCHILDREN or WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
400, 300,
0,
0,
hInstance,
nil);
ShowWindow(hWindow, CmdShow);
UpDateWindow(hWindow);
while GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
Halt(Msg.wParam);
end.