Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

How to get form caption font properties
Vlad Grynchyshyn, October 6, 2000
Windows form caption properties stored in the user preferences. You can change them using Windows Control Panel\Display\Appearance. To get these parameters programmatically in VFP, you can use following routine as a sample.
Summary
Windows form caption properties stored in the user preferences. You can change them using Windows Control Panel\Display\Appearance. To get these parameters programmatically in VFP, you can use following routine as a sample.
Description
*************************************************************************
*  Description.......: GetTitleAttributes
*  Calling Samples...: local lcFont, lnSize, lcStyle
*                               lcFont=space(32)
*                               lnSize=0
*                               lcStyle=space(4)
*                               =GetTitleAttributes(@lcFont, @lnSize, @lcStyle)
*  Parameter List....: pcFontName, pnSize, pcStyle
*  Created by........: Vlad Grynchyshyn  UT #035257 
*  Modified by.......: Nadya Nosonovsky 10/05/00 08:28:33 PM
**************************************************************************
lparameters pcFontName, pnSize, pcStyle
#DEFINE SIZE_OF_SPI_GETNONCLIENTMETRICS 340
#DEFINE OFFSET_OF_cbSize 1
#DEFINE SPI_GETNONCLIENTMETRICS 41

* prepare string buffer for structure
local lcMyStr
lcMyStr = space(SIZE_OF_SPI_GETNONCLIENTMETRICS)
* put buffer length into structure
lcMyStr = stuff(lcMyStr, OFFSET_OF_cbSize, 4, IntToSTR(SIZE_OF_SPI_GETNONCLIENTMETRICS) )

DECLARE INTEGER SystemParametersInfo IN WIN32API integer nOption, integer n2, string cStruct, integer n2
if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @lcMyStr, 0)>0
* examine result string
* values of lfCaptionFont structure should start at the offset 24.
* these values are:
*   lfHeight   - 24
*   lfWidth    - 28
*   lfEscapement - 32
*   lfOrientation - 36
*   lfWeight - 40
*   lfItalic - 44
*   lfUnderline - 45
*   lfStrikeOut - 46
*   lfCharSet - 47
*   lfOutPrecision - 48
*   lfClipPrecision - 49
*   lfQuality - 50
*   lfPitchAndFamily - 51
*   lfFaceName - 52
* note that you need to add 1 to each offset value when working with strings in VFP
* the last one is the most interesting - its 32 bytes of Font Face name. So you can take it, for example, by easy way:
local lcCaptionFont, llBold, llStrikeOut, llItalic, llUnderline, lnHeight

  lcCaptionFont = substr(lcMyStr, 53, 32)
  if at(chr(0), lcCaptionFont) > 0
    lcCaptionFont = left(lcCaptionFont, at(chr(0), lcCaptionFont) - 1)
  endif

 llItalic = asc(substr(lcMyStr, 45, 1))>0 && .T. if Italic

 llUnderline = asc(substr(lcMyStr, 46, 1))>0 && .T. if underline

 lIStrikeOut = asc(substr(lcMyStr, 47, 1))>0 && .T. if StrikeOut

 llBold = strToInt(substr(lcMyStr, 41, 4)) > 500 && .T. if bold
  ?lcMyStr
  ?lcCaptionFont
  ?llItalic
  ?llBold
  ?lIStrikeOut
  ?llUnderline
* ............
* something tricky with font size:
  DECLARE INTEGER CreateDC in gdi32 string cDriver, integer, integer, integer
  DECLARE INTEGER DeleteDC in gdi32 integer hDC
  DECLARE INTEGER GetDeviceCaps in Win32API integer hDC, integer nOption
  #DEFINE LOGPIXELSY 90
  local lcDriverName, lnDC
  lcDriverName = 'DISPLAY' + chr(0)
  lnDC = CreateDC(@lcDriverName, 0, 0, 0)
  if lnDC0
    lnHeight = StrToInt(substr(lcMyStr, 25, 4))
    * its integer, not UInt
    if lnHeight > 65536*32768 - 1 && if it is 
      lnHeight = lnHeight - 65536*65536
      lnHeight = round( (-lnHeight) * 72 / GetDeviceCaps(lnDC, LOGPIXELSY), 0)
    endif && otherwise lnHeight should contain 0 or correct height.

    = DeleteDC(lnDC)
  endif

  ?lnHeight

endif
pnSize=lnHeight && Return font size
pcFontName=lcCaptionFont
*!*     B Bold 
*!*     I Italic 
*!*     N Normal 
*!*     O Outline 
*!*     Q Opaque 
*!*     S Shadow 
*!*     – Strikeout 
*!*     T Transparent 
*!*     U Underline 

pcStyle=iif(llBold,'B','')+iif(llItalic,'I','')+iif(llUnderline,'U','')+iif(lIStrikeOut,'-','')
if empty(pcStyle)
  pcStyle='N'
endif
?pcStyle
return
********************************************************************
procedure IntToSTR
lparameters pnValue
return chr(pnValue % 256) + ;
     chr(int(pnValue / 256) % 256) + ;
     chr(int(pnValue / 65536) % 256) + ;
     chr(int(pnValue / 16777216) % 256 )
**********************************************
procedure STRToInt
lparameters pcValue
return asc(left(pcValue,1)) + ;
     asc(substr(pcValue,2,1))*256 + ;
     asc(substr(pcValue,3,1))*65536 + ;
     asc(substr(pcValue,4,1))*16777216
Above routine can be used, for example, to put some text at the right side of form caption. Following example of Caption_Assign method provided by Cetin Basoz with corrections by Nadya Nosonovsky
**************************************************************************
*  Description.......: Form.Caption_Assign
*  Calling Samples...:
*  Parameter List....:
*  Created by........: Nadya Nosonovsky 10/04/2000 10:37:20 AM
*  Modified by.......: Nadya Nosonovsky 10/05/00 08:31:55 PM
*Caption_Assign method was based on code, kindly provided by Cetin Basoz.:
****************************************************************************
lparameters vNewVal
if not 'version' $ vNewVal && not already there
     local lcCaption, lcFont, lnSize, lcStyle, lnCaptionWidth, lnSpaces
* Form.scalemode should be = 0 - Pixels
     lcFont = space(32)
     lnSize = 0
     lcStyle = space(4)
* Retrieve  Title Bar font attributes    
     =GetTitleAttributes(@lcFont,@lnSize, @lcStyle)
     lcCaption=rtrim(vNewVal) +'version ' +alltrim(str(this.nVersion,5,2))
     lnCaptionWidth=txtwidth(lcCaption,lcFont,lnSize,lcStyle)*;
          fontmetric(6,lcFont,lnSize,lcStyle)+iif(this.controlbox, ;
          iif(this.maxbutton or this.minbutton, 3, 1) * sysmetric(33)+sysmetric(16),0)
     lnSpaces = (FLOOR(this.width-lnCaptionWidth) / ;
          (txtwidth(" ",lcFont,lnSize,lcStyle) * fontmetric(6,lcFont,lnSize,lcStyle)))
     if lnSpaces>0
          vNewVal = rtrim(vNewVal) + space(lnSpaces)+'version ' +alltrim(str(this.nVersion,5,2))
     endif
endif
this.caption = m.vNewVal
Vlad Grynchyshyn, Soft Serve
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experience working with many MS development tools, components, utilities and documentation. Most experience is related to Visual FoxPro, MS SQL Server, Visual Studio and Visual Basic. He is active member of Visual FoxPro and SQL Server community, author of several articles for Universal Thread WEB site and other VFP community forums. He was MS MVP 2001-2002. He has a MS MCP certificate in Visual FoxPro area.
More articles from this author
Vlad Grynchyshyn, May 28, 2002
VFP does not support 256-color icons as project's icon (icon displayed for EXE in Windows Explorer). But 16-color icons usually looks ugly and too simplified. Here is an approach that allows organize 256-color icons for VFP EXE application. The approach is based on use of Resource Hacker appli...
Vlad Grynchyshyn, February 8, 2002
There is a situation often when we need some way to position a text cursor in the text of Editbox or RTF ActiveX controlwhen right click on the control. For example, we want to display a shortcut menu on right click. In menu, user select an option that insert some text into the control on place of c...
Vlad Grynchyshyn, March 16, 2001
Have you ever found a situation when your grid don't want to behave as you directed in design time? Custom controls in columns lost? Code of columns, headers or controls event not running? Read this FAQ then. Grid reconstruction behavior is a complete removing of all grid's controls and columns a...
Vlad Grynchyshyn, September 21, 2001
In VFP there are no direct way to assign code to the method or event in run-time mode. However, some workaround is possible with use of additional, 'hook' class. The sample below describes the approach. It is possible to make it generic. The approach is very useful to catch, for example, events of t...
Vlad Grynchyshyn, February 1, 2002
In VFP6 Grid value of the ToolTipText property of controls is displayed only for the entire grid or for current control when mouse is over it. Becuase there are a lot of parts in the grid, it is often useful to display tool tip for different parts separately. Unfortunately, VFP interprets grid as a ...
Vlad Grynchyshyn, February 8, 2002
The approach is based on a simple principle. LeftColumn property of the grid represents a column that is currently the leftmost visible column in the grid with current horizontal scrolling. As we scroll the grid horizontally, this property changes. We can assign this number to the ColumnOrder proper...
Vlad Grynchyshyn, February 6, 2001
After some investigation, I managed to make a collection-like property of object. The following is a simple sample of how to organize collection-like access (rough, need to improve it to work as real collection). It is just to show an approach.
Vlad Grynchyshyn, June 20, 2001
This article describes how to configure grid to appear as a list similar to the list box or the drop-down list of combo box. It is for appearance only. All other things are as usual for any grid. This is useful for case when need to replace list box by a grid to display more records, because list...
Vlad Grynchyshyn, April 9, 2002
The SQLEXEC() function in VFP allows downloading of data from any data source through ODBC. Unlike remote views, SQL Pass-Through approach does not provide default (automatic) settings in the returned cursor to update data on the server after changes in the cursor at the client side. Anyway, it is p...
Vlad Grynchyshyn, September 4, 2001
There is a little problem for query to get something like a sum() for a character field to concatenate character values from all records in the group. Here is described solution. The approach below have an limitation to max 30 records in group for concatenation. Test it if it will work for more r...
Vlad Grynchyshyn, February 5, 2001
Suggest Grid1 is a name of grid required to put onto the form, grid should contain 10 columns an display data from the MyAlias alias. Grid should contain a combo box in the second colunm with the name Combo1. Following sample routine will allow you to see a generic idea of how to put grid on the for...
Vlad Grynchyshyn, January 26, 2001
I have seen many questions about sorting of a grid by clicking on its header and proper refreshing of grid after sorting. There is a reliable way to sort (index) grid cursor and properly refresh the grid without change of the record number AND with very good looking. I made this in my grid class and...
Vlad Grynchyshyn, January 11, 2001
Text field on SQL Serevr is not good to store binary data because it is not reliable and often SQL Server corrupts binary data in text field. varbinary type could be too short. There are certain difficulties to use image field on SQL Server to store and read binary data in VFP. Image field on SQL...
Vlad Grynchyshyn, September 1, 2002
Hussars Very often VFP applications are associated with Microsoft Office programs. Users want to use the formatting abilities of MS Word to create documents, send letters using Outlook and to carry out statistical analysis of data in Excel. "Smart tags" is a new technology used in O...
Vlad Grynchyshyn, February 5, 2002
SQL Pass Through commands often can take a lot of time for running and returning the result set to the client. It is often usefult to show a progress bar in case of such lengthy process. Also, FetchAsNeeded option, available for views, could be very useful for SPT cursors as well. However, how we ca...
Vlad Grynchyshyn, August 1, 2001
What is the grid and when to use it? Grid control is a set of the VFP objects that allow representing data in a grid-like scrollable list. Grid consist of the grid object itself and a set of the columns. Each column must have a header object and a control that represent a data in the grid col...
Vlad Grynchyshyn, September 1, 2001
In this part, I will discuss about grid columns and header tricks on how to make development with grids go faster. I will also discuss about detecting the exact positioning over grid header or cell. As usual, I have included some tips and warnings. Grid column and header tricks - how to make de...
Vlad Grynchyshyn, October 1, 2001
In this part, I will discuss about grid sorting by header click, grid sorting marker (indicator) and resizing of grid column by double click to the width of data. As usual, I have included some tips and warnings. Grid sorting by header click Last time, sorting of information by a click on...
Vlad Grynchyshyn, October 1, 2003
This is the monthly column of Vlad Grynchyshyn SQL Server Tips. This column includes four monthly tips in regards to SQL Server which covers various topics either discussed online on the Universal Thread or sent as a contribution by another person.
Vlad Grynchyshyn, November 1, 2003
This is the monthly column of Vlad Grynchyshyn SQL Server Tips. This column includes four monthly tips in regards to SQL Server which covers various topics either discussed online on the Universal Thread or sent as a contribution by another person.
Vlad Grynchyshyn, December 1, 2003
This is the monthly column of Vlad Grynchyshyn SQL Server Tips. This column includes four monthly tips in regards to SQL Server which covers various topics either discussed online on the Universal Thread or sent as a contribution by another person.
Vlad Grynchyshyn, September 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, August 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, July 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, June 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, February 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, January 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, March 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, May 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, April 1, 2003
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...
Vlad Grynchyshyn, December 1, 2002
Vlad Grynchyshyn is senior developer and project manager at the Ukrainian company "Soft Serve Ltd.", that provides custom-developed software solutions in several areas with use of wide range of development tools and languages. Vlad works in the MS Solutions department of the company, and has experie...