您的位置:程序门 -> delphi -> windows sdk/api



求助!为什么双击系统托盘不显示主窗体?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求助!为什么双击系统托盘不显示主窗体?
发表于:2007-11-08 00:53:42 楼主
代码如下
unit   fapp;

interface

uses
    windows,   messages,   sysutils,   variants,   classes,   graphics,   controls,   forms,
    dialogs,shellapi;

type
    tform1   =   class(tform)
        procedure   formcreate(sender:   tobject);
        procedure   formclose(sender:   tobject;   var   action:   tcloseaction);
    private
        {   private   declarations   }
        procedure   wndproc(var   msg:tmessage);
        procedure   myminimize(sender:tobject);
    public
        {   public   declarations   }
        icondata:tnotifyicondata;

    end;

var
    form1:   tform1;

implementation

{$r   *.dfm}

procedure   tform1.formcreate(sender:   tobject);
begin
      icondata.cbsize:=sizeof(icondata);
      icondata.wnd:=handle;
      icondata.uid:=100;
      icondata.uflags:=nif_message+nif_icon+nif_tip;
      icondata.ucallbackmessage:=wm_user+1;
      icondata.hicon:=application.icon.handle;

      strpcopy(icondata.sztip,application.title);

      shell_notifyicon(nim_add,@icondata);

      application.onminimize:=myminimize;
      myminimize(nil);
end;

procedure   tform1.formclose(sender:   tobject;   var   action:   tcloseaction);
begin
      shell_notifyicon(nim_delete,@icondata);
      application.processmessages;
      application.terminate;
end;

procedure   tform1.wndproc(var   msg:tmessage);
begin
      case   msg.msg   of
                wm_user+1:
                case   msg.lparam   of
                          wm_lbuttondown:
                          begin
                                form1.show;
                                showwindow(application.handle,sw_shownormal);
                          end;
                end;
      end;
      inherited;
end;

procedure   tform1.myminimize(sender:tobject);
begin
      form1.hide;
      showwindow(application.handle,sw_hide);
end;


end.
双击不显示主窗体,根本没有反应,怎么回事?请高手解答
发表于:2007-11-08 01:12:131楼 得分:0
现在可以了,自己对照一下看看有什么不一样。
unit   fapp;

interface

uses
    windows,
    messages,
    sysutils,
    variants,
    classes,
    graphics,
    controls,
    forms,
    dialogs,
    shellapi;

type
    tfrmapp   =   class(tform)
        procedure   formcreate(sender:   tobject);
        procedure   formclose(sender:   tobject;   var   action:   tcloseaction);
    private
                {       private       declarations       }
        procedure   wndproc(var   msg:   tmessage);   override;
        procedure   myminimize(sender:   tobject);
    public
                {       public       declarations       }
        icondata:   tnotifyicondata;

    end;

var
    frmapp:   tfrmapp;

implementation

{$r       *.dfm}

procedure   tfrmapp.formcreate(sender:   tobject);
begin
    icondata.cbsize   :=   sizeof(icondata);
    icondata.wnd   :=   handle;
    icondata.uid   :=   100;
    icondata.uflags   :=   nif_message   +   nif_icon   +   nif_tip;
    icondata.ucallbackmessage   :=   wm_user   +   1;
    icondata.hicon   :=   application.icon.handle;

    strpcopy(icondata.sztip,   application.title);


    formstyle   :=   fsstayontop;
    application.onminimize   :=   myminimize;
end;

procedure   tfrmapp.formclose(sender:   tobject;   var   action:   tcloseaction);
begin
    shell_notifyicon(nim_delete,   @icondata);
end;

procedure   tfrmapp.wndproc(var   msg:   tmessage);
begin
    case   msg.msg   of
        wm_user   +   1:
            case   msg.lparam   of
                wm_lbuttondown:
                    begin
                        showwindow(handle,   sw_shownormal);
                    end;
            end;
    end;
    inherited;
end;

procedure   tfrmapp.myminimize(sender:   tobject);
begin
    shell_notifyicon(nim_add,   @icondata);

end;


end.
发表于:2007-11-08 10:27:382楼 得分:0
能说一下原因吗?谢谢!
发表于:2007-11-08 10:41:123楼 得分:0
好象还不行
发表于:2007-11-08 10:43:214楼 得分:0
在我这个已经可以运行了。
你把我的代码考过去试试。
要不你手工设置
formstyle       :=       fsstayontop;  
发表于:2007-11-08 11:29:105楼 得分:0
因为你在声明你的wndproc函数时,没有注明为重载或者覆盖
看下面
      procedure       wndproc(var       msg:       tmessage);       override;  
有个override;
发表于:2007-11-08 22:39:456楼 得分:0
setforegroundwindow(mainfrm.handle);
发表于:2007-11-21 17:01:097楼 得分:0
wndproc函数错了吧?
发表于:2007-11-21 21:07:068楼 得分:0
你不应该这样用自定义的消息
发表于:2007-11-21 21:08:249楼 得分:0
好像这两天有一个"托盘"标题的贴子,和你的差不多


快速检索

最新资讯
热门点击