你看我下面的程序:(我用的是Delphi,其实与CB一样的)
--------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
ListBox1: TListBox;
ComboBox1: TComboBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure CreateParams(var Params: TCreateParams); override;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams( Params);
Params.WndParent:=GetDesktopWindow;
// Params.WndParent := 0;
// Params.ExStyle := Params.ExStyle or WS_Ex_AppWindow;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
// Application.MessageBox('Hello!!!!','Hint', MB_OK);
MessageBox(Self.Handle,'Hello!!!!','Hint', MB_OK);
end;
end.
-----------------------------------
在调用新的对话框时,不要使用Delphi集成的MessageBox,因为他的父窗口是你的MainForm,
如果你直接这么用,那么父窗口就会跳到前面来了。而用Windows API的方式,加上本窗口句柄,一切OK!