现在的位置: 首页 > 综合 > 正文

怎么自动把窗体显示出来?

2012年04月13日 ⁄ 综合 ⁄ 共 2268字 ⁄ 字号 评论关闭
怎么自动把窗体显示出来? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061119181326198.html
当窗体当前没有焦点,或者窗体被最小化了,在该窗体得到某一事件怎么显示窗体呀?让窗体得到焦点。我用以下代码不行:  
  procedure   TForm1.WndProc(var   message:   TMessage);  
  var  
      dataStruct:   PCOPYDATASTRUCT;  
      passingMessage:   PMessage;  
  begin  
      inherited;  
      if   message.Msg   =   WM_COPYDATA   then   begin  
          dataStruct   :=   PCOPYDATASTRUCT(message.LParam);  
          passingMessage   :=   PMessage(dataStruct.lpData);  
          if   (passingMessage^.Msg   =   WM_KEYDOWN)   then   begin  
              //listBox1.Items.Add('message='   +   IntToStr(passingMessage^.WParam));  
              if   (passingMessage^.wParam   =   VK_HOME)   then  
              begin  
                  ShowWindow(self.Handle,   SW_SHOWNORMAL   or   SW_RESTORE);  
                  BringWindowToTop(self.Handle);  
                  SetForegroundWindow(self.Handle);  
              end;  
          end;  
      end;  
  end;  
   
  窗体在任务栏一闪一闪得,就是不提前现实。

试下:  
  ShowWindow(Application.Handle,   SW_SHOWNORMAL   or   SW_RESTORE);

帮顶

试了ShowWindow(Application.Handle,   SW_SHOWNORMAL   or   SW_RESTORE);  
  也是一样,就是不提前显示出来

有用了,我发现如果最小化得时候采用Application.Handle就行了,哈哈,我再试试  
  目前处于别得窗体之后还不行

加上BringWindowToTop和SetForegroundWindow呢?用Application.Handle

我也是都在后面2函数上加上才能在最小化状态把窗体置前得。但是处于别得窗体之后还是不行。不知道怎么回事

不是你想SetForegroundWindow谁就可以SetForegroundWindow谁的。  
   
  (msdn只说win98/me是这样,其实2k/xp也一样)  
  the   system   restricts   which   processes   can   set   the   foreground   window.   A   process   can   set   the   foreground   window   only   if   one   of   the   following   conditions   is   true:    
   
  The   process   is   the   foreground   process.    
  The   process   was   started   by   the   foreground   process.    
  The   process   received   the   last   input   event.    
  There   is   no   foreground   process.    
  The   foreground   process   is   being   debugged.    
  The   foreground   is   not   locked   (see   LockSetForegroundWindow).    
  The   foreground   lock   time-out   has   expired   (see   SPI_GETFOREGROUNDLOCKTIMEOUT   in   SystemParametersInfo).    
  No   menus   are   active.    
  不信可以自己试验,  
  搞一个程序只有:  
  void   __fastcall   TForm1::Timer1Timer(TObject   *Sender)  
  {  
          SetForegroundWindow(Handle);          
  }  
  保存起来,运行它然后把窗体放在后面,这时它只能在任务栏里闪。  
   
  再搞一个程序:  
  void   __fastcall   TForm1::Button1Click(TObject   *Sender)  
  {  
        WinExec("C:\\Documents   and   Settings\\Ray\\桌面\\新建文件夹\\project1.exe",SW_SHOW);//运行上一个程序  
  }  
  这时按Button1就可以调到前面来。

学习接分;;;;;;;;;;;

leonatcs(LeonKennedy)(时常逛一逛csdn,有益身心健康。)    
  真是这样,只在任务栏里闪,但是有没有办法直接掉到前面来?如果不开新进程。因为这个进程要一直开着,比如游戏外挂。我看到别得游戏外挂可以做到。

谢谢

抱歉!评论已关闭.