gpt4 book ai didi

delphi - 应用程序必须执行什么操作才能获得 "support"远程桌面服务?

转载 作者:行者123 更新时间:2023-12-03 14:37:18 25 4
gpt4 key购买 nike

我有一个 Delphi 程序,需要通过远程桌面服务运行。我应该注意什么会阻止它正常运行?

最佳答案

Andreas 在精确定位双缓冲方面是正确的。据我所知,这是需要考虑的最重要的方面。

作为一个温和的反驳点,我一般不喜欢双缓冲,因为很难做到正确。许多组件没有成功。我正在考虑 VCL 下拉列表框,它不能在 Windows Basic 下正确绘制。还有其他人!

但是有些控件确实需要双缓冲以避免闪烁,那么该怎么办呢?当用户在本地连接时,您希望获得双缓冲的好处,但又不想在远程连接时给他们带来网络带宽的负担。

所以,这就是我所做的:

procedure WMWTSSessionChange(var Message: TMessage); message WM_WTSSESSION_CHANGE;

procedure TBaseForm.WMWTSSessionChange(var Message: TMessage);
begin
case Message.WParam of
WTS_CONSOLE_DISCONNECT,WTS_REMOTE_DISCONNECT,
WTS_SESSION_LOCK,WTS_SESSION_LOGOFF:
SessionDisconnected;
WTS_CONSOLE_CONNECT,WTS_REMOTE_CONNECT,
WTS_SESSION_UNLOCK,WTS_SESSION_LOGON:
SessionConnected;
end;
inherited;
end;

function WTSRegisterSessionNotification(hWnd: HWND; dwFlags: DWORD): BOOL; stdcall; external 'Wtsapi32.dll';
function WTSUnRegisterSessionNotification(hWnd: HWND): BOOL; stdcall; external 'Wtsapi32.dll';

const
NOTIFY_FOR_THIS_SESSION = 0;
NOTIFY_FOR_ALL_SESSIONS = 1;

procedure TBaseForm.CreateWnd;
begin
inherited;
WTSRegisterSessionNotification(WindowHandle, NOTIFY_FOR_THIS_SESSION);
end;

procedure TBaseForm.DestroyWnd;
begin
WTSUnRegisterSessionNotification(WindowHandle);
inherited;
end;

我的应用程序中的所有表单均源自 TBaseForm,因此继承了此行为。 SessionConnectedSessionDisconnected 方法是虚拟方法,因此各个表单可以执行特定操作。

特别是,我的所有表单都调用 UpdateDoubleBuffered:

function InRemoteSession: Boolean;
begin
Result := Windows.GetSystemMetrics(SM_REMOTESESSION)<>0;
end;

class procedure TBaseForm.UpdateDoubleBuffered(Control: TWinControl);
var
DoubleBuffered: Boolean;
begin
if InRemoteSession then begin
//see The Old New Thing, Taxes: Remote Desktop Connection and painting
DoubleBuffered := False;
end else begin
DoubleBuffered := (Control is TCustomListView)
or (Control is TCustomStatusBar);
//TCustomListView flickers when updating without double buffering
//TCustomStatusBar has drawing infidelities without double buffering in my app
end;
Control.DoubleBuffered := DoubleBuffered;
end;

procedure TBaseForm.UpdateDoubleBuffered;
var
Control: TControl;
begin
for Control in ControlEnumerator(TWinControl) do begin
UpdateDoubleBuffered(TWinControl(Control));
end;
end;

ControlEnumerator 是一个遍历组件子组件的枚举器。

旧新事物引用的是一篇题为 Taxes: Remote Desktop Connection and painting 的文章这是我大部分代码的灵感来源。

我确信还有其他与远程桌面相关的问题,但双缓冲肯定是最重要的问题之一。

关于delphi - 应用程序必须执行什么操作才能获得 "support"远程桌面服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4854534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com