说明:1、主程序main.exe,从程序cong.exe;
2、cong.exe包含窗体testFrm;
3、testFrm窗体上有个按钮【隐藏】。
要求如下:
运行main程序,判断系统进程中是否有cong运行,
1、如果没有就运行cong(已经实现);
2、如果有就把cong激活到前台;
3、点击cong程序窗体按钮【隐藏】,cong程序到后台;
4、任务栏看不到cong程序;
5、再次运行main程序,又回到了2说明的过程。简单来说就是主程序调用从程序,已经运行就起来,没有运行就调用从程序。然后从程序可以消失,在主程序调用的时候可以再显示。
我现在碰到的问题是:从程序隐藏后主程序再通过setforegroundwindow就调不出来了。从程序隐藏我用的testFrm.windowstate = wsminimized
2、cong.exe包含窗体testFrm;
3、testFrm窗体上有个按钮【隐藏】。
要求如下:
运行main程序,判断系统进程中是否有cong运行,
1、如果没有就运行cong(已经实现);
2、如果有就把cong激活到前台;
3、点击cong程序窗体按钮【隐藏】,cong程序到后台;
4、任务栏看不到cong程序;
5、再次运行main程序,又回到了2说明的过程。简单来说就是主程序调用从程序,已经运行就起来,没有运行就调用从程序。然后从程序可以消失,在主程序调用的时候可以再显示。
我现在碰到的问题是:从程序隐藏后主程序再通过setforegroundwindow就调不出来了。从程序隐藏我用的testFrm.windowstate = wsminimized
试下下面我常用的代码:
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;