Delphi:Windows消息在应用程序最小化时失败

Delphi:Windows消息在应用程序最小化时失败,delphi,sendmessage,Delphi,Sendmessage,我有一个要求,我必须将一个值从application1传递到application2。从以下链接获得解决方案: 发送方的示例代码如下所示: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; const WM_MY_MESSAGE = WM_USER + 1; type TForm1

我有一个要求,我必须将一个值从application1传递到application2。从以下链接获得解决方案:

发送方的示例代码如下所示:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  WM_MY_MESSAGE = WM_USER + 1;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  h: HWND;
begin
  h := FindWindow(nil, 'My Second Window');
  if IsWindow(h) then
    SendMessage(h, WM_MY_MESSAGE, 123, 520);
end;

end.
接收机的样本代码如下:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

const
  WM_MY_MESSAGE = WM_USER + 1;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  protected
    procedure WndProc(var Message: TMessage); override;    
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited;
  case Message.Msg of
    WM_MY_MESSAGE:
      ShowMessageFmt('The other application sent the data %d and %d.', [Message.WParam, Message.LParam]);
  end;
end;

end.

但是,当标题为“我的第二个窗口”的应用程序最小化时,这将无法正常工作。感谢您的帮助。

请勿使用表单的wibdow句柄。由于VCL窗口娱乐,这些可以在生活中改变形式。使用AllocateHWnd来分配一个稳定的窗口句柄。我无法重现Windows 7 32位上Delpfi XE7的问题,因为我也无法重现大约4天前@IndhuRajendran提出的相同问题(我使用了不同的代码)。您使用的是哪个Delphi版本和Windows版本?请遵循David Heffernan的建议。我正在使用Delphi 5和windows 7。我不再使用Delphi 5,但我使用Delphi 7进行了测试,没有问题。AppB显示的消息框与最小化或否无关。我想您需要调试,什么失败了,如果有的话,请在appa的
按钮1中单击
,不要搜索窗口,然后;-)