Home All Groups Group Topic Archive Search About

Hpw to make a VB6 form appears and gets focus every 15 seconds

Author
2 Feb 2006 12:52 AM
James Ma
In VB6, I need to make a form appears and got focus every, say 15 seconds. I
use code like following in the Timer event handler. But it doesn't appear
after it lost focus (only blinking on the task bar). Do you know how to
achieve the effect? Need to use Win32 API and WM_ACTIVATE? PostMessage or
SendMessage?

Private Sub Timer1_Timer()
    Me.Show        ' Even this does not make it appear!
    Me.SetFocus
End Sub

Many thanks in advance.
James

Author
2 Feb 2006 1:27 AM
Karl E. Peterson
James Ma wrote:
> In VB6, I need to make a form appears and got focus every, say 15
> seconds. I use code like following in the Timer event handler. But it
> doesn't appear after it lost focus (only blinking on the task bar).
> Do you know how to achieve the effect? Need to use Win32 API and
> WM_ACTIVATE? PostMessage or SendMessage?
>
> Private Sub Timer1_Timer()
>     Me.Show        ' Even this does not make it appear!
>     Me.SetFocus
> End Sub

Microsoft, and many users, decided this to be RUDE behavior, by definition,
many years ago.  To ignore that judgement, see
http://vb.mvps.org/samples/ForceFore
--
Working without a .NET?
http://classicvb.org/
Author
2 Feb 2006 5:36 PM
James Ma
Thanks for your help.

I need the effect because I'm maintaining a project that uses Janus GridEX
2000 and the application is designed to run without human intervention.
Somehow the Janus Grid's sort function can only work well when it's visible
ang focused. That's why. I am not intended to annoy anyone, actually I was
annoyed by the gird.

Thanks and I'll try it.

Show quoteHide quote
"Karl E. Peterson" wrote:

> James Ma wrote:
> > In VB6, I need to make a form appears and got focus every, say 15
> > seconds. I use code like following in the Timer event handler. But it
> > doesn't appear after it lost focus (only blinking on the task bar).
> > Do you know how to achieve the effect? Need to use Win32 API and
> > WM_ACTIVATE? PostMessage or SendMessage?
> >
> > Private Sub Timer1_Timer()
> >     Me.Show        ' Even this does not make it appear!
> >     Me.SetFocus
> > End Sub
>
> Microsoft, and many users, decided this to be RUDE behavior, by definition,
> many years ago.  To ignore that judgement, see
> http://vb.mvps.org/samples/ForceFore
> --
> Working without a .NET?
> http://classicvb.org/
>
>
>
Author
2 Feb 2006 6:09 PM
Karl E. Peterson
James Ma wrote:
> Thanks for your help.
>
> I need the effect because I'm maintaining a project that uses Janus
> GridEX 2000 and the application is designed to run without human
> intervention. Somehow the Janus Grid's sort function can only work
> well when it's visible ang focused. That's why. I am not intended to
> annoy anyone, actually I was annoyed by the gird.

Yes, we all have our "reasons." <g>
--
Working without a .NET?
http://classicvb.org/
Author
2 Feb 2006 4:22 AM
LoVe ScoRpiOn
James Ma wrote:
Show quoteHide quote
> *In VB6, I need to make a form appears and got focus every, say 15 > seconds. I
> use code like following in the Timer event handler. But it doesn't > appear
> after it lost focus (only blinking on the task bar). Do you know how > to
> achieve the effect? Need to use Win32 API and WM_ACTIVATE? > PostMessage or
> SendMessage?
>
> Private Sub Timer1_Timer()
> Me.Show        ' Even this does not make it appear!
> Me.SetFocus
> End Sub
>
> Many thanks in advance.
> James *



I am  VB beginner 
but
i think u may  do that  by using 2 timers
i tried  and it worked
try this
Private Sub Form_Load()
Me.Hide

End Sub

Private Sub Timer1_Timer()

Timer1.Interval = 15000
Me.Show
Me.SetFocus


End Sub

Private Sub Timer2_Timer()
Timer2.Interval = 16000 
' change this interval to increase form show time
Me.Hide
End Sub

----

@_@ -- LoVe ScoRpiOn ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------
Author
2 Feb 2006 5:20 AM
Mike Williams
"James Ma" <Jame***@discussions.microsoft.com> wrote in message
news:B6E2088D-6F72-4209-8C87-3EB577D9C5ED@microsoft.com...

> In VB6, I need to make a form appears and got focus every, say 15 seconds.

Who are you trying to annoy?

Mike
Author
2 Feb 2006 4:40 PM
Grant
you?


Show quoteHide quote
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message
news:%23hdGzh7JGHA.584@tk2msftngp13.phx.gbl...
> "James Ma" <Jame***@discussions.microsoft.com> wrote in message
> news:B6E2088D-6F72-4209-8C87-3EB577D9C5ED@microsoft.com...
>
>> In VB6, I need to make a form appears and got focus every, say 15
>> seconds.
>
> Who are you trying to annoy?
>
> Mike
>
>
Author
2 Feb 2006 4:39 PM
Grant
try me.zorder



Show quoteHide quote
"James Ma" <Jame***@discussions.microsoft.com> wrote in message
news:B6E2088D-6F72-4209-8C87-3EB577D9C5ED@microsoft.com...
> In VB6, I need to make a form appears and got focus every, say 15 seconds.
> I
> use code like following in the Timer event handler. But it doesn't appear
> after it lost focus (only blinking on the task bar). Do you know how to
> achieve the effect? Need to use Win32 API and WM_ACTIVATE? PostMessage or
> SendMessage?
>
> Private Sub Timer1_Timer()
>    Me.Show        ' Even this does not make it appear!
>    Me.SetFocus
> End Sub
>
> Many thanks in advance.
> James
>
Author
2 Feb 2006 6:05 PM
James Ma
Cool. The ForceFore also works but not as good as yours. Now I post my final
code to share with you.

Private Sub Timer1_Timer()
    If Me.WindowState = vbMinimized Then Me.WindowState = vbNormal
    Me.ZOrder
    Me.SetFocus
End Sub

Thanks again.
James

Show quoteHide quote
"Grant" wrote:

> try me.zorder
>
>
>
> "James Ma" <Jame***@discussions.microsoft.com> wrote in message
> news:B6E2088D-6F72-4209-8C87-3EB577D9C5ED@microsoft.com...
> > In VB6, I need to make a form appears and got focus every, say 15 seconds.
> > I
> > use code like following in the Timer event handler. But it doesn't appear
> > after it lost focus (only blinking on the task bar). Do you know how to
> > achieve the effect? Need to use Win32 API and WM_ACTIVATE? PostMessage or
> > SendMessage?
> >
> > Private Sub Timer1_Timer()
> >    Me.Show        ' Even this does not make it appear!
> >    Me.SetFocus
> > End Sub
> >
> > Many thanks in advance.
> > James
> >
>
>
>
Author
2 Feb 2006 6:10 PM
Karl E. Peterson
James Ma wrote:
> Cool. The ForceFore also works but not as good as yours. Now I post
> my final code to share with you.
>
> Private Sub Timer1_Timer()
>     If Me.WindowState = vbMinimized Then Me.WindowState = vbNormal
>     Me.ZOrder
>     Me.SetFocus
> End Sub

Ah...  I naturally assumed you had tried the native methods, and they
weren't working because your application didn't have focus at the time it
attempted to steal it.  Save ForceFore for times such as that.
--
Working without a .NET?
http://classicvb.org/
Author
2 Feb 2006 6:46 PM
J French
Show quote Hide quote
On Thu, 2 Feb 2006 10:10:41 -0800, "Karl E. Peterson" <k***@mvps.org>
wrote:

>James Ma wrote:
>> Cool. The ForceFore also works but not as good as yours. Now I post
>> my final code to share with you.
>>
>> Private Sub Timer1_Timer()
>>     If Me.WindowState = vbMinimized Then Me.WindowState = vbNormal
>>     Me.ZOrder
>>     Me.SetFocus
>> End Sub

>Ah...  I naturally assumed you had tried the native methods, and they
>weren't working because your application didn't have focus at the time it
>attempted to steal it.  Save ForceFore for times such as that.

Surely the 'native' methods will not steal focus under XP
- although they work under Win 9x

J M must be using Win 9x   (??)
Author
2 Feb 2006 7:02 PM
Karl E. Peterson
J French wrote:
Show quoteHide quote
> On Thu, 2 Feb 2006 10:10:41 -0800, "Karl E. Peterson" <k***@mvps.org>
> wrote:
>
>> James Ma wrote:
>>> Cool. The ForceFore also works but not as good as yours. Now I post
>>> my final code to share with you.
>>>
>>> Private Sub Timer1_Timer()
>>>     If Me.WindowState = vbMinimized Then Me.WindowState = vbNormal
>>>     Me.ZOrder
>>>     Me.SetFocus
>>> End Sub
>
>> Ah...  I naturally assumed you had tried the native methods, and they
>> weren't working because your application didn't have focus at the
>> time it attempted to steal it.  Save ForceFore for times such as
>> that.
>
> Surely the 'native' methods will not steal focus under XP
> - although they work under Win 9x

SetForegroundWindow was actually redefined at the Windows98/2000 level,
so...

> J M must be using Win 9x   (??)

That's one possibility (either NT4 or less, or Win95).

   http://vb.mvps.org/articles/ap199902.pdf

Another is that some other window in his app/process has focus.
--
Working without a .NET?
http://classicvb.org/
Author
2 Feb 2006 6:56 PM
James Ma
Finally I find I have to use ForceFore.

You know what? Just now I tested the 3 methods (the ForceFore forks 2
methods) on several computers in my shop (winXP pros, Citrix on win2k, citrix
on win2003), found only ForceFore can always work, but still a bit annoyed
because it brings another 2 forms visible though not focused. But that is
enough to solve my headache. So I decide to use ForceFore method finally. I
guess that might be related to VB6SP6, since only I installed it on my
machine.

Thanks a lot to all of you.
James

Show quoteHide quote
"Karl E. Peterson" wrote:

> James Ma wrote:
> > Cool. The ForceFore also works but not as good as yours. Now I post
> > my final code to share with you.
> >
> > Private Sub Timer1_Timer()
> >     If Me.WindowState = vbMinimized Then Me.WindowState = vbNormal
> >     Me.ZOrder
> >     Me.SetFocus
> > End Sub
>
> Ah...  I naturally assumed you had tried the native methods, and they
> weren't working because your application didn't have focus at the time it
> attempted to steal it.  Save ForceFore for times such as that.
> --
> Working without a .NET?
> http://classicvb.org/
>
>
>
Author
2 Feb 2006 7:05 PM
Karl E. Peterson
James Ma wrote:
> Finally I find I have to use ForceFore.
>
> You know what? Just now I tested the 3 methods (the ForceFore forks 2
> methods) on several computers in my shop (winXP pros, Citrix on
> win2k, citrix on win2003),

So much for the Win95/NT4 theory! <g>

> found only ForceFore can always work,

Just about.  Not always.  See http://vb.mvps.org/articles/ap199902.pdf for
one more known exception.

> still a bit annoyed because it brings another 2 forms visible though
> not focused.

There must be a parent/child relation between them, then?  That's not
"normal" behavior, but could be possible if that's the way your application
is designed.

> But that is enough to solve my headache. So I decide to
> use ForceFore method finally. I guess that might be related to
> VB6SP6, since only I installed it on my machine.

The ability to push a window to the front was altered in Windows 98 and
Windows 2000.  VB really doesn't enter into the picture, unless you're
seeing different results in the IDE versus an EXE.
--
Working without a .NET?
http://classicvb.org/
Author
2 Feb 2006 7:38 PM
James Ma
I built the ForceFore code and directly used the EXE to do the tests. So the
ForceFore form is fully seperated from the 2 forms that belong to another EXE.


Show quoteHide quote
"Karl E. Peterson" wrote:

> > still a bit annoyed because it brings another 2 forms visible though
> > not focused.
>
> There must be a parent/child relation between them, then?  That's not
> "normal" behavior, but could be possible if that's the way your application
> is designed.
>
> The ability to push a window to the front was altered in Windows 98 and
> Windows 2000.  VB really doesn't enter into the picture, unless you're
> seeing different results in the IDE versus an EXE.
> --
Author
2 Feb 2006 8:38 PM
Karl E. Peterson
James Ma wrote:
> I built the ForceFore code and directly used the EXE to do the tests.
> So the ForceFore form is fully seperated from the 2 forms that belong
> to another EXE.

I honestly can't imagine why that may be.  There's something else afoot.
--
Working without a .NET?
http://classicvb.org/
Author
2 Feb 2006 7:53 PM
J French
On Thu, 2 Feb 2006 11:05:57 -0800, "Karl E. Peterson" <k***@mvps.org>
wrote:

<snip>

>The ability to push a window to the front was altered in Windows 98 and
>Windows 2000.  VB really doesn't enter into the picture, unless you're
>seeing different results in the IDE versus an EXE.

I'm sure there was a similar problem in NT before 1998

Sadly my memory from 1996 is a little raddled

.... JM must have owning or owned Forms being pushed up
Author
2 Feb 2006 9:59 PM
Tom Esh
On Thu, 2 Feb 2006 10:56:17 -0800, "James Ma"
<Jame***@discussions.microsoft.com> wrote:

>..., but still a bit annoyed
>because it brings another 2 forms visible though not focused.

I think you may be describing the "normal" (or abnormal depending on
your POV) way VB links the zording of all top-level forms in an app.
By default they're all "owned" by the non-visible
"ThunderMain...whatever" class window, which links their z-order just
like specifying the Ownerform arg with the Show statement. Same thing
happens if you have multiple forms and click the taskbar button for
one of them - they ~all~ get a zorder bump. However you can easily
"fix" that behavior if you want by using the API to de-couple the
ownership. Note this is for normal top-level forms, ~not~ MDI.

'declares....
Public Const GWL_HWNDPARENT = (-8)
Public Declare Function SetWindowLong Lib "user32" _
    Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long

'usage...
Private Sub Form_Load()
    SetWindowLong Me.hwnd, GWL_HWNDPARENT, 0
End Sub


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)