Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2008, 07:17 AM
nester261 nester261 is offline
Moderator
 
Join Date: Jan 2004
Location: UK
Posts: 617
Default SetForegroundWindow not working on Vista

Hi,

I have registered File Types for my program and once my program is executed I need the Main Form to become TopMost.

It is working perfectly without issues on my development machine which is running Windows XP Pro. However I then tested it on another computer also running WinXP Pro but the window would just flash 3 times and remain under the window where I was launching the associated files from.

I fixed the issue on the XP machine by setting ForegroundLockTimeout to (0) in the registry under the Key:
HKEY_CURRENT_USER\Control Panel\Desktop It was set to 200000 by default.

Now in Vista this registry key was also set the same value - (200000) and I have reset it to (0) however it has no effect and the window still does not become TopMost.

I have tried everything I can think of in Vista to get the form TopMost even using a function to Force it but nothing seems to work! The Form will just stay under the Window and flash 3 times.

Does anyone have any ideas or what I could do to solve this?

Many thanks

Nester261

"Where there's a will, there's always a way."

-- The Hon Robert Nester Marley O.M. - aka Bob Marley!
Reply With Quote
  #2  
Old 07-14-2008, 07:25 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,841
Default RE: SetForegroundWindow not working on Vista

Try:

[DELPHI]self.BringToFront;
//Or
Windows.SetForegroundWindow(self.Handle);[/DELPHI]

Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 07-14-2008, 07:39 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,841
Default RE: SetForegroundWindow not working on Vista

Also see help for "SetWindowPos" API.

Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
Old 07-14-2008, 08:31 AM
nester261 nester261 is offline
Moderator
 
Join Date: Jan 2004
Location: UK
Posts: 617
Default RE: SetForegroundWindow not working on Vista

Hi,

Thanks for your reply. I have tried what you suggested but on Vista for some reason nothing is working to bring the Window to the front!

I have tried:
  • Application.BringToFront;
  • SetForeGroundWindow(Self.Handle);
  • Windows.SetForeGroundWindow(Self.Handle);
  • ForceForeground(Self.Handle); <-- Called from a function
  • Self.BringToFront;
  • Application.MainForm.BringToFront;
  • Main.BringToFront;

The only thing I can get working is SetWindowPos like you suggested but I have to unset it twice once the Form is TopMost to prevent it becoming stuck.

The only thing I can think is causing this in my program is that to make it Vista compatible I have had to override CreateParams and listen to messages from WMSyscommand, and, WMActivate.

I am not sure if this would cause any problems though? Do you think? * My program crashes if I do not override CreateParams *

I will mark as solved in a moment, I have just one more idea to try.

Many thanks

Nester261

"Where there's a will, there's always a way."

-- The Hon Robert Nester Marley O.M. - aka Bob Marley!
Reply With Quote
  #5  
Old 07-14-2008, 10:52 AM
nester261 nester261 is offline
Moderator
 
Join Date: Jan 2004
Location: UK
Posts: 617
Default RE: SetForegroundWindow not working on Vista

ok after much testing and playing around I have nailed it down to being the ForegroundLockTimeout registry setting in Windows Vista.

When I changed it from (200000) to (0) there was no effect until I Rebooted and now the Form is becoming TopMost.

The same happens in reverse, if I set it back to (200000) it will not take effect untill a Reboot has taken place.

Note
** This does not happen on Windows XP ** I am going to test it on Windows 2k as soon as I have posted this.

...so now my question would be can this be avoided? Can I force Windows Vista to do this before a Reboot is needed?

I did also try just restarting Explorer.exe to see if this would have any effect on things, but no it did not! (it was worth a try).

Many thanks

Nester261

"Where there's a will, there's always a way."

-- The Hon Robert Nester Marley O.M. - aka Bob Marley!
Reply With Quote
  #6  
Old 07-14-2008, 11:55 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,841
Default RE: SetForegroundWindow not working on Vista

I played with Vista but never liked it. I still use XP pro SP2. To tell you the truth, I can play with Windows APIs but not with (a buggy OS like Vista). They will clean it up for sure or perhaps replace it with a new one (for there lake in unable to convenience people to accept it as a good replacement for XP). But at this point I have no idea.

Regards,
Abdulaziz Jasser
Reply With Quote
  #7  
Old 07-14-2008, 12:03 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,841
Default RE: SetForegroundWindow not working on Vista

Not really I good idea (al least in your case), but why not reboot by code immediately after making the change?

This is only to avoid the users help until you figure out the problem (or MS comes with a service pack).

Regards,
Abdulaziz Jasser
Reply With Quote
  #8  
Old 07-14-2008, 04:57 PM
nester261 nester261 is offline
Moderator
 
Join Date: Jan 2004
Location: UK
Posts: 617
Default RE: SetForegroundWindow not working on Vista

Hi,

I will check the key the first time File Associations are made then display a message to inform the User and ask them what action they would like taken.

When I tested it in Windows 2000 the ForegroundLockTimeout was also set to (200000) by default. It would seem this is the default in ALL versions of Windows. I cannot confirm this 100% just yet.

Thanks for all your help Jasser

Nester261

"Where there's a will, there's always a way."

-- The Hon Robert Nester Marley O.M. - aka Bob Marley!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:31 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.