随意拖动的窗体---菜鸟问题!

0754boy 2004-06-09 09:32:48
本人正在学DELPHI,看例题,但实现不了效果,望高手指点一二;)

题意:普通窗体只能按住标题才能拖动.那么如何通过窗体的客户区(client区)来实现窗体的拖动呢?答案如下:
[步骤一]在窗体声明中(Type语句后)加入如下事例:
procedure WMNCHitTest(var M:TWMNCHitTest); message wm_NCHitTest;
//估计无法执行与这一句有关!

[步骤二]在窗体的实现部分(Implement语句后)添加如下语句:
//工程文件名:dragwindow.dpr
procedure TForm1.WMNCHitTest(var M:TWMNCHitTest);
begin
inherited; {调用默认的事件处理程序}
if M.Result=htClient then M.Result:=htCaption;
{如果是在Client区让Windows认为是在Caption区}
end;

=================================================================
我编写的程序:
=================================================================
=================================================================
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm);
procedure WMNCHitTest(var M;TWMNCHitTest); message wm_NCHitTest;

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

procedure tform1.WMCHitTest(var M: TWMNCHitTest);
BEGIN
inherited;
if M.Result = htClient then M.Result :=htcaption;
END;

{$R *.dfm}

end.
=================================================================
=================================================================
错误提示:
=================================================================
Build
[Error] Unit1.pas(11): Missing parameter type
[Error] Unit1.pas(11): Unknown directive: 'wm_NCHitTest'
[Error] Unit1.pas(13): Unknown directive: 'private'
[Error] Unit1.pas(15): Unknown directive: 'public'
[Error] Unit1.pas(17): 'IMPLEMENTATION' expected but ';' found
[Error] Unit1.pas(22): '.' expected but 'IMPLEMENTATION' found
[Error] Unit1.pas(11): Unsatisfied forward or external declaration: 'WMNCHitTest'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
=================================================================

...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
0754boy 2004-06-10
  • 打赏
  • 举报
回复
谢谢指正,结帖;)
miky 2004-06-10
  • 打赏
  • 举报
回复
照抄,对比一下你错误的地方,也就是一个:和;的问题。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
private
procedure WMNCHitTest(var M:TWMNCHitTest); message wm_NCHitTest;

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.WMNCHitTest(var M: TWMNCHitTest);
begin
inherited;
if M.Result = htClient then M.Result :=htcaption;

end;

end.
0754boy 2004-06-09
  • 打赏
  • 举报
回复
是的!整个例题滴字不漏 ^-^
zhlwyy 2004-06-09
  • 打赏
  • 举报
回复
你书上的源代码是这样写的吗?
0754boy 2004-06-09
  • 打赏
  • 举报
回复
能不能解释这一句的意思?(是一句还是两句,起什么作用)
procedure WMNCHitTest(var M:TWMNCHitTest); message wm_NCHitTest;
0754boy 2004-06-09
  • 打赏
  • 举报
回复
编译不成功!

能不能编译通过后直接把代码粘上来!
zhlwyy 2004-06-09
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm);


private
procedure WMNCHitTest(var M;TWMNCHitTest); message wm_NCHitTest;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

procedure tform1.WMCHitTest(var M: TWMNCHitTest);
BEGIN
inherited;
if M.Result = htClient then M.Result :=htcaption;
END;

{$R *.dfm}

end.
[Error] Unit1.pas(11): Missing parameter type
[Error] Unit1.pas(11): Unknown directive: 'wm_NCHitTest'
[Error] Unit1.pas(13): Unknown directive: 'private'
[Error] Unit1.pas(15): Unknown directive: 'public'
要把定义的过程写在private或者public


[Error] Unit1.pas(17): 'IMPLEMENTATION' expected but ';' found
[Error] Unit1.pas(22): '.' expected but 'IMPLEMENTATION' found
用了中文的标点符号改过来

5,391

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧