全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1564
推到 Plurk!
推到 Facebook!

关于Password dialog 的两个问题

尚未結案
gyao
一般會員


發表:5
回覆:8
積分:7
註冊:2005-02-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-05 17:13:35 IP:61.165.xxx.xxx 未訂閱
Justmode & chih俩位版主,你们好,参考论坛里之前您解答问题的几个贴子,我写了以下的code(Delphi7),但是有俩个问题不知如何,烦请帮忙看看: 我想要实现的效果是: 1。窗口鼠标右键菜单中如果Lock选中,则窗体不能被移动;如果没有选中,则可以移动; 2。没有选中Lock时,可以拖动窗体的任何部分来达到移动窗体的目的; 3。取消Lock的选中,需要输入密码GMS。    但是有以下俩个问题: 1。按照我所写的code,在添加了Passworddlg后,主窗口Form1就无法通过标题栏来拖动了,这是什么原因?如果不添加这个Passworddlg就可以,这是为了什么?如何解决呢?    2。password的form我是通过file-new-other-password dialog的方式添加的,初始情况下,PasswordDlg.visible=False。但是如果改为了True,run时会提示“Cannot make a visible window modal”。改为False就不会有这个提示,我想请教这个原因是为什么?只是查了很久才发现这个错误提示是Visible=True造成的,所以想深入请教一下。    我是个Delphi的初学者,期待您们的指点。多谢多谢。
Project1:
program Project1;    uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {PasswordDlg};    {$R *.res}    begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TPasswordDlg, PasswordDlg);
  Application.Run;
end.    Unit1:
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus;    type
  TForm1 = class(TForm)
    PopupMenu_FormLock: TPopupMenu;
    FormPopMenu_Lock: TMenuItem;
    N1: TMenuItem;
    FormPopMenu_SavePosition: TMenuItem;
    procedure WmNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
    procedure FormPopMenu_LockClick(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    uses Unit2;    {$R *.dfm}    procedure TForm1.WmNCHitTest(var Msg : TWMNCHitTest);
begin
    DefaultHandler(Msg);
    if FormPopMenu_Lock.Checked=True then
    begin
        if Msg.Result=HTCAPTION then
            //Msg.Result := htClient;  // Dont move the window
            Msg.Result := Windows.HTNOWHERE;   //another method
    end
    else
    begin
        {if change Edit's text in this place, then just can change after release the LeftButton}
        //Edit_FormTop.Text := intTostr(Form_Main.Top);
        //Edit_FormLeft.Text := intTostr(Form_Main.Left);
        inherited;
    end;
     
end;    procedure TForm1.FormPopMenu_LockClick(Sender: TObject);
var
  hSysMenu: HMENU;    begin
    if FormPopMenu_Lock.Checked=True then
    begin        
        with TPasswordDlg.Create(Self) do
        begin
            try
            if ShowModal=mrOK then
            begin
                ShowMessage('Good Password');
                FormPopMenu_Lock.Checked := not FormPopMenu_Lock.Checked;
                FormPopMenu_SavePosition.Enabled := not FormPopMenu_SavePosition.Enabled;                     //RESTORE systemMenu
                GetSystemMenu(Handle, True);
            end        
            else
            begin
                ShowMessage('Wrong Password');
            end;         
            finally
                Free;
            end;
        end;        
    end
    else
    begin
        FormPopMenu_Lock.Checked := not FormPopMenu_Lock.Checked;
        FormPopMenu_SavePosition.Enabled := not FormPopMenu_SavePosition.Enabled;               hSysMenu := GetSystemMenu(Handle, False);
        //Delete 'Move' command from systemMenu
        DeleteMenu(hSysMenu, SC_MOVE, MF_BYCOMMAND);
    end;
    
end;    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    if FormPopMenu_Lock.Checked=False then
    begin
        // ---- Release any mouse cature functionallity
        ReleaseCapture;            // ---- "Fool" the mouse to hit the caption and
        // ---- initiate a move command to the system 
        Perform(WM_SYSCOMMAND,$F012,0);        //send the system message
        //second way
        //SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE   HTCAPTION, 0);
    end;    end;    end.    Unit2:
unit Unit2;    interface    uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons;    type
  TPasswordDlg = class(TForm)
    Label1: TLabel;
    Password: TEdit;
    OKBtn: TButton;
    CancelBtn: TButton;
    procedure OKBtnClick(Sender: TObject);
    procedure CancelBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  PasswordDlg: TPasswordDlg;    implementation    {$R *.dfm}    procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
    if Password.Text='GMS' then
    begin
        Modalresult := mrOK;
    end
    else
    begin
        Modalresult := mrCancel;
        Beep;
    end;    end;    procedure TPasswordDlg.CancelBtnClick(Sender: TObject);
begin
    Modalresult := mrCancel;
end;    end.    
gyao
一般會員


發表:5
回覆:8
積分:7
註冊:2005-02-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-08 15:29:43 IP:63.161.xxx.xxx 未訂閱
哪位先生帮帮忙啊,似乎看的人不少,却没有人理我。是我贴的code太长么?如果哪位需要code请给我发email,我寄文件给他。 younger_yg@hotmail.com 多谢了先。
scotthsiao
高階會員


發表:13
回覆:324
積分:147
註冊:2005-02-01

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-08 20:04:12 IP:210.68.xxx.xxx 未訂閱
因為你的意思好像是要 Justmode & chih兩位版主回答,其他的會員當然不好介入。
gyao
一般會員


發表:5
回覆:8
積分:7
註冊:2005-02-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-09 11:08:51 IP:63.161.xxx.xxx 未訂閱
多谢scotthsiao 老兄的提醒,原来是我提问的方式有问题!!我的本意是想说:我不是没有先在论坛里找过就随便发问的,不是只针对俩位版主发问。 不管怎样,再次感谢scotthsiao 提醒。并恳请各位先进能指点一二。感激不尽。
系統時間:2024-06-02 0:21:59
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!