Delphi创建透明窗口

时间:2020-10-03 23:49:25

标签: delphi winapi createwindow

因此,我使用WinApi的CreateWindow函数创建了一个窗口,但似乎无法使孔窗口透明,该窗口显示为全黑或白色,不透明,这是我所缺少的吗?

begin
  case uMsg of
    WM_DESTROY:
      begin
        Cleanup;
        PostQuitMessage(0);
        Result := 0;
        Exit;
      end;

    WM_PAINT:
      begin
        ValidateRect(hWnd, nil);
        Result := 0;
        Exit;
      end;
  end;

  Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;

    var
      wc: TWndClassEx = (cbSize: SizeOf(TWndClassEx); style: WS_EX_TRANSPARENT;
        lpfnWndProc: @MsgProc; cbClsExtra: 0; cbWndExtra: 0; hInstance: 0;
        hIcon: 0; hCursor: 0; hbrBackground: 0; lpszMenuName: nil;
        lpszClassName: 'Window'; hIconSm: 0);
    begin
      wc.hInstance := GetModuleHandle(nil);
      RegisterClassEx(wc);
    
      hWindow := CreateWindow('Window', '', 0, 0, 0, 300, 300,
        GetDesktopWindow, 0, wc.hInstance, nil);

  if SUCCEEDED(hWindow) then
  begin
    ShowWindow(hWindow, SW_SHOW);
    UpdateWindow(hWindow);

    while GetMessage(msg, 0, 0, 0) do
    begin
      TranslateMessage(msg);
      DispatchMessage(msg);
    end;
end;

1 个答案:

答案 0 :(得分:-1)

我已使用图像作为组件的父项,并将组件设置为使用父项