出200分问一个比较简单的问题!

THE_ROCK 2002-07-15 02:35:53
我的程序是一个多窗口的浏览器,目前能作到与Html文件关联起来,用鼠标右键选择本程序来打开一个网页文件后,然后再选择一个网页文件来打开就不行了,程序接收不到第二个网页文件!我希望程序在打开多个网页文件时,能够无须再次运行程序,因为本程序是多窗口的。希望能让程序新建窗口来打开。我在FormShow事件中有这样的代码:
if FileExists(ParamStr(1)) then
begin
OpenUrl(ParamStr(1));
end;

...全文
35 29 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
delphimm 2002-07-22
  • 打赏
  • 举报
回复
up
zzwu 2002-07-22
  • 打赏
  • 举报
回复

另外,启动一次,总只有一个文件名为ParamStr(1).

所以,要显示2个或多个文件,必须多次启动.
zzwu 2002-07-22
  • 打赏
  • 举报
回复
我对你的程序:

if FileExists(ParamStr(1)) then
begin
OpenUrl(ParamStr(1));
end;


能不能实现打开多个文件表示怀疑.

ParamStr(1)怎样能体现是变化的你呢?

另外,我不知道你的程序是如何启动的,用命令行启动吗? 否则,ParamStr(1)何处来呢?
kanghl 2002-07-22
  • 打赏
  • 举报
回复
学习。
ehom 2002-07-21
  • 打赏
  • 举报
回复
procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;

procedure TForm1.WMCopyData(var Msg: TWMCopyData);
var
ParamString: string;
begin
with Msg.CopyDataStruct^ do
begin
ParamString := StrPas(PChar(lpData));
end;
end;

接收!
ehom 2002-07-21
  • 打赏
  • 举报
回复
第二个网页用sendmessage发送啊!

program Project1;

uses
Windows,
Messages,
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

var
AppWnd, MainWnd: HWND;

I: Integer;
ParamString: string;

CopyDataStruct: TCopyDataStruct;
begin
AppWnd := FindWindow('TApplication', 'This is my project title');
if AppWnd <> 0 then
begin
if IsIconic(AppWnd) then
ShowWindow(AppWnd, SW_RESTORE)
else
SetForegroundWindow(AppWnd);
MainWnd := GetProp(AppWnd, 'Main Form Handle');
ParamString := ParamStr(1);
CopyDataStruct.cbData := Length(ParamString) + 1;
CopyDataStruct.lpData := PChar(ParamString);
SendMessage(MainWnd, WM_COPYDATA, 0, LPARAM(@CopyDataStruct));
Exit;
end;

Application.Initialize;
Application.Title := 'TEST';
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
del_c_sharp 2002-07-21
  • 打赏
  • 举报
回复
在主程序中加入:
h:=findwindow('formtext'....)
if h<>0 then
begin
setforegroundwindow(h);
...根据参数生成新的子窗体

end
else
正常创建主窗体
delphimm 2002-07-21
  • 打赏
  • 举报
回复
up
CXZ9 2002-07-21
  • 打赏
  • 举报
回复
UP
============================
@* .☆ / */ . / * . ☆/ *。
◢◣。 ◢◣。
◢★◣。 ◢★◣。
◢■■◣。 ◢■■◣。
◢■■■◣。 ◢■■■◣。
︸︸||︸︸ !!︸︸||︸︸
愿您有快乐的每一天 ^_^!!
stargazer 2002-07-21
  • 打赏
  • 举报
回复
你的问题的实质是如何只运行程序的一个实例,要达到这个目的,方法很多,比如 del_c_sharp(feifei)的方法。
不过我认为使用Mutex是个比较好的办法。
程序创建时调用CreateMutex创建一个Mutex,然后判断该对象是否存在,如存在,表明程序已经有一个实例,此时可以调用EnumWindows枚举当前系统中的实例,找到后就激活当前的实例,让它处理html文件(具体方法ehom网友写的很清楚)
ehom 2002-07-21
  • 打赏
  • 举报
回复
注意第一段代码是加在工程文件DPR中!
ehom 2002-07-21
  • 打赏
  • 举报
回复
AppWnd := FindWindow('TApplication', 'This is my project title');
改为
AppWnd := FindWindow('TApplication', 'Test');
Ehomsoft 2002-07-21
  • 打赏
  • 举报
回复
up
ehom 2002-07-21
  • 打赏
  • 举报
回复
然后在接收代码里新建窗口,打开网页,网页地址为 ParamString
huamin 2002-07-20
  • 打赏
  • 举报
回复
好象不简单
floattofool 2002-07-20
  • 打赏
  • 举报
回复
代码没错
tangss 2002-07-20
  • 打赏
  • 举报
回复
帮你UP
riddler 2002-07-20
  • 打赏
  • 举报
回复
用activex控件,他支持多线程
shao528 2002-07-20
  • 打赏
  • 举报
回复
同意delphi1234(披着羊皮的狼) ,你的代码没有错,但放错了地方,可以写在工程代码里。
Xinhao 2002-07-20
  • 打赏
  • 举报
回复
用WebBrowers控件试试!
加载更多回复(9)

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧