当窗体当前没有焦点,或者窗体被最小化了,在该窗体得到某一事件怎么显示窗体呀?让窗体得到焦点。我用以下代码不行:
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;窗体在任务栏一闪一闪得,就是不提前现实。

解决方案 »

  1.   

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

  2.   

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

  3.   

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

  4.   

    加上BringWindowToTop和SetForegroundWindow呢?用Application.Handle
      

  5.   

    不是你想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就可以调到前面来。
      

  6.   

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