Link to home
Start Free TrialLog in
Avatar of Mdib
Mdib

asked on

changing focus

I am trying to set the focus to an application other than the calling application. I seem to remember making a call to  SetForegroundWindow in the past yet it doesnt seem to work.  The app is activated by making a call to ShellExecuteEx so i have the Handle. what am i doing wrong. I may be Mistaken and used to call another API in the past. Platform :- win95 Delphi20.
Avatar of olmy
olmy

You should try this

  ShowWindow(Wnd: HWnd; CmdShow: Integer): Bool;

But you need to retrive to windows Hwnd handle to use it, if you know windows classname or windowname.

  FindWindow(Classname, WindowName: PChar): HWnd;
Avatar of Mdib

ASKER

I use winsight to get the handle to the window and use the handle, The function returns success but the window is not bought to the forground..
SetForegroundWindow does work if you pass it the correct handle, but you can't get this handle from ShellExecuteEx, you need to use FindWindow or more likely EnumWindows.

Could you list the window classes and names for the app as reported by WinSight? If so, I'll write you some code.



1. use SetActiveWindow(handle of the window)
2. in order to find the handle of the window use
FindWindow(windowclass,nil)
3. in order to find the class of the window use the spy program.
Avatar of Mdib

ASKER

SetActiveWindow will only bring the window to the forground if the window belongs to the application making the call. I am trying to activate a vindow from a different app.

Avatar of Mdib

ASKER

Comment for Sperling:-

I would appreciate an example of EnumWindows callback. Essentially what i am trying to accomplish is to activate an application. If an instace of that application already exists then simply set the focus to the existing instance. Note that the application is a third party app such as netscape for example so i can not chech for previous instance from within the app. I will know befor hand wich apps i will want to run so i would have no problem making a comparison of the windows class.  If you can think of a better way of doing this I would be glad to hear it. for the purpose of this exercise (EnumWindows) feel free to use any windows class or you can use RegEdit_RegEdit.

thanks
ASKER CERTIFIED SOLUTION
Avatar of sperling
sperling

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mdib

ASKER

Thnaks