Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Activate window?
Message
De
23/08/2006 19:31:09
 
 
À
23/08/2006 16:50:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 8
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01147895
Message ID:
01148063
Vues:
20
>>Hi,
>>I use Winsock control. when my application got message from remote computer - the main window must appears in Windows as foreground window (like ALT-TAB switch)
>>
>>SwitchToThisWindow(_screen.HWnd,1)
>>SetForegroundWindow(_screen.HWnd)
>>SetFocusAPI(_screen.HWnd)
>>
>>Not help for me ;(
>>
>>Any idea
>>Thanks
>>Denis
>
>Windows interface guidelines does not allow this to be done, but I see MS apps doing it all the time, you are writing something in one program and another program pops into focus and all your typing is gone...

this is one of the most great WINDOWS's design bug.


>I hate it. So here is the way to torture your users doing the same thing:
>
>For demo purposes, copy/paste into prg:
>
>
>Public oForm
>oForm = Newobject("ffw")
>oForm.Show()
>
>Define Class ffw As Form
>
>	DoCreate = .T.
>	Caption = "Form1"
>	Name = "Form1"
>
>	Add Object timer1 As Timer With ;
>		Top = 204, ;
>		Left = 312, ;
>		Height = 23, ;
>		Width = 23, ;
>		Interval = 5000, ;
>		Name = "Timer1"
>
>	Add Object text1 As TextBox With ;
>		Height = 23, ;
>		Left = 12, ;
>		Top = 24, ;
>		Width = 144, ;
>		Name = "Text1"
>
>	Procedure forceforegroundwindow
>	Lparameters thWnd
>
>	Declare Integer AttachThreadInput In user32;
>		INTEGER idAttach,;
>		INTEGER idAttachTo,;
>		INTEGER fAttach
>
>	Declare Integer GetForegroundWindow In user32
>
>	Declare Integer GetWindowThreadProcessId In user32;
>		INTEGER HWnd,;
>		INTEGER lpdwProcessId
>
>	Declare Integer IsIconic In user32;
>		INTEGER HWnd
>
>	Declare Integer SetForegroundWindow In user32;
>		INTEGER HWnd
>
>	Declare Integer ShowWindow In user32;
>		INTEGER HWnd,;
>		INTEGER nCmdShow
>
>	#Define SW_RESTORE 9
>	#Define SW_SHOW  5
>
>	Local lnThreadID1
>	Local lnThreadID2
>
>	*!*
>	*!* Nothing to do if already in foreground.
>	*!*
>	If Not thWnd = GetForegroundWindow()
>		*!*
>		*!* First need to get the thread responsible for this window,
>		*!* and the thread for the foreground window.
>		*!*
>		m.lnThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(), 0)
>		m.lnThreadID2 = GetWindowThreadProcessId(m.thWnd, 0)
>		*!*
>		*!* By sharing input state, threads share their concept of
>		*!* the active window.
>		*!*
>		If m.lnThreadID1 <> m.lnThreadID2
>			AttachThreadInput(m.lnThreadID1, m.lnThreadID2, 1)
>			SetForegroundWindow(m.thWnd)
>			AttachThreadInput(m.lnThreadID1, m.lnThreadID2, 0)
>		Else
>			SetForegroundWindow(m.thWnd)
>		Endif
>		*!*
>		*!* Restore and repaint
>		*!*
>		If IsIconic(m.thWnd) <> 0
>			ShowWindow(m.thWnd, SW_RESTORE)
>		Else
>			ShowWindow(m.thWnd, SW_SHOW)
>		Endif
>	Endif
>	Endproc
>
>	Procedure timer1.Timer
>	Thisform.forceforegroundwindow(_vfp.HWnd)
>	Thisform.text1.SetFocus
>	Endproc
>
>Enddefine
>
>
>If you use a Top Level Form, use the form hWnd instead of _VFP.hWnd
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform