如何打开窗口控制菜单(50分)

  • 主题发起人 主题发起人 zhzdl
  • 开始时间 开始时间
Z

zhzdl

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么才可以像联从游戏大厅那样,按窗口左上角一个小图标就打开窗口的控制菜单?
 
重载WM_NCHITTEST消息,使这个点图标时象点在系统菜单时一样
参见http://www.delphibbs.com/delphibbs/dispq.asp?lid=399936
 
这个按钮的OnClick方法要怎么写啊,我笨笨的:)
 
按钮?图标吧

设置为HTSYSMENU自己就出来了,你得重载WM_nchittest呀
 
To menxin
你还在吗?我还是不会:)
下面是源代友,您帮帮我,好吗?
告诉我要怎么,谢谢您了!
代码:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, fcImgBtn, StdCtrls, fcButton;

type
  TMainFrm = class(TForm)
    Image6: TImage;
    Panel1: TPanel;
    Image7: TImage;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Image1: TImage;
    Image3: TImage;
    Image2: TImage;
    Image4: TImage;
    Image5: TImage;
    Image8: TImage;
    Label1: TLabel;
    fcImageBtn1: TfcImageBtn;
    fcImageBtn3: TfcImageBtn;
    fcImageBtn2: TfcImageBtn;
    Panel5: TPanel;
    Panel6: TPanel;
    Image9: TImage;
    Panel7: TPanel;
    Panel8: TPanel;
    Image14: TImage;
    Image10: TImage;
    procedure fcImageBtn3Click(Sender: TObject);
    procedure fcImageBtn2Click(Sender: TObject);
    procedure fcImageBtn1Click(Sender: TObject);
    procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image2MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
        procedure WmNCHitTest(var Msg: TWMNCHitTest);
  public
    { Public declarations }
    //procedure CreateParams(var Params:TCreateParams);override;
  end;

var
  MainFrm: TMainFrm;
  CanMove:Boolean;
  oldPoint:TPoint;

implementation

{$R *.dfm}


{让窗口可以改变大小
procedure TMainFrm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style:=WS_THICKFRAME or WS_POPUP or WS_BORDER;
end;  }

procedure TMainFrm.WmNCHitTest(var Msg: TWMNCHitTest);
const v=10; //border width
var p:TPoint;
begin
  p:=Point(Msg.XPos,Msg.YPos);
  p:=ScreenToClient(p);
  if PtInRect(Rect(0,0,v,v),p) then
    Msg.Result:=HTTOPLEFT
  else if PtInRect(Rect(Width-v,Height-v,Width,Height),p) then
    Msg.Result:=HTBOTTOMRIGHT
  else if PtInRect(Rect(Width-v,0,Width,v),p) then
    Msg.Result:=HTTOPRIGHT
  else if PtInRect(Rect(0,Height-v,v,Height),p) then
    Msg.Result:=HTBOTTOMLEFT
  else if PtInRect(Rect(v,0,Width-v,v),p) then
    Msg.Result:=HTTOP
  else if PtInRect(Rect(0,v,v,Height-v),p) then
    Msg.Result:=HTLEFT
  else if PtInRect(Rect(Width-v,v,Width,Height-v),p) then
    Msg.Result:=HTRIGHT
  else if PtInRect(Rect(v,Height-v,Width-v,Height),p) then
    Msg.Result:=HTBOTTOM;
  Inherited;
end;


procedure TMainFrm.fcImageBtn3Click(Sender: TObject);
begin
    AppLication.Minimize;
end;

procedure TMainFrm.fcImageBtn2Click(Sender: TObject);
begin
     Close;
end;

procedure TMainFrm.fcImageBtn1Click(Sender: TObject);
begin
   //弹出系统菜单
end;

procedure TMainFrm.Image2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
     if (Button = mbleft) and not CanMove then
     begin
     CanMove := True;
     oldPoint.X:=x;
     oldPoint.Y:=y;
     end;
end;

procedure TMainFrm.Image2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
      CanMove:=False;
end;

procedure TMainFrm.Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
    if CanMove then
      begin
       //移动窗口
        MainFrm.Left:=MainFrm.Left+X-oldPoint.x;
        MainFrm.Top:=MainFrm.Top+Y-oldPoint.y;
      end;
end;

end.
 
procedure TMainFrm.WmNCHitTest(var Msg: TWMNCHitTest);
const v=10; //border width
var p:TPoint;
begin
p:=Point(Msg.XPos,Msg.YPos);
p:=ScreenToClient(p);
//加入下面这两行
//*******************
if ptinrect(imagebtn.clientrect,p) then //clientrect可能不准确,自己变换一下坐标吧
msg.result:=htsysmenu;
//********************

if PtInRect(Rect(0,0,v,v),p) then
Msg.Result:=HTTOPLEFT
else if PtInRect(Rect(Width-v,Height-v,Width,Height),p) then
Msg.Result:=HTBOTTOMRIGHT
else if PtInRect(Rect(Width-v,0,Width,v),p) then
Msg.Result:=HTTOPRIGHT
else if PtInRect(Rect(0,Height-v,v,Height),p) then
Msg.Result:=HTBOTTOMLEFT
else if PtInRect(Rect(v,0,Width-v,v),p) then
Msg.Result:=HTTOP
else if PtInRect(Rect(0,v,v,Height-v),p) then
Msg.Result:=HTLEFT
else if PtInRect(Rect(Width-v,v,Width,Height-v),p) then
Msg.Result:=HTRIGHT
else if PtInRect(Rect(v,Height-v,Width-v,Height),p) then
Msg.Result:=HTBOTTOM;
Inherited;
end;


 
我按您的方法做了,还是不行,您看看运行结果。
http://shui.jian.gov.cn/mypro/imagfrm.exe
真是麻烦您了。
 
重载 WMNCHitTest 的过程少了message。

procedure WmNCHitTest(var Msg: TWMNCHitTest); message WMNCHitTest;

 
我加上了,不行,移动窗口可以,弹出窗口的控制菜单还是不行,对了,为什么按在窗口
上的Plane就不能移动窗口,按到其他的控件可以,要怎样处理?
分可以继续加。
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部