简体   繁体   English

是否可以在RAD Studio 10 c ++中设置窗口(x,y)的位置?

[英]Is it possible to set the Window (x, y) Position in RAD Studio 10 c++?

I'm developing an application and it looks as if my Form object doesn't have anything for me to specify its exact coordinates. 我正在开发一个应用程序,它看起来好像我的Form对象没有任何东西可供我指定其确切坐标。

I have a label at the top acting as a titlebar, in c# I could use a combination of my mouse coordinates and window coordinates to make the window move with the mouse when the user clicks and drags. 我在顶部有一个标签充当标题栏,在c#中,我可以使用鼠标坐标和窗口坐标的组合来使窗口在用户单击和拖动时通过鼠标移动。 However, in c++ (along side RAD studio) there doesn't appear to be anything online I can use as reference to pull this off. 但是,在c ++(与RAD Studio一起使用)中,似乎没有什么可以用作参考的在线内容。

I've tried windows api with: 我已经尝试过Windows API:

SetWindowPos(this->GetOwnerWindow(), HWND_TOPMOST, 5,5,5,5, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

There's things like window position, but that only accepts integers or vars like "poScreenCenter". 诸如窗口位置之类的东西,但是只接受诸如“ poScreenCenter”之类的整数或变量。

Any insight on how this could be possible would be great. 关于如何做到这一点的任何见解都会很棒。

TForm (and all UI controls in general) have Left and Top (and Width and Height ) properties. TForm (以及所有的UI控件)具有LeftTop (以及WidthHeight )属性。

You can use the Label's OnMouse(Down|Up) events to set/unset a bool, and then have the Label's OnMouseMove event reposition the Form if the bool is set. 您可以使用Label的OnMouse(Down|Up)事件设置/取消设置布尔值,如果设置了布尔值,则可以让Label的OnMouseMove事件重新定位窗体。

A simpler and more efficient solution is to have the OnMouseDown event send an undocumented WM_COMMAND(SC_DRAGMOVE) message to the Form's HWND and let the OS handle the rest for you. 一个更简单,更有效的解决方案是让OnMouseDown事件向表单的HWND发送未记录的WM_COMMAND(SC_DRAGMOVE)消息,然后让操作系统为您处理其余的事情。 See Moving a caption-less window by using a "drag area" (written for Delphi, but it applies to C++Builder too, since they use the same VCL framework). 请参见使用“拖动区域”移动无字幕窗口 (为Delphi编写,但由于它们使用相同的VCL框架,因此它也适用于C ++ Builder)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM