Mark Forums Read
  #1  
Old 04-13-2009, 10:30 AM
ajit22 ajit22 is offline
Member
 
Join Date: Jan 2009
Posts: 54
ajit22 is on a distinguished road
Default Bring Window To Front Periodically

You can use a timer to call self.focus() for this, that is triggered whenever the window loses focus by detecting the onblur event. Add onBlur="setTimeout('self.focus()',500)" to the window's body tag, like this:

<body onBlur="setTimeout('self.focus()',500)">

The 500 is the time interval, in milliseconds. (1000 milliseconds is 1 second). Usually a range of 300-7000 will keep the window comfortably in front. Unlike a simple onblur="self.focus();" the window does not behave modally.
__________________
New York Web design
Website design

Reply With Quote
 #Add to Ads's Reputation  
OldSponsored Ads
Ads AdsPromoter is online
Member
 
Join Date: LongTime
Posts: 1100
Ads is on a distinguished road
Default New Sponsored Ads



This message will go away once you are registered. Also, by registering, you will have access to all post topics, communicate privately with other members (PM), respond to polls, upload graphics, and access other special features! Registration is fast, simple and absolutely free so please Click Here to join our Web Hosting community today!
Reply With Quote
  #2  
Old 06-25-2009, 09:30 AM
gkumar gkumar is offline
Senior Member
 
Join Date: Jun 2009
Posts: 203
gkumar is on a distinguished road
Default Bring Window To Front Periodically

Hi at all,

for my applikation I need on incoming message, if the window is in background, that it comes to foreground. The option if the window has come to front is changeable.
I tried it with SetForegroundWindow.
Following is happen.
If I start the applikation with the option is set, it works fine under XP, Vista, W2K3.
Now without starting the app new ich change the option and the window stays in background. Correct so far. Yet I switch the option back to bring the window to front.
Under Vista it works fine but under XP and W2K3 the applikation just blinking in the tastbar.

Now I tried to do it following:-
Quote:
BOOL CMyViewClass::ForceForegroundWindow(HWND hWnd)
{
if(!hWnd || !::IsWindow(hWnd))
return FALSE;

HWND hWndCurrentWindow = ::GetForegroundWindow();
if(hWndCurrentWindow == NULL)
{
return ::SetForegroundWindow(hWnd);
}

DWORD dwCurProcId, dwCurThreadId = ::GetWindowThreadProcessId(hWndCurrentWindow, &dwCurProcId);
DWORD dwHWndProcId;
::GetWindowThreadProcessId(hWnd, &dwHWndProcId);

BOOL bReturn = FALSE;

if(dwHWndProcId == dwCurProcId)
{
bReturn = ::SetForegroundWindow(hWnd);
}
else
{
DWORD dwMyThreadId = ::GetCurrentThreadId();

if(::AttachThreadInput(dwMyThreadId, dwCurThreadId, TRUE))
{
//bReturn = ::SetForegroundWindow(hWnd);
HWND hActiveWnd = ::SetActiveWindow(hWnd);
if(hActiveWnd == NULL)
bReturn = ::SetForegroundWindow(hWnd);
else
bReturn = ::SetForegroundWindow(hActiveWnd);
//::SetFocus(hWnd);
::AttachThreadInput(dwMyThreadId, dwCurThreadId, FALSE);
}
else
{
bReturn = ::SetForegroundWindow(hWnd);
}
}

return bReturn;
}
The problem stays. With the Method SetActiveWindow nothing happens!
Now I have read that I could bring the window to front with SetWindowPos().

I´ve tried it in 3 ways:-

Quote:
//1.)
this->SetWindowPos(&CWnd::wndTopMost, 0 ,0, 0, 0, SWP_SHOWWINDOW|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOZORDE R);
//2.)
this->SetWindowPos(&CWnd::wndTopMost, 0 ,0, 0, 0, SWP_SHOWWINDOW|SWP_NOREDRAW|SWP_NOSIZE);
//3.)
this->SetWindowPos(&CWnd::wndTopMost, 0 ,0, 0, 0, SWP_SHOWWINDOW);
But with none of these tries the window come to front.
If it is really running to bring window to front with SetWindowPos can anyone explain me
how to use the method that it works???
Reply With Quote
 #Add to Ads's Reputation  
OldSponsored Ads
Ads AdsPromoter is online
Member
 
Join Date: LongTime
Posts: 1100
Ads is on a distinguished road
Default New Sponsored Ads



This message will go away once you are registered. Also, by registering, you will have access to all post topics, communicate privately with other members (PM), respond to polls, upload graphics, and access other special features! Registration is fast, simple and absolutely free so please Click Here to join our Web Hosting community today!
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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


Powered by vBulletin Version 3.6.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 2.4.0