Solved

Execute Application and Resize its Window Size

Posted on 2002-04-20
13
495 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
13 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ItsMe
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:inthe
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now