请问如何在程序中加入一个Alt+F8 就可以实现程序(窗体from1)的隐藏 
源代码是什么   我需要最简单的一种方法
本人是初学者,希望可以比较详细说明!
谢谢!

解决方案 »

  1.   

    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
        if (key = VK_F8) and (Shift = [ssAlt]) then
          form1.Hide;end;
    设置窗口的
    KeyPreview 属性为 true;
      

  2.   

    编译通过了 但是我用Shift+F8窗口并没有隐藏啊~你说的具体一点点啊  我刚开始学delphi的 麻烦你了谢谢
      

  3.   

    (Shift = [ssAlt]) 
    ======================================
    應該是Alt+F8吧?
      

  4.   

    详情请参考
    http://community.csdn.net/Expert/topic/4571/4571807.xml?temp=.341778和楼主提到的一样。
      

  5.   

    我试过Alt+F8了 也没有用的
    另:楼上的那位提到
    http://community.csdn.net/Expert/topic/4571/4571807.xml?temp=.341778
    这里只实现了运行隐藏程序,但是呼出后怎么再次隐藏呢?源代码如下请会的帮我写一下再次按下F2隐藏程序的代码 谢谢了!
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure FormActivate(Sender: TObject);
      private
        FHotKeyId: Integer;
        procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY; 
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      FHotKeyId := GlobalAddAtom('MyHotKey') - $C000;
      RegisterHotKey(Handle, FHotKeyId, MOD_CONTROL, VK_F2);
    end;procedure TForm1.HotKeyDown(var Msg: Tmessage);
    begin
      if (Msg.LparamLo = MOD_CONTROL) AND (Msg.LParamHi = VK_F2) then // 假设热键为ALT+F8
      begin
        ShowWindow(Application.Handle, SW_SHOW);
        ShowWindow(Self.Handle, SW_SHOW);
        if IsIconic(Application.Handle) then
          ShowWindow(Application.Handle, SW_RESTORE)
        else
          SetForegroundWindow(Application.Handle);
      end;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      UnRegisterHotKey(Handle, FHotKeyId);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowWindow(Application.Handle, SW_HIDE);
      ShowWindow(Self.Handle, SW_HIDE);
    end;procedure TForm1.FormActivate(Sender: TObject);
    begin
      ShowWindow(Application.Handle, SW_HIDE);
      ShowWindow(Self.Handle, SW_HIDE);
    end;end.
      

  6.   

    帮你改一下,这里设置的热键是Ctrl+F2,如果需要其他按键自己改一下,改不了再说
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        FHotKeyId: Integer;
        procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY; 
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      showFlag: Boolean;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      FHotKeyId := GlobalAddAtom('MyHotKey') - $C000;
      RegisterHotKey(Handle, FHotKeyId, MOD_CONTROL, VK_F2);
      showFlag := true;
    end;procedure TForm1.HotKeyDown(var Msg: Tmessage);
    begin
      if (Msg.LparamLo = MOD_CONTROL) AND (Msg.LParamHi = VK_F2) then
      begin
        if showFlag then
        begin
          ShowWindow(Application.Handle, SW_HIDE);
          ShowWindow(Self.Handle, SW_HIDE);
        end
        else
        begin
          ShowWindow(Application.Handle, SW_SHOW);
          ShowWindow(Self.Handle, SW_SHOW);
          if IsIconic(Application.Handle) then
            ShowWindow(Application.Handle, SW_RESTORE)
          else
            SetForegroundWindow(Application.Handle);
        end;
        showFlag := Not(showFlag);
      end;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      UnRegisterHotKey(Handle, FHotKeyId);
    end;end.
      

  7.   

    要在Form1的OnCreate和OnDestory事件里面双击一下来激活这两个事件
      

  8.   

    cuteant 十分感谢你,问题解决了!