通过使用“拖动区域”来移动无标题窗口 [英] Moving a caption-less window by using a "drag area"

查看:106
本文介绍了通过使用“拖动区域”来移动无标题窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拥有自己的标题栏,因此我基本上使用面板(名称: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.

Christian

Christian

推荐答案

您可以随时通过任何具有mousedown事件的控件拖动窗口,方法是使用Magic $ F012号码与WM_SYSCOMMAND消息。这是我从Ray Kanopka(优秀的大型组件的作者)拿起的东西,但我不再记得这是如何传给我的。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆