1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 怎么把程序内部坐标转为屏幕坐标 如何将工作空间坐标转换为屏幕坐标?

怎么把程序内部坐标转为屏幕坐标 如何将工作空间坐标转换为屏幕坐标?

时间:2022-12-22 09:58:18

相关推荐

怎么把程序内部坐标转为屏幕坐标 如何将工作空间坐标转换为屏幕坐标?

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 ?

解决方案

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));

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));

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。