procedure TfrmSubChat.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
//Params.ExStyle := Params.ExStyle or WS_Ex_AppWindow or WS_EX_CLIENTEDGE;
//Params.ExStyle := Params.ExStyle or WS_Ex_AppWindow; //最上层WS_EX_TOOLWINDOW,WS_EX_TOPMOST
//Params.WndParent := GetDesktopWindow;
//params.WndParent := 0;
//SetWindowLong(Handle,GWL_EXSTYLE,(GetWindowLong(Handle,GWL_EXSTYLE) or WS_EX_APPWINDOW)); //设父属性,0是桌面
end;procedure TfrmSubChat.FormCreate(Sender: TObject);
begin
//SetWindowLong(Handle, GWL_HWNDPARENT, Application.MainForm.Handle);
end;这些都试过了,效果很不理想,要么是主窗口时不时跳到前面,要么是在子窗口上打开保存|打开对话框有问题,跳后面去了
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ShellAPI, AppEvnts, Menus;const WM_NID = WM_User + 1000; //申明一个常质type
TOSVersion = (osUnknown, os95, os98, osME, osNT3, osNT4, os2K, osXP, os2K3);type
TFHXMain = class(TForm)
webhx: TWebBrowser;
IdHTTP1: TIdHTTP;
pm1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
FIconData: TNotifyIconData;
procedure SysCommand(var SysMsg: TMessage); message WM_SYSCOMMAND;
procedure WMNID(var msg:TMessage); message WM_NID;
public
{ Public declarations }
end;var
FHXMain: TFHXMain;
NotifyIcon: TNotifyIconData; // 全局变量implementation{$R *.dfm}function GetOS: TOSVersion; //获得系统类型,用来取得托盘句柄
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := osUnknown;
if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
case OS.dwMajorVersion of
3: Result := osNT3;
4: Result := osNT4;
5:
begin
case OS.dwMinorVersion of
0: Result := os2K;
1: Result := osXP;
2: Result := os2K3;
end;
end;
end;
end
else
if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 0) then
Result := os95
else
if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 10) then
Result := os98
else
if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) then
Result := osME
end;function GetSysTrayWnd(): HWND; //返回系统托盘的句柄,适合于Windows各版本
var
OS: TOSVersion;
begin
OS := GetOS;
Result := FindWindow('Shell_TrayWnd', nil);
Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil);
if (OS in [osXP, os2K3]) then
Result := FindWindowEx(Result, 0, 'SysPager', nil);
if (OS in [os2K, osXP, os2K3]) then
Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil);
end;procedure KillTrayIcons(Sender: TObject);
var
hwndTrayToolBar: HWND;
rTrayToolBar: tRect;
x, y: Word;
begin
hwndTrayToolBar := GetSysTrayWnd;
Windows.GetClientRect(hwndTrayToolBar, rTrayToolBar);
for x := 1 to rTrayToolBar.right - 1 do
begin
for y := 1 to rTrayToolBar.bottom - 1 do
begin
SendMessage(hwndTrayToolBar, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
end;
end;
end;procedure TFHXMain.FormCreate(Sender: TObject);
begin
Self.Left := Screen.Width-self.Width;
Self.Top := Screen.Height-self.Height-30;
end;procedure TFHXMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
KillTrayIcons(self);
end;procedure TFHXMain.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @FIconData); //删除托盘图标
Shell_NotifyIcon(NIM_MODIFY, @FIconData);
end;procedure TFHXMain.N1Click(Sender: TObject);
begin
FHXMain.Visible := True; // 显示窗体
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); //删除托盘图标
Refresh;
end;procedure TFHXMain.N2Click(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
Refresh;
Application.Terminate;
end;procedure TFHXMain.SysCommand(var SysMsg: TMessage);
begin
case SysMsg.WParam of
SC_MINIMIZE: //主窗体最小化时
begin
SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW);
Hide; // 在义务栏暗藏程序
//正在托盘区显示图标
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage := WM_NID;
hIcon := Application.Icon.Handle;
szTip := 'HXGOLD';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon); // 正在托盘区显示图本
Refresh;
end;
else
inherited;
end;
end;procedure TFHXMain.WMNID(var msg:TMessage);
var
mousepos: TPoint;
begin
GetCursorPos(mousepos); //获得鼠标位置
case msg.LParam of
WM_LBUTTONUP: //在托盘区点右键
begin
FHXMain.Visible := not FHXMain.Visible; // 隐示从窗体取可 hexagonal wire mesh,
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); //隐藏窗体,先删除托盘区的图标
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);//正在义务栏隐示窗体
Refresh;
end;
WM_RBUTTONUP: pm1.Popup(mousepos.X, mousepos.Y); //点击弹出菜单
end;
end;procedure TFHXMain.FormShow(Sender: TObject);
begin
//
end;end.
主程序调用时创建它即是了,都是独立的窗体,任务栏会显示图标
至于如何通信。这是另外的问题