本文介绍了如何将工作空间坐标转换为屏幕坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换 rcNormalPosition.Left 中的 GetWindowPlacement 返回的工作区坐标rcNormalPosition.Top 来显示屏幕坐标,稍后我可以将其分配给 MainForm.Left MainForm.Top 。我该怎么做?

I want to convert the workspace coordinates returned by GetWindowPlacement in rcNormalPosition.Left and rcNormalPosition.Top to screen coordinates that I can assign later to MainForm.Left and MainForm.Top. How can I do that ?

推荐答案

最简单,最干净的方法是使用与 GetWindowPlacement ,即。这样,您无需在工作空间和屏幕坐标之间转换,因为您让系统为您完成工作。

The simplest and cleanest way is to use the API function that partners with GetWindowPlacement, namely SetWindowPlacement. That way you don't need to convert between workspace and screen coordinates because you let the system do the work for you.

var
  WindowPlacement: TWindowPlacement;
....
WindowPlacement.length := SizeOf(WindowPlacement);
Win32Check(GetWindowPlacement(Handle, WindowPlacement));
....
Win32Check(SetWindowPlacement(Handle, WindowPlacement));

在上面的代码中,假定为 Handle 成为表单的窗口句柄。

In the above code, Handle is assumed to be the window handle of the form.

如果您一直坚持左上方,则可以像这样恢复它们:

If you have persisted the left and top then you'd restore them like this:

var
  WindowPlacement: TWindowPlacement;
....
WindowPlacement.length := SizeOf(WindowPlacement);
Win32Check(GetWindowPlacement(Handle, WindowPlacement));
WindowPlacement.rcNormalPosition.Left := NewLeft;
WindowPlacement.rcNormalPosition.Top := NewTop;
Win32Check(SetWindowPlacement(Handle, WindowPlacement));

这篇关于如何将工作空间坐标转换为屏幕坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:18