⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 219.htm

📁 水木清华的BBS文章
💻 HTM
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://bbs.tsinghua.edu.cn"><font face="黑体"><big><big>水木清华★</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         Delphi编程                            (BM: strayli FlyingBoy)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="454"> <p align="center">[<a href="index.htm">回到开始</a>][<a href="178.htm">上一层</a>][<a href="220.htm">下一篇</a>]
<hr><p align="left"><small>发信人: JeffreyDong (Jeff), 信区: Visual <br>

标  题: Re: 如何让程序运行时不在任务栏中显示? <br>

发信站: BBS 水木清华站 (Wed Apr 22 00:43:07 1998) WWW-POST <br>

  <br>

  <br>

【 在 TigerJade (鸭子) 的大作中提到: 】 <br>

: 【 在 JeffreyDong (Jeff) 的大作中提到: 】 <br>

: : 【 在 Colin (babee) 的大作中提到: 】 <br>

: : : 如题 <br>

: : : 若能够,请告之DELPHI实现方法 <br>

: : : 谢谢 <br>

: :   有控件... <br>

: 可以在最小化时用:Form1->Hide() <br>

: 但是如又要显示,又要不出现在任务栏中则比较难了 <br>

  <br>

  干脆我把源码贴上吧... <br>

  <br>

(******************************************************************************* <br>

** <br>

**  NoTask <br>

** <br>

**      Prevents a program's icons from showing on the Win95 TASKBAR <br>

**  while the program is running and the form is visible.  Works <br>



**  only in Delphi 2.0. Simply drop the component on the form, and <br>

**  set the HideForm property to TRUE to hide the TASKBAR icons. <br>

**  Set to FALSE to show the TASKBAR icons. <br>

** <br>

**  The outline of this code was shamelessly stolen from the most <br>

**  Excellent (Freeware!!) TPREVCHEK component which prevents a second <br>

**  instance of an application.  Ironically enough, PREVCHEK only works <br>

**  in DELPHI 1.0, whereas NOTASK only works in Delphi 2.0...  Go <br>

**  figure.  The author also owes a debt of gratitude to the author of <br>

**  TMinMax, Patrick Brisacier.  All of the PARENT routines came from that <br>

**  wonderful component.  Anyway, try this out, let me know what you think. <br>

**  This is generally intended to be used with one of the TASKTRAY components. <br>

** <br>

**  Feedback to: <br>

**      Eric Lawrence <br>

**      Lead Programmer <br>

**      Delta Programming Group <br>

** <br>

**      deltagrp@juno.com    or    deltagrp@keynetcorp.net <br>

** <br>

**  This component should be dropped on either the main form of the <br>

**  application or on the Splash screen form, whichever shows first. <br>

**  application or on the Splash screen form, whichever shows first. <br>

** <br>

**  This code may be used, modified, included in applications without any <br>

**  license agreements as long as the disclaimers are accepted.  Credit should <br>

**  be given where it is due. <br>

** <br>

**  Disclaimer: <br>

**  This software is released into the public domain on the strict understanding <br>

**  that neither myself nor any associates or companies I work for have any <br>

**  liability explicitly or implied. <br>

** <br>

**  Possible Enhancements: <br>

**      Beats me.  Any ideas? <br>

*******************************************************************************) <br>

unit NoTask; <br>

  <br>

interface <br>

uses <br>

  WinTypes, WinProcs, Classes, Forms, SysUtils, Controls, Messages; <br>

  <br>

type <br>

  TDuplicateComponent = class(Exception); <br>

  { Define a Form not Owner object exception } <br>



  TFormNotOwner = class(Exception); <br>

  { The NoTask Class declaration } <br>

  TNoTask = class(TComponent) <br>

  private <br>

    { Private declarations - Attributes } <br>

    FHideForm: boolean; <br>

    OldWndProc: TFarProc; <br>

    NewWndProc: Pointer; <br>

  <br>

  <br>

    { Private declarations - Methods } <br>

  <br>

    Function IsIt:boolean; <br>

    Procedure SetIt (value:boolean); <br>

  <br>

    {Start of Block to trap Parent form's messages...} <br>

    procedure HookParent; <br>

    procedure UnhookParent; <br>

    procedure HookWndProc(var Message: TMessage); <br>

    {End of Block to trap Parent form's messages...} <br>

  <br>

  protected <br>

  protected <br>

  <br>

  public <br>

    { Public declarations - Methods } <br>

    constructor Create(AOwner: TComponent); override; <br>

    destructor Destroy;override; <br>

    procedure Loaded; override; <br>

    procedure ProcessEnabled; <br>

  published <br>

    { Published declarations } <br>

    property HideForm: boolean read IsIt write SetIt stored true default true; <br>

  end; <br>

  <br>

procedure Register;                     { Register for Object Inspector } <br>

  <br>

implementation <br>

  <br>

destructor Tnotask.Destroy; <br>

begin <br>

  { Always make sure that the hook is removed. } <br>

  UnhookParent; <br>

  inherited destroy; <br>

end; <br>

end; <br>

  <br>

  <br>

(* <br>

**  Overridden constructor for our component.  Creates underlying TComponent, <br>

**  sets our own method pointer to an unassigned state, and checks that there <br>

**  is only one TNoTask Component on the form.  If there is another one, <br>

**  this one is destroyed by virtue of the exception handler within the design <br>

**  mode. <br>

*) <br>

  <br>

constructor TNoTask.Create(AOwner: TComponent); <br>

var <br>

  i: word;                              { General Loop Counter } <br>

  CompCount: byte;                      { TNoTask Component count } <br>

begin <br>

  inherited Create(AOwner);             { Call TComponent Constructor } <br>

  fhideform:=true;   //Default to hidden <br>

  NewWndProc := nil; <br>

  OldWndProc := nil; <br>

  CompCount := 0;                       { Initialise Component Count to zero } <br>

  { If we are designing at present } <br>

  if (csDesigning in ComponentState) then <br>



    if (AOwner is TForm) then <br>

      with (AOwner as TForm) do <br>

      begin <br>

        for i := 0 to ComponentCount - 1 do { Check if there is already one of uus! } <br>

          if Components[i] is TNoTask then inc(CompCount); <br>

  <br>

if CompCount > 1 then raise TDuplicateComponent.Create ('There is already a TNoTTask component on this Form'); <br>

     end <br>

      else <br>

        raise TFormNotOwner.Create <br>

              ('The owner of TNoTask Component is not a TForm'); <br>

        HookParent; <br>

  <br>

end; <br>

  <br>

  <br>

(* <br>

**  Overridden LOADED method.  This ensures that the check for a previous <br>

**  instance of our Application is done immediately after the TNoTask <br>

**  components properties have been read in from the form, and initialized. <br>

*) <br>

  <br>

  <br>

procedure TNoTask.Loaded; <br>

begin <br>

  inherited Loaded;                     { Always call inherited Loaded method } <br>

 if not (csDesigning in ComponentState) then <br>

  ProcessEnabled; <br>

 end; <br>

  <br>

  <br>

Procedure TNoTask.ProcessEnabled; <br>

begin <br>

//if (owner as tform).windowstate<>wsMinimized then exit; <br>

if fHideform then <br>

showwindow(FindWindow (nil,@Application.Title[1]),sw_hide) <br>

else <br>

showwindow(FindWindow (nil,@Application.Title[1]),sw_restore); <br>

end; <br>

  <br>

  <br>

Function TNoTask.IsIt:boolean; <br>

begin <br>

result:=fHideform; <br>

end; <br>

end; <br>

  <br>

Procedure TNoTask.SetIt(value:boolean); <br>

begin <br>

fhideform:=value; <br>

processenabled; <br>

end; <br>

  <br>

procedure Tnotask.HookParent; <br>

{ This procedure is used to get the parent's window procedure, save it,      } <br>

{ and replace it with our own.  This allows see all of the parent's messages } <br>

{ before it does.                                                            } <br>

begin <br>

  { If there is no parent, we can't hook it. } <br>

 if owner=nil then exit; <br>

  { Get the old window procedure via API call and store it. } <br>

  OldWndProc := TFarProc(GetWindowLong((owner as tform).Handle, GWL_WNDPROC)); <br>

  { Convert our object method into something Windows knows how to call } <br>

  NewWndProc := MakeObjectInstance(HookWndProc); <br>

  { Install it as the new Parent window procedure } <br>

  SetWindowLong((owner as tform).Handle, GWL_WNDPROC, LongInt(NewWndProc)); <br>

end; <br>

  <br>

  <br>

procedure Tnotask.UnhookParent; <br>

{ Remove our window function and reinstall the original. } <br>

begin <br>

  { We must have a parent, and we must have already hooked it. } <br>

  if (owner <> NIL) and assigned(OldWndProc) then <br>

    { Set back to original window procedure } <br>

    SetWindowLong((owner as tform).Handle, GWL_WNDPROC, LongInt(OldWndProc)); <br>

  { If we have created a window procedure via MakeObjectInstance, } <br>

  { it must be disposed of.                                       } <br>

  if assigned(NewWndProc) then <br>

    FreeObjectInstance(NewWndProc); <br>

  { Reset variables to NIL } <br>

  NewWndProc := NIL; <br>

  OldWndProc := NIL; <br>

end; <br>

  <br>

  <br>

procedure Register; <br>

{Register for the Object Inspector & Component Palette} <br>

begin <br>

  RegisterComponents('Additional', [TNoTask]); <br>

end; <br>

end; <br>

  <br>

  <br>

{ The window procedure that is installed into our parent. } <br>

procedure Tnotask.HookWndProc(var Message: TMessage); <br>

  <br>

begin <br>

  { If there's no parent, something has really gone wrong. } <br>

  if owner = NIL then exit; <br>

        if (message.msg=wm_showwindow) then <br>

            begin <br>

              if (message.wparam<>0) then {restoring...} <br>

                   ProcessEnabled; <br>

            end; <br>

  <br>

{ ALWAYS call the old window procedure so the parent can process its stuff  } <br>

message.Result := CallWindowProc(OldWndProc, (owner as tform).Handle, message.Mssg, message.wParam, message.lParam); <br>

  <br>

end; <br>

  <br>

end. <br>

  <br>

  <br>

  { If there's no parent, something has really gone wrong. } <br>

  if owner = NIL then exit; <br>

        if (message.msg=wm_showwindow) then <br>

            begin <br>

              if (message.wparam<>0) then {restoring...} <br>

                   ProcessEnabled; <br>

            end; <br>

  <br>

{ ALWAYS call the old window procedure so the parent can process its stuff  } <br>

message.Result := CallWindowProc(OldWndProc, (owner as tform).Handle, message.Ms <br>

  <br>

end; <br>

  <br>

end. <br>

  <br>

  <br>

-- <br>

  <br>

 使生如夏花之绚烂,死如秋叶之静美. <br>

  <br>

  http://www.nease.net/~jeffdong <br>

  <br>

※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: dialuser185.gb.com.cn] <br>

</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="178.htm">上一层</a>][<a href="220.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -