keep focus on my form
Hi,
I'd like to press the callkey, of the smartphone, with kbd_event method, when there is an incoming call, but, when there is an incoming call, a popup apears end I loose the focus on my program...
So I'd like keep the focus on my form thanks to a loop like this :
DeclareFunction SetForegroundWindowLib "CoreDll.dll" (ByVal hWndAsInteger)AsBoolean hwin =--handleOfMyForm--
while(true)
SetForegroundWindow(hwin)
End While
But how can I get the Handle of my Form?
[1156 byte] By [
jjm] at [2008-1-27]
Ok, thanks Manfred, it runs with this code :
Me
.Capture = True
hwin = GetCapture()
Me.Capture = FalseBut I fact, it doesn't solve my problem, because with this loop, my form is always on top, even if i run an other application, exepted the phonecall popup...
I thinks that this popup do the same thing, she catch the focus in a loop.How could i do ?
jjm at 2007-8-21 >

Hi,
your question was "how can I get the handle of my form".
Now you are asking for another thing.
I'm not very shure if I understand your needs, but I assume:
a.) if your app is in foreground you want to keep the foucs
b.) if your app is in the background it should stay there
So how to solve this.
First get the handle of your window with a call to GetHandle(myForm)
What I forgot (missing line) is the boolean to keep the before state!!!
The line to reset it is there.
So a change to the function is needed:
After declaration of the hwnd add
bool bCapture=theFrm.Capture.
So with this and the line before the return (theFrm.Captur=bCapture) you reset the state.
But that is just a little "helping".
So now to the app:
I would do 3 things:
a.) create a timer (duration as long as possible)
the duration tells the time you are without focus after the popup
b.) create a variable to keep the status of Activation (bool bActive)
c.) create a handler for form activation (Activated)
therein set bActive to true
d.) create a handler for form deactivation (Deactivate)
therein set bActive to false
e.) create a timer handler like this
if(bActive) SetForeGroundWindow(this);
So if your form gets hidden (another app on top) bActive is false - and you stay hidden. If you are the foregroundwindow the popup maybe (!!!!) will result in a Deactivated and after closing an Activate.
If this is the fact you can forget the deactivate handler and the timer.
Use the SetForegroudnWindow directly in this function.
To check it out simply place a textbox and in the handlers add some text to show the statuschanges.
Cheers
Manfred