Solved

Execute Application and Resize its Window Size

Posted on 2002-04-20
13
502 Views
Last Modified: 2008-03-06
hi ! i want to execute the MSIE or netscape and define its screen width and height, so that I can simulate diffrent screen resolutions without switching araound.

Any ideas ?
best regards
ItsMe
0
Comment
Question by:ItsMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6956412
hi,
although it should be its not that easy actually as first need to execute the app then unfortunalty executing it doesnt give back the window handle so need to search other windows comparing the procesids till you find the right one that oyu started so you can get from it the actual window handle to use with setwindowpos,movewindow etc..


var
  Form1: TForm1;
  WL : TList;
  TheProcessId : DWORD;
  Si : TStartupInfo;
  Pi : TProcessInformation;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
 h : HWND;
 i : Integer;
 tmpPid : DWORD;
 function GetAllWindows(Handle: HWND; NotUsed: Pointer): Bool; stdcall;
 begin
   Result := True;
   WL.add(pointer(Handle));
 end;
begin
 FillChar(Si,SizeOf(Si),#0);
 FillChar(Pi,SizeOf(Pi),#0);
 if not CreateProcess(nil,pChar('G:\WINNT\system32\notepad.exe'),
                     nil,nil,FALSE,NORMAL_PRIORITY_CLASS,nil,
                     pChar(ExtractFilePath('G:\WINNT\system32\notepad.exe')),
                     Si,Pi) then
   ShowMessage(SysErrorMessage(GetLastError))
 else
WaitForInputIdle(Pi.hProcess, 400);
TheProcessId := Pi.dwProcessId;
try
   WL := TList.Create;
   h  := Handle;
   if not EnumWindows (@GetAllWindows,Longint(@h)) then
     Exit;
   for i := 0 to WL.Count - 1 do
   begin
     GetWindowThreadProcessId(HWND(WL[i]),@tmpPid);
      if tmpPid = TheProcessId then
     begin
      SetWindowPos(HWND(WL[i]),HWND_TOP,0,0,50,100,SW_SHOWNORMAL);
      Break;
     end
     end;
 finally
   WL.Free;
 end;
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
end;


for anything easier to use see www.madshi.net as his units incorporate the windowlist stuff etc already.

Regards Barry
0
 
LVL 17

Expert Comment

by:inthe
ID: 6956414
ps,
i dont know if WaitForInputIdle will be long enough for ie or netscape to execute ,i know they can take some time to start .
0
 

Author Comment

by:ItsMe
ID: 6957489
hi inthe ! thanks for this code. i can change the position of the window now, but the size is always the same. no matter if i change the height / width values. do you know why ?

best regards
ItsMe
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ItsMe
ID: 6957500
ps_ can you tell me why this causes an access violation ?

     GetWindowText (HWND(WL[i]),wintext,GetWindowTextLength(HWND(WL[i])));
0
 

Author Comment

by:ItsMe
ID: 6957507
hi inthe ! i solved the first problem with calling the MoveWindow function with Repaint = True. Now I only have the problem with Wintext ;-)

best regards
ItsMe
0
 

Author Comment

by:ItsMe
ID: 6957831
hi barry !
i've got a second problem: how can i pass parameters to the application ? when i execute iexplore.exe i need to add a file&path to my html page which shall be called.

best regards
ItsMe
0
 
LVL 17

Expert Comment

by:inthe
ID: 6958180
hi itsme,
sorry been away a while :)
to pass parameters with createprocess just add them (with a space first for ex:

 CreateProcess(nil,
        pChar(strpas(Browser)+' F:\Mandrake\nvidia.htm'),
        nil,
        nil,
        FALSE,NORMAL_PRIORITY_CLASS,nil,
        pChar(ExtractFilePath(strpas(Browser))),
        Si,Pi)

ps,
i am using FindExecutable (shellapi) method to get browser so no paths are hardcoded.

about the getwindowtext ,i wonder if did your movewindow actually work?after youve positioned ie it will auto start in the same place.i say cause
i am pretty sure the getwindowtext part isnt working cause the HWND(WL[i]) isnt valid yet .as i mentioned in first comment i think this whole concept is a difficult one as you dont know how long the app takes to start and on each system it will be different.createprocess is actually  returning before the windows are fully created,the various procedures ive been trying in last 1/2 hr all work flawlessly on notepad and some other small app but on ie they are always failing.
if i manualy start ie then do a getwindowtext it is fine but trying it straight after createprocess is just not working here until i put a fairly long sleep in it:
hopefully this is better for you:

uses shellapi;

procedure TForm1.Button1Click(Sender: TObject);
var
h : HWND;
i : Integer;
tmpPid : DWORD;
WinText : Array[0..254] of Char;
T : Textfile;
Dir,browser:array[0..255] of char;
function GetAllWindows(Handle: HWND; NotUsed: Pointer): Bool; stdcall;
begin
  Result := True;
  WL.add(pointer(Handle));
end;
begin
Assignfile(T ,'D:\test.html');
Rewrite(T);
Closefile(T);
FindExecutable('D:\test.html',Dir,browser);
Deletefile('D:\test.html');
//here browser contains full path to web browser
FillChar(Si,SizeOf(Si),#0);
FillChar(Pi,SizeOf(Pi),#0);
if not CreateProcess(nil,pChar(strpas(Browser)+' F:\Mandrake\Install Guide nvidia.htm'),
                    nil,nil,FALSE,NORMAL_PRIORITY_CLASS,nil,
                    pChar(ExtractFilePath(strpas(Browser))),
                    Si,Pi) then
  ShowMessage(SysErrorMessage(GetLastError))
else
 begin
 WaitForInputIdle(Pi.hProcess, 500);
caption := 'finished waiting';
TheProcessId := Pi.dwProcessId;
try
  WL := TList.Create;
  h  := Handle;
  if not EnumWindows (@GetAllWindows,Longint(@h)) then
    Exit;
  for i := 0 to WL.Count - 1 do
  begin
    GetWindowThreadProcessId(HWND(WL[i]),@tmpPid);
     if tmpPid = TheProcessId then
    begin
   sleep(500); //without this its too fast to do the next.
    MoveWindow(HWND(WL[i]),0,0,200,100,True);
    GetWindowText(HWND(WL[i]),@Wintext[0],255);
    Caption := Wintext;
    Break;
    end
    end;
finally
  WL.Free;
end;
end;
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
end;
0
 

Author Comment

by:ItsMe
ID: 6958340
hi inthe,
i tried the same like you did with tzhe parameter. but this didn't work. delphi tells me "path not found".

best regards
ItsMe
0
 

Author Comment

by:ItsMe
ID: 6958343
hi inthe ! everything is working ! it only depends on the length of the window text you specify to read. set it to 10 and you get the first 10 chars. it works !!! but i can't pass a parameter. and i can't get the length of the window's text.
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6961618
hi,
i am having no problems passing a parameter
my actual string is like:

g:\blah\iexporer.exe f:\mandrake\blah.html
and this is opening the file fine in internet explorer

//it only depends on the length of the window text you specify to read
not sure what you mean here ,length is irrelevent i am reading all the title with no problem now using the same as above.
can you post you whole procedure here?
is it much differetnt to above?
0
 

Author Comment

by:ItsMe
ID: 6962091
hi inthe ! my app now doesn't work on other systems than on mine. i will give the other code you posted a try, this evening ;-)

best regards
ItsMe
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6975640
This question is current, others below are not and need your attention.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20274670.html
http://www.experts-exchange.com/questions/Q.20124921.html
http://www.experts-exchange.com/questions/Q.20172193.html
http://www.experts-exchange.com/questions/Q.20279339.html
http://www.experts-exchange.com/questions/Q.20287364.html
http://www.experts-exchange.com/questions/Q.20291705.html
http://www.experts-exchange.com/questions/Q.20290930.html
http://www.experts-exchange.com/questions/Q.20291700.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20261976.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9003744
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from inthe

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question