Microsoft KB Archive/96540

= Display Window Title with GetFocus and GetWindowText =

Article ID: 96540

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a

-



This article was previously published under Q96540



SUMMARY
The sample code below displays the title of the window that has the focus. It demonstrates how to use the FOXTOOLS.FLL library commands to call the following Microsoft Windows application programming interface (API) functions: GetFocus GetWindowText



MORE INFORMATION
The program first loads the FOXTOOLS.FLL library that is supplied with FoxPro for Windows and creates a variable. Next, it retrieves the handle to the window that has the focus, that is, the currently active window. It then calls the GetWindowText function, passing the second parameter by reference by using the @ sign. This is the variable that will hold the title of the window. It then displays the window title. set library to sys(2004)+&quot;foxtools.fll&quot; additive

* create a string variable to hold the title * and initialize it with blank characters

place = replicate(chr(32),80)

* get the handle to the window

gethwnd = RegFN(&quot;GetFocus&quot;,&quot;&quot;,&quot;I&quot;) hwnd = CallFN(gethwnd)

* call the Windows function to get the title * using pass by reference for the variable place

gettitle = RegFN(&quot;GetWindowText&quot;,&quot;I@CI&quot;,&quot;I&quot;) = CallFN(gettitle,hwnd,@place,80)

* display the window title * the output ends with a null character

? &quot;The window title is: &quot; + alltrim(place)

release library sys(2004)+&quot;foxtools.fll&quot;

