0

このチュートリアル に示されているように、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.
4

1 に答える 1