Welcome to MSDN Blogs Sign in | Join | Help

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))

  • File->New->Form
  • 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

 

 

 

See also

 

 

Program starts below (and works in VFP7 too)

 

CLEAR ALL

CLEAR

 

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

          LOCAL n,aFiles[1],cPath,i,j,cTemp,nBorderStyle,nDoCreate,aProps[1],nLines,nIndex

          n=ADIR(aFiles,cPath+"*.scx")        && look in current dir for all form files (.SCX)

          FOR i = 1 TO n

                   ?cPath+aFiles[i,1]

                   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

                             ?Properties

                             nLines = ALINES(aProps,Properties)          && Create an array of all the lines in the Properties

                             nDoCreate=0

                             nBorderStyle=0

                             FOR j = 1 TO nLines  && Loop through and record the array indices of DoCreate and BorderStyle

                                      ?j,aProps[j]

                                      DO CASE

                                      CASE ATC("DoCreate",aProps[j])>0

                                                nDoCreate=j

                                      CASE ATC("BorderStyle",aProps[j])>0

                                                nBorderStyle=j

                                      ENDCASE

                             ENDFOR

                             IF nDoCreate > 0 AND nDoCreate  < nBorderStyle         && If DoCreate precedes BorderStyle, insert BorderStyle before

                                      cTemp=""

                                      FOR nIndex = 1 TO nLines   && now emit the properties in the desired order

                                                DO CASE

                                                CASE nIndex = nDoCreate

                                                          cTemp=cTemp+aProps[nBorderStyle]+CHR(13)+CHR(10)

                                                          cTemp=cTemp+aProps[nDoCreate]+CHR(13)+CHR(10)

                                                CASE nIndex = nBorderStyle

                                                          * do nothing: already added

                                                OTHERWISE

                                                          cTemp=cTemp+aProps[nIndex]+CHR(13)+CHR(10)

                                                ENDCASE

                                      ENDFOR

                                     

                                      REPLACE Properties WITH cTemp    && and update

                                      ?properties

                             ENDIF

                   ENDSCAN

                   USE IN SCX    && close the file

          ENDFOR

          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

                   ENDIF

          ENDFOR

         

RETURN

</end of program>

 

Published Friday, April 27, 2007 5:31 PM by Calvin_Hsia
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Fix your forms to paint borders correctly under Vista Aero

Friday, April 27, 2007 9:54 PM by Calvin_Hsia

I've modified the code: instead of swapping the DoCreate and the BorderStyle, it now inserts the BorderStyle before the DoCreate. It might make a subtle difference, although I don't know of any cases where it would.

# re: Fix your forms to paint borders correctly under Vista Aero

Saturday, April 28, 2007 4:54 PM by Randy Jean

Calvin,

Your continued contributions to the VFP community are much appreciated.  Keep up the great work!

# re: Fix your forms to paint borders correctly under Vista Aero

Sunday, April 29, 2007 6:59 PM by Markus Winhard

Hi Calvin,

thank you very much for another insight into the inner workings of VFP. I'd like to add that your fix can be called from a project hook class' BeforeBuild event.

Unfortunately it's not as useful for a professional VFP user. Most of us are using Visual SourceSafe with VFP. So most forms are checked in at build time and thus are read only (removing the read only attribute is not really an option).

As the ProjectHook class has no BeforeCheckIn event I have no clue how to automate running your code before check in.

Any idea?

TIA,

Markus

# re: Fix your forms to paint borders correctly under Vista Aero

Monday, April 30, 2007 4:17 AM by Dominic Webb

Unfortunately this fix does not work - at least under VFP 8. Mostly (but not always) the borders are correctly painted on creation, but if a form is opened over the top, or the form moved over the edge of the screen and back, corruptions occur. The properties of one my forms that does not work (after Calvin's fix) are:

Height = 396

Width = 314

BorderStyle = 2

DoCreate = .T.

ShowTips = .T.

AutoCenter = .T.

Caption = "Letter Generator"

ControlBox = .F.

Closable = .F.

MaxButton = .F.

MinButton = .F.

WindowType = 1

Name = "LETTER"

I have tried moving other properties before the DoCreate, but without success. Interestingly, running as administrator does correct the problem.

Another workaround I have just tried is to set HalfHeightCaption = .T., which gives a Windows 2000 look, but does seem to avoid the corruptions.

A final problem affecting VFP applications is with fonts corrupting. I understand from Rick Strahl that this is due to the ClearType setting which is now default in Vista. Are there likely to be any solutions to this?

# re: Fix your forms to paint borders correctly under Vista Aero

Monday, April 30, 2007 12:07 PM by Calvin_Hsia

Dominic:

I tried creating a form with exactly the same properties as you specify in VFP8, and it repro’s the Aero problem as expected. I run the fix in my code above to put the BorderStyle before the DoCreate, and the problem goes away. Keep in mind that every time VFP rewrites the form from any modification, the fix above needs to be applied. If you can still repro the problem, can you provide the exact repro steps. Thanks

# re: Fix your forms to paint borders correctly under Vista Aero

Monday, April 30, 2007 12:59 PM by Calvin_Hsia

Markus:

Perhaps in your beforeBuild event you can run code that turns off the readonly attrib, applies the fix. The AfterBuild event can be used to clean up. You could even make/restore a backup copy in these events.

# re: Fix your forms to paint borders correctly under Vista Aero

Tuesday, May 01, 2007 12:04 AM by Kenneth Tamayo

Calvin,

Thank you for these set of fixes!

# Windows Vista Aero BorderStyle Paint problem as non Administrator

Tuesday, May 01, 2007 5:43 PM by Calvin Hsia's WebLog

Above is an image of an inner form (from the C++ project below) before and after I dragged it a little

# VFP9 SP2 / SEDNA USEFUL LINKS

Saturday, August 11, 2007 12:09 AM by Cesar Chalom

Here are some of the links that I often visit regarding VFP9 SP2 and Sedna. The official Microsoft Visual...

# re: Fix your forms to paint borders correctly under Vista Aero

Wednesday, September 05, 2007 4:55 AM by Gregory Adam

Calvin,

When the border/Titlebar is not shown, clicking outside the form and clicking back inside the form sometimes repaints it correctly with a Titlebar

Have taken out the 'DoCreate = .T.' line altogether.  Some testing seems to confirm that this is another possibility

(1) Compile form does not put 'DoCreate = .T.'

(2) Editing a form does put the 'DoCreate = .T.' back

Any thoughts ?

# re: Fix your forms to paint borders correctly under Vista Aero

Sunday, October 28, 2007 10:34 AM by Joe M.

How can I enabled the Aero Glass effect to a  VFP program that's built as a SDI? In other words, this program uses the main VFP screen at runtime. VFP ignores the Aero Glass effect. Can it be enabled in this instance?

# Windows Vista border issue and SP2

Wednesday, October 31, 2007 2:17 PM by yag: Community and Architecture

We've figured out the Vista border issue (we think). We couldn't reproduce it here, but Jim Slater noted

# re: Fix your forms to paint borders correctly under Vista Aero

Thursday, September 18, 2008 4:26 AM by Christoph Dreßler

The Border problem exists also with Border Style = 3. I fix the program be amended and all was well.

# re: Fix your forms to paint borders correctly under Vista Aero

Wednesday, December 17, 2008 11:07 PM by Abel Turrubiartes

Hi Calvin. I'm coming late to the party but have the same VFP form border issues and need some clarity. All of the forms in my app. were built using Vsual Fox Express and VFP9. All of the forms are VCXs. None are SCX. Nevertheless, in Aero, they all paint correctly at startup but any form movement (moving a form from one place to another on the screen) or calling another form corrupts their borders. The form's title bar disappears thereby losing its Min, Max and Close buttons.

I haven't tried your code because your message imples the VCX forms should behave correctly. What am I missing? Thanks.

# re: Fix your forms to paint borders correctly under Vista Aero

Friday, June 12, 2009 3:55 PM by 出会い

ヒマだょ…誰かかまってぉ…会って遊んだりできる人募集!とりあえずメール下さい☆ uau-love@docomo.ne.jp

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker