Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > trying to open new page in new window


Автор: muratboy31 13.2.2010, 01:35
i am trying to open the page in new window but it doesnt load the page, it opens a blank page and an internet explorer window !!!

Код

procedure Tform1.NewWindowEvent(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
var
s:string;
begin
S:=ExtractFilePath(Application.ExeName)+'Project1.exe';
WinExec(PChar(Format('%s GetActiveEWB.DefaultDispatch',[S])),SW_SHOWNORMAL);
end;

Автор: Mikel 13.2.2010, 12:53
You should use ShellExecute, WinExec is old function and i had some problems with it in Win7/Vista.
http://www.cryer.co.uk/brian/delphi/howto_openbrowserurl.htm
add ShellAPI to uses.

Автор: muratboy31 13.2.2010, 13:08
i used like that ;

Код

procedure Tform1.NewWindowEvent(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
begin
ShellExecute(self.WindowHandle,'open',PChar(GetActiveEWB.DefaultDispatch),nil,nil, SW_SHOWNORMAL);
end;


but it opens internet explorer window, i want to open my project window...

Автор: Mikel 13.2.2010, 13:17
Then you should run your application with URL as parameter http://delphi.about.com/od/windowsshellapi/a/executeprogram.htm
Exe name of your application is "S:=ExtractFilePath(Application.ExeName);", there is no reason to extract file path and then add exename "S:=ExtractFilePath(Application.ExeName)+'Project1.exe';"

And when program is start (for example, OnShow event), get url from ParamStr() value and open it in embedded webbrowser.

Автор: muratboy31 13.2.2010, 13:32
why it says incompatible types HWND and string  ?

Код

procedure Tform1.NewWindowEvent(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
var
s:string;
begin
S:=ExtractFilePath(Application.ExeName);
ShellExecute(s,'open',PChar(GetActiveEWB.DefaultDispatch),nil,nil, SW_SHOWNORMAL);
end;

Автор: amsoft 13.2.2010, 16:28
try this
Код

ShellExecute(handle,'open',S,PChar(GetActiveEWB.DefaultDispatch),nil, SW_SHOWNORMAL);

Автор: muratboy31 13.2.2010, 16:40
it gives error      incompatible types 'String' and 'PAnsiChar'

Код

var
s:string;
ShellExecute(handle,'open',S,PChar(GetActiveEWB.DefaultDispatch),nil, SW_SHOWNORMAL);

Автор: amsoft 13.2.2010, 17:08
you have to convert string to PChar first
try this:

Код

var
s:string;
ShellExecute(handle,'open',PChar(S),PChar(GetActiveEWB.DefaultDispatch),nil, SW_SHOWNORMAL);

Автор: muratboy31 13.2.2010, 17:15
ok no error but it opens the folder(filepath) and also an internet explorer window...
i am trying to open new window with my project...

Автор: amsoft 13.2.2010, 17:26
Код

ShellExecute(handle,'open',PChar(Application.ExeName),PChar(GetActiveEWB.DefaultDispatch),nil, SW_SHOWNORMAL);

Автор: muratboy31 13.2.2010, 17:33
this opened my project window with a blank page and also an internet explorer window with the correct link...

Автор: amsoft 13.2.2010, 17:45
you have to use function ParamStr(1) in your application to determine the sended parameter and then do what you want

Автор: muratboy31 13.2.2010, 18:16
can u please explain me how to use it ? i have no idea !!!

Автор: amsoft 13.2.2010, 18:38
For example:
You need to start application and open some text file

1. start application with parameter (the parameter is name of the text file you want to open):
Код

ShellExecute(handle,'open',<application name>,<parameter>,nil, SW_SHOWNORMAL);

2. in the event OnCreate of main form of your application write the code:
Код

var
S: string;
...
S := ParamStr(1);
Memo1.Lines.LoadFromFile(S);



Автор: muratboy31 13.2.2010, 19:24
ok 1 question,
i use ini file to load the home page anyway on form create and the question is ;
can i use this ini line as parameter ???

Автор: amsoft 13.2.2010, 19:44
You can use any string as parameter

Автор: muratboy31 14.2.2010, 00:24
am i doing it wrong ?

Код

procedure TForm1.FormCreate(Sender: TObject);
var  
  ini1 : TINIFile;
  S : string;
begin
  S := ParamStr(1);
  ini1 := TINIFile.Create( ExtractFilePath(Application.ExeName)+'Ayar.INI ');
  S:= ini1.ReadString('AnaSayfa','Adres','');
  ini1.Free;
  CreateNewTabBrowser(S);
end;



Автор: amsoft 14.2.2010, 12:08
if you work with ini-file so simply read needed parameter directly from this file.
it's not nessesary to send any parameter in this case

Добавлено через 3 минуты и 48 секунд
Discribe what you want.
Your application must open file which name is in parameter or just open file which name is in ini-file.

Автор: muratboy31 14.2.2010, 13:09
you know internet explorer has a function that opens the link in a new window of internet explorer... 
i want to make the same thing with my browser but open the link with my browser's new window not internet explorer... 


Автор: amsoft 14.2.2010, 20:44
In your case during application start first check sended parameter (ParamStr(1)).
If this parameter is not empty than load file which name is in the parameter.
If this parameter is empty than load file which name is in ini-file.

Автор: muratboy31 15.2.2010, 17:42
i tried this also but it didnt work either...  smile 
it doesnt open my project window !!!

Код

procedure Tform1.NewWindowEvent(Sender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
var
ts: string;
begin
with TRegistry.Create do
try
rootkey := HKEY_CLASSES_ROOT;
OpenKey('\htmlfile\shell\open\command', False);
try
ts := ReadString('');
except
ts := '';
end;
CloseKey;
finally
Free;
end;
if ts = '' then Exit;
ts := Copy(ts, Pos('"', ts) + 1, Length(ts));
ts := Copy(ts, 1, Pos('"', ts) - 1);
ShellExecute(self.WindowHandle, 'open', PChar(ts), PChar(GetActiveEWB.DefaultDispatch), nil, SW_SHOW);
end;

Автор: muratboy31 15.2.2010, 18:24
can u please help me with the example attached ?
right click on any link on the page and choose open in new window...

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)