Windows XP中的问题两个程序,一个程序A,一个程序B,其中,A是MDI风格的程序。当A程序运行的时候,单击右上角的最小化按钮,程序就最小化到任务栏中了,如何在程序B中将程序A最大化,并让程序A获得焦点
解决方案 »
- 【求助】delphi编译时出现错误!
- 何谓:线程 频繁切换???
- 请教:用wise install 制作安装工具的时候 bde 项怎么设置 我的数据库是 sql server2000
- 在IntraWeb怎样实现文件下载功能?
- form关闭的问题
- 急!一个有关与DELPHI 6的安装问题!高分!
- 关于dbgrid的问题,我的执行时程序行颜色为什么不会变,这段程序应当如何改?如果这的不能实现请说明原因?
- 请问有谁做过此程序????,帮忙看看....
- 怎样确定光盘的存在及盘符????????
- 菜菜的问题,请帮帮我,分已经用光了,一定加!??
- 程序出错了,但我不知道那里错了。。。。。哭ing
- Delphi连接Oracle 数据库最好用哪种连接方式
var
handle : THandle;
begin
handle := FindWindow('','B程序的标题');
SendMessage(handle,WM_SYSCOMMAND,SC_MAXIMIZE,0);
SetActiveWindow(handle);
end;
其实我是要做一个只允许运行一次的程序,我希望,如果程序已经启动了,再次启动的时候代码如下:自动切换到已经启动的程序上。
当我第一次启动的程序不是最小化的时候,第二次启动程序的时候可以自动机获第一次启动的程序,但是如果我把第一次启动的程序最小化的时候,第二次在运行程序就不行了。不知道是不是WindowsXP的原因。我只有WindowsXP.program MobileTest;uses
Controls,
Forms,
Windows,
SysUtils,
Messages,
uForm1 in 'uMDIFrame.pas' {Form1};
{$R *.res}var
hMutex:hwnd;
ret,iHandle:integer;
sName:String;
begin
Application.Initialize; sName:=Lowercase(StringReplace(Application.ExeName,'\','',[rfReplaceAll]));
hMutex:=CreateMutex(nil,false,PChar(sName));
ret:=GetLastError;
if ret=ERROR_ALREADY_EXISTS then
begin
ReleaseMutex(hMutex); iHandle:=FindWindow('TForm1',nil);
if iHandle<>0 then
begin
SendMessage(iHandle,WM_SYSCOMMAND,SC_MAXIMIZE,0);
SetActiveWindow(iHandle);
SetForegroundWindow(iHandle);
end
else
MessageBox(Application.Handle,'抱歉,本程序已经在运行!','系统提示' ,
MB_OK + MB_DEFBUTTON1 + MB_ICONEXCLAMATION);
exit;
end; Screen.Cursor:=crHourGlass;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
互斥对象(CreateMutex)应该是最好的方法
//项目文件...beginApplication.initialation;if CreateMutex then beginApplication.CreateForm(Form1, TForm1);Application.Run;end elseDestroyMutex;end;//主窗体文件...implementationvarMutex: hWnd;function CreateMutex: Boolean;varPrevInstHandle: THandle;AppTitle: PChar;beginAppTitle := StrAlloc(100);StrPCopy(AppTitle, Application.Title);Result := True;Mutex := Windows.CreateMutex(nil, False, AppTitle);if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then beginResult := False;SetWindowText(Application.Handle, '');PrevInstHandle := FindWindow(nil, AppTitle);if PrevInstHandle <> 0 then beginif IsIconic(PrevInstHandle) thenShowWindow(PrevInstHandle, SW_RESTORE)elseBringWindowToTop(PrevInstHandle);SetForegroundWindow(PrevInstHandle);end;if Mutex <> 0 thenMutex := 0;end;StrDispose(AppTitle);end;procedure DestroyMutex;beginif Mutex <> 0 thenCloseHandle(Mutex);end;
不知道你注意看没有,我的程序也用的是互斥对象,只不过我希望第二次启动的时候自动把焦点切换到第一次的程序中,现在的问题是当第一次启动的程序最小化后,无法自动切换到第一次启动的程序
if IsIconic(PrevInstHandle) then
ShowWindow(PrevInstHandle, SW_RESTORE)
也不行