Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why the 2 - Top level form is not on focus... 2

Status
Not open for further replies.

fredgmain

IS-IT--Management
Oct 30, 2009
22
MY
Hi all,

I create a simple form (2- Top level) but the form is not in focus until I click on the form (any area or title).

I believed the settings in the form properties is wrong but I cannot figure out why.

Or any command that I can put in the form "Init" or "Activate" section so that the cursor will stop at the fist text field?

Thanks for your help.
Fred
 
You can use this (I have been using successfully), in activate call BringAppInFront( thisform.hwnd ):

Code:
Procedure BringAppInFront(tnHWND)
	Declare Integer GetForegroundWindow In win32API
	Declare Integer GetCurrentThreadId In win32API
	Declare Integer GetWindowThreadProcessId In win32API ;
		integer HWnd, Integer @lpdwProcessId
	Declare short SetForegroundWindow In win32API Integer lnHWnd
	Declare short AttachThreadInput In win32API ;
		integer idAttach, Integer idAttachTo,  short fAttach

	Declare Integer SetActiveWindow In WIN32API Integer HWnd   && handle to window

	Local lpdwProcessId, lnThreadID1, lnThreadID2
	lpdwProcessId = 0
	lnThreadID1 = GetCurrentThreadId()

	lnThreadID2 = GetWindowThreadProcessId( m.tnHWND, @lpdwProcessId)

	AttachThreadInput(m.lnThreadID1, m.lnThreadID2, 1)
	SetForegroundWindow(m.tnHWND)
	SetActiveWindow(m.tnHWND)
	AttachThreadInput(m.lnThreadID1, m.lnThreadID2, 0)
Endproc

Cetin Basoz
MS Foxpro MVP, MCP
 
Fred,

You are not doing anything wrong. You have simply come up against a long-standing quirk (bug?) in VFP.

A simple way of fixing it is to put this code in the form's Init:

THISFORM.AlwaysOnTop = .T.
THISFORM.AlwaysOnTop = .F.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Dear Cetin Basoz

Thank you for your help. It solved my forms' problem.

Regards,
Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top