Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set focus to a form
Message
From
15/08/2017 05:13:59
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
14/08/2017 16:29:48
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01653292
Message ID:
01653306
Views:
80
>Hi friends:
>
>Most of my programs when they are started lose the focus. This is not a big problem because most of the users just click on the initial form, write their user names and password and go in very fast. They're hurry...
>
>But now I want a program to start with Windows and no one is going to be there anxious for go in... In fact is just a price query. The user has to scan a codebar and the program should show the price... But as the only form don't have the focus she can scan till the final judgment.
>
>Does anyone knos any trick for set the focus to a particular program in windows?

Not for the faint of heart...
	DECLARE LONG FindWindow IN Win32API STRING, STRING

	nHWND = FindWindow(NULL,_SCREEN.CAPTION)

	IF nHWND >0
		=ForceForegroundWindow(nHWND)
	ENDIF


PROCEDURE ForceForegroundWindow(lnHWND)

	LOCAL nForeThread, nAppThread

	DECLARE LONG BringWindowToTop IN Win32API LONG
	DECLARE INTEGER GetCurrentThreadId IN kernel32
	DECLARE INTEGER GetWindowThreadProcessId IN user32;
		INTEGER   HWND,;
		INTEGER @ lpdwProcId
	DECLARE INTEGER AttachThreadInput IN user32 ;
		INTEGER idAttach, ;
		INTEGER idAttachTo, ;
		INTEGER fAttach
	DECLARE INTEGER GetForegroundWindow IN user32
	DECLARE INTEGER "ShowWindow" IN win32api AS ShowWindowAPI ;
		INTEGER HWND,;
		INTEGER nCmdShow


	nForeThread = GetWindowThreadProcessId(GetForegroundWindow(), 0)
	nAppThread = GetCurrentThreadId()

	IF nForeThread != nAppThread
		AttachThreadInput(nForeThread, nAppThread, .T.)
		BringWindowToTop(lnHWND)
		ShowWindowAPI(lnHWND,1)
		AttachThreadInput(nForeThread, nAppThread, .F.)
	ELSE
		BringWindowToTop(lnHWND)
		ShowWindowAPI(lnHWND,1)
	ENDIF

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform