Fix your forms to paint borders correctly under Vista Aero
Apparently, the borders of some forms don’t get painted correctly on Windows Vista.
When executing a Fox Form, Fox asks Windows to create a window, then sets the BorderStyle of the window. Apparently, under Vista Aero (except as Administrator), the BorderStyle cannot be set after the Window has been created.
To reproduce the problem, start Visual FoxPro (I tried back to VFP7 (released summer 2001))
- In the property sheet, dbl-click BorderStyle to change it to 1 or 2
- 0 = No border ( no problem, because there are no borders to draw)
- 1 = Fixed Single
- 2 = Fixed Dialog
- 3 = Sizable (Default) (no problem, because it’s the default)
- Hit Ctrl-E or click on the “!” in the toolbar to run the form. Give it a name
- Move the form around so that the borders or title bar will need to be repainted
- Result: The window behaves as if there is no border: it won’t get repainted.
Amazingly enough, run under Admin mode, and you’ll see the problem disappear. Perhaps a non-admin app changing the BorderStyle might be a security risk: An app might be able to grab a window handle from another process and impersonate a Credentials screen or something.
When Fox runs a form, it reads the Properties and sets them in the order encountered. For a Form, the “DoCreate” pseudo property means to create the window. The BorderStyle happens to be written after the DoCreate, so the BorderStyle setting is ignored
The properties look like this before the fix:
Top = 0
Left = 0
Height = 250
Width = 375
DoCreate = .T.
BorderStyle = 1
Caption = "Form1"
Name = "Form1"
So your choices are:
- Open the Form as a table (It really is just a table) and manually put BorderStyle before DoCreate.
- Run the program below that fixes your SCX files by putting the BorderStyle property before the DoCreate
- Convert your SCX forms to VCX (Visual Classes), where the BorderStyle is set at window creation time. (Just choose File->Save As Class from the Form designer)
- Wait for the next release of VFP SP
- Run Vista without Aero
- Run your app as Admin
- Foxpro Menu items, combo boxes not refreshing selected item under Aero in Vista
- Add a manifest to control your application Vista UAC behavior
Program starts below (and works in VFP7 too)
FixDir(CURDIR()) && Call recursive program with current directory
*Recursive program to fix all forms found in cPath and subdirectories
* Fix Vista Aero Border painting by changinge DoCreate and BorderStyle order
PROCEDURE FixDir(cPath) && Fix all forms in directory cPath and subdirectories
n=ADIR(aFiles,cPath+"*.scx") && look in current dir for all form files (.SCX)
FOR i = 1 TO n
USE (cPath+aFiles[i,1]) ALIAS SCX && open the form as a table
SCAN FOR !EMPTY(Properties) AND ATC("DoCreate",Properties)>0 && locate the Properties
nLines = ALINES(aProps,Properties) && Create an array of all the lines in the Properties
FOR j = 1 TO nLines && Loop through and record the array indices of DoCreate and BorderStyle
IF nDoCreate > 0 AND nDoCreate < nBorderStyle && If DoCreate precedes BorderStyle, insert BorderStyle before
FOR nIndex = 1 TO nLines && now emit the properties in the desired order
CASE nIndex = nDoCreate
CASE nIndex = nBorderStyle
* do nothing: already added
REPLACE Properties WITH cTemp && and update
USE IN SCX && close the file
n=ADIR(aFiles,cPath+"*.*","D") && Get any subdirs
FOR i = 1 TO n
IF ATC("D",aFiles[i,5])>0 AND aFiles[i,1] != "."
FixDir(cPath+aFiles[i,1]+"\") && recur
</end of program>