首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

获取另一个exe资料的控制权

2013-07-08 
获取另一个exe文件的控制权A程序是一个exe执行文件B程序可以启动A程序。如果A已经启动,则激活A到当前程序,

获取另一个exe文件的控制权
A程序是一个exe执行文件
B程序可以启动A程序。如果A已经启动,则激活A到当前程序,如果A未启动则启动A程序
EXE
[解决办法]
先遍历所有进程,发现有A程序进程就SetForegroundWindow到前台,如果没有就启动A程序
启动其他程序可以在以下方式任选一种
CreateProcess
WinExec
WinExecEx
ShellExcute
[解决办法]
首先确认找到的句柄是对的,然后用下面的代码试下:

http://bbs.csdn.net/topics/390383307


function BringWindowToTopEx(hWnd: HWND): Boolean;
begin
  if IsIconic(hWnd) then
    ShowWindow(hWnd, SW_RESTORE);
  if GetForegroundWindow <> hWnd then
    SetForegroundWindow(hWnd);//enabled
    //BringWindowToTop(hWnd);//not enabled
    //ForceForegroundWindow(hWnd);//enabled
    {SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
    SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);//enabled}
    //SwitchToThisWindow(hWnd, True);//enabled
  Result := GetForegroundWindow = hWnd;
end;
 
function BringWindowToTopMost(hWnd: HWND; bTopMost: Boolean): Boolean;
begin
  if IsIconic(hWnd) then
    ShowWindow(hWnd, SW_RESTORE);
  if bTopMost then
    SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
  else
    SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
 
function BringWindowToTopXY(hWnd: HWND; X, Y: Integer;
  hWndInsertAfter: HWND): Boolean;
begin
  Result := BringWindowToTopEx(hWnd);
  Result := SetWindowPos(hWnd, hWndInsertAfter, X, Y, 0, 0, SWP_NOSIZE)
    and Result;
end;

热点排行