1、在网看到的一段类似QQ的代码,好象是这里的一个版主(对不住没有记住)写的,因为本人是菜鸟刚开始学习,请高手给加上解释(有*号的行),特别是其中的许多变量等代表的意思,越详细分越多。
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    FAnchors: TAnchors;//*************
    procedure WMMOVING(var Msg: TMessage); message WM_MOVING;//******
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}uses Math;procedure TForm1.WMMOVING(var Msg: TMessage);
begin
  inherited;//**********
  with PRect(Msg.LParam)^ do begin//*********
    Left := Min(Max(0, Left), Screen.Width - Width);//**********
    Top := Min(Max(0, Top), Screen.Height - Height);
    Right := Min(Max(Width, Right), Screen.Width);
    Bottom := Min(Max(Height, Bottom), Screen.Height);
    FAnchors := [];//*******
    if Left = 0 then Include(FAnchors, akLeft);//***
    if Right = Screen.Width then Include(FAnchors, akRight);
    if Top = 0 then Include(FAnchors, akTop);
    if Bottom = Screen.Height then Include(FAnchors, akBottom);
    Timer1.Enabled := FAnchors <> [];//****
  end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Enabled := False;
  Timer1.Interval := 200;
  FormStyle := fsStayOnTop;
end;procedure TForm1.Timer1Timer(Sender: TObject);
const
  cOffset = 2;
var
  vHandle: THandle;//****
begin
  vHandle := WindowFromPoint(Mouse.CursorPos);//***
  while (vHandle <> 0) and (vHandle <> Handle) do //****
    vHandle := GetParent(vHandle);//***
  if vHandle = Handle then begin
    if akLeft in FAnchors then Left := 0;//***
    if akTop in FAnchors then Top := 0;
    if akRight in FAnchors then Left := Screen.Width - Width;
    if akBottom in FAnchors then Top := Screen.Height - Height;
  end else begin
    if akLeft in FAnchors then Left := -Width + cOffset;
    if akTop in FAnchors then Top := -Height + cOffset;
    if akRight in FAnchors then Left := Screen.Width - cOffset;
    if akBottom in FAnchors then Top := Screen.Height - cOffset;
  end;
end;end.2、将这段代码改成:程度开始的时候窗口就自动停留在屏幕上端,和屏幕等宽,有自动隐藏功能。
  留言后请给:DJC@GENERSOFT.COM发消息,提醒我给你加分。谢谢
        MSN:DONG6785@HOTMAIL.COM

解决方案 »

  1.   

    有同感,其实,搂主的Idea 非常好
      

  2.   

    用Ctrl+鼠标左键单击一层层深入的看!遇上不懂的再按F1!有些东西和开发工具是无关的,还要学会利用MSDN!你上面有些标注*的地方表示你对些基本的Pascal语法,集合类型,句柄,消息机制,一些简单的API,以及Object Pascal中的面向对象的一些基本概念都不太了解!所以还要从语言角度和Window系统本身等方面下点工夫!让别人帮你写代码,你还是什么都不学不到!
      

  3.   

    同意ehom(?!)其实没有什么东西,都比较基础,为什么不给自己一个机会好好搞明白呢。。从别人口里听到的印象不是深。
      

  4.   

    顺手解释一点,分给不给无所谓了unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Memo1: TMemo;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
        FAnchors: TAnchors;//*************这里是定义一个窗体类成员
        procedure WMMOVING(var Msg: TMessage); message WM_MOVING;//****** 捕捉移动消息
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses Math;procedure TForm1.WMMOVING(var Msg: TMessage);
    begin
      inherited;//**********      继承原来的事件
      with PRect(Msg.LParam)^ do begin//*********这句PRECT不知道
        Left := Min(Max(0, Left), Screen.Width - Width);//**********计算窗体LEFT,不让窗体位于屏幕左边之外,
        Top := Min(Max(0, Top), Screen.Height - Height);
        Right := Min(Max(Width, Right), Screen.Width);
        Bottom := Min(Max(Height, Bottom), Screen.Height);
        FAnchors := [];//*******等于空集合
        if Left = 0 then Include(FAnchors, akLeft);//***
        if Right = Screen.Width then Include(FAnchors, akRight);
        if Top = 0 then Include(FAnchors, akTop);
        if Bottom = Screen.Height then Include(FAnchors, akBottom);
        Timer1.Enabled := FAnchors <> [];//****集合不为空时TIMER1开始记时
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Enabled := False;
      Timer1.Interval := 200;
      FormStyle := fsStayOnTop;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    const
      cOffset = 2;
    var
      vHandle: THandle;//****定义句柄
    begin
      vHandle := WindowFromPoint(Mouse.CursorPos);//***取鼠标所在的窗口句柄
      while (vHandle <> 0) and (vHandle <> Handle) do //****  取得窗口成功
        vHandle := GetParent(vHandle);//***  取父窗体
      if vHandle = Handle then begin
        if akLeft in FAnchors then Left := 0;//***akLeft是集合成员时,LEFT=0
        if akTop in FAnchors then Top := 0;
        if akRight in FAnchors then Left := Screen.Width - Width;
        if akBottom in FAnchors then Top := Screen.Height - Height;
      end else begin
        if akLeft in FAnchors then Left := -Width + cOffset;
        if akTop in FAnchors then Top := -Height + cOffset;
        if akRight in FAnchors then Left := Screen.Width - cOffset;
        if akBottom in FAnchors then Top := Screen.Height - cOffset;
      end;
    end;end.
      

  5.   

    谢谢各位,对不起我这里开始设的分不够,我再开一个贴子,请haitian(海天)过来我给加分,谢谢。有的时候对于一个初学者来说,往往几几句关键的话可能就起到了捅窗户纸的作用,很管用,真希望这里的每个高手都会起到这个作用。再一次谢谢。