使用“拖动区域"移动无字幕窗口 [英] Moving a caption-less window by using a "drag area"
问题描述
我想拥有自己的标题栏,因此我基本上使用了一个面板(名称:pnCaption)并删除了 CreateParams 中的原始标题栏.但是在新面板中通过MouseDown-MouseMove移动窗口的能力是个问题.
I would like to have my own caption bar and therefore I am using basically a panel (Name: pnCaption) and remove the original caption bar in CreateParams. But the ability to move the window by MouseDown-MouseMove in the new panel is a problem.
通常您会使用 NCHITTEST 消息.但是,如果鼠标位于面板上(我自己的标题),则不会发出信号.看代码...
Normally you would use the NCHITTEST message. BUT this isn't signaled if the mouse is over the panel (my own caption). See code ...
procedure TForm1.CreateParams(var params: TCreateParams);
begin
inherited Createparams(Params);
with Params do
Style := (Style or WS_POPUP) and (not WS_DLGFRAME);
end;
procedure TForm1.WM_NCHitTest(var Msg: TWMNcHitTest);
begin
inherited;
if PtInRect(pnCaption.BoundsRect, ScreenToClient(Point(Msg.XPos, Msg.YPos)))
then Msg.Result := HTCAPTION;
end;
如果有任何关于如何完成该任务的提示,我将不胜感激.
I would appreciate any hints how to accomplish that task.
基督徒
推荐答案
通过使用带有 WM_SYSCOMMAND 消息的Magic"$F012 数字,您始终可以通过任何具有鼠标按下事件的控件拖动窗口.这是我从 Ray Kanopka(优秀 raize 组件的作者)那里学到的东西,但我不再记得这是如何传授给我的.
You can always drag a window by any control that has a mousedown event by using the "Magic" $F012 number with a WM_SYSCOMMAND message. It's something I picked up from Ray Kanopka (author of the excellent raize components), but I no longer remember how this was imparted to me.
这也是一种简洁的方式,允许用户通过给他们一个看起来像标题的面板标签来移动无边框表单.例如,我用它来允许用户移动一个无边框的关于对话框:
It is also a neat and simple way of allowing users to move borderless forms by giving them a label of panel that looks like a caption. For example, I use it to allow users to move a borderless about dialog:
procedure TAbout_Dlg.LblTitleMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
sc_DragMove = $F012;
begin
ReleaseCapture;
Perform( wm_SysCommand, sc_DragMove, 0 );
end;
这篇关于使用“拖动区域"移动无字幕窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!