我现在以获取目标窗体句柄,窗体本身是不显示在当前桌面的,请问怎样在知道其句柄的情况下激活它 让它显示出来!
谢谢

解决方案 »

  1.   


    {从Win98开始,微软更改了系统代码,一般的SetForegroundWindow只能将
    状态栏中应用按钮闪烁,并没有将应用调到最前面。请使用下列函数:} 
    function ForceForegroundWindow(hwnd: THandle): Boolean;   
    const   
      SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
      SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;   
    var
      timeout: DWORD;   
    begin   
      if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
        ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and ((Win32MajorVersion > 4) or
        ((Win32MajorVersion = 4) and (Win32MinorVersion > 0)))) then
      begin   
        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);   
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE);   
        Result := SetForegroundWindow(hWnd);   
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);   
      end else
        Result := SetForegroundWindow(hWnd);   
    end;   { ForceForegroundWindow }
      

  2.   

    你的不显示在当前桌面是什么意思?是仅仅没有在最前端显示吗?如果是这样的话,用这个函数就可以ForceForegroundWindow(AHwnd{你要激活的窗口句柄})如果你要显示的窗口当前被隐藏了,没有显示,则用下面语句:ShowWindow(AHwnd{窗口句柄}, SW_SHOWNORMAL);
    ForceForegroundWindow(AHwnd{你要激活的窗口句柄})
      

  3.   

    HWND   hForegdWnd   =   ::GetForegroundWindow();   
      DWORD   dwCurID   =   ::GetCurrentThreadId();   
      DWORD   dwForeID   =   ::GetWindowThreadProcessId(hForegdWnd,   NULL);   
      ::AttachThreadInput(dwCurID,   dwForeID,   TRUE);   
      ::SetForegroundWindow(m_hWnd);   
      ::AttachThreadInput(dwCurID,   dwForeID,   FALSE);   这个肯定行,自己改为delphi的
      

  4.   

    先 ShowWindow  再 SetForegroundWinow