Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Row/Col vs Pixels

212 views
Skip to first unread message

Jack Jackson

unread,
May 28, 2004, 1:53:55 PM5/28/04
to
Does anyone know how to convert between Row and Column numbers (used
in various VFP commands and functions, such as WAIT) and pixels?

Rick Bean

unread,
May 28, 2004, 5:50:12 PM5/28/04
to
Jack,
While I've got TwipsToPixels() and PixelsToTwips() functions, what you want is quite a bit more complicated. Columns and Rows are based on the current Screen/Window/Form font (type, "name", size and special features), and pixels are simply a count of "dots".

I recently was shown a routine that attempts to center a wait window on the screen, and it was ~ 3 pages of code and it still didn't always work right!

Using columns and rows just doesn't make sense in a VFP - it there strictly for backward compatibility of code.

Using Fontmetric() you can make some approximations - good luck.

Rick

"Jack Jackson" <jackn...@pebbleridge.com> wrote in message news:80veb0hohupn9guvs...@4ax.com...

Jack Jackson

unread,
May 29, 2004, 2:34:12 AM5/29/04
to
Thanks. I agree that it makes no sense. Unfortunately there are a
number of VFP commands that accept only rows and columns.

Rick Bean

unread,
May 29, 2004, 9:30:58 AM5/29/04
to
Jack,
While there are a number of commands that use thse contructs, they all seem to be xBase backward compatible commands, not VISUAL FoxPro commands.

Recently I found this posing by Lisa Slater Nicholls (at one time proclaimed the Fox Report "Goddess"), which shows her attempt at implementing a centered WAIT Window.

Rick

* M_CWAIT.PRG
* utility program for the MasterClass Framework
* to center the wait window
* Lisa Slater Nicholls


#DEFINE WAIT_WINDOW_FONT_NAME "MS SANS SERIF"
#DEFINE WAIT_WINDOW_FONT_SIZE 8
#DEFINE WAIT_WINDOW_FONT_STYLE ""
#DEFINE WAIT_WINDOW_STANDARD_MESSAGE "Press any key to continue ..."

#DEFINE WAIT_WINDOW_BORDER_WIDTH SYSMETRIC(12)* 2

LPARAMETERS tcMessage, tcAddtlParams, tcParentWindow

* second thing can be string like "TIMEOUT 1"

IF TYPE("tcMessage") # "C"
tcMessage = WAIT_WINDOW_STANDARD_MESSAGE
ENDIF

IF TYPE("tcAddtlParams") # "C"
tcAddtlParams = ""
ENDIF


* note that the default case,
* centers in the main desktop,
* because this is really how
* the AT stuff works for WAIT WINDOW,
* even though without the
* AT clause the window is relative to the _SCREEN!

* You're probably going to think it's weird that I'm
* using _SCREEN.Font information when I'm going to the
* desktop, but in fact Fox uses _SCREEN.Font information
* when it's relating information like foxel sysmetrics
* to the desktop. We have to be concerned wth foxels,
* even when talking about the full desktop here,
* because the AT clause "thinks" in Fox rows and
* columns, not pixels. <sigh>

* If you want to center in the Fox window instead, pass the
* optional parameter.

* Note that the first line is used to measure the length
* of multi-line wait windows. Horizontal centering is not
* perfect, possibly because of divergence of message from
* "average char width". But it's pretty good!

* I don't have it working with a parent window, but
* the calculations should be similar to what I'm doing
* with the Fox window. The difference will be in
* what SYSMETRIC()s you use -- depends on the
* window definition (because it won't have the
* menu bar and may have different-sized borders)


LOCAL lcFont, lnFont
lnFont = _SCREEN.FontSize
lcFont = _SCREEN.FontName
llFont = _SCREEN.FontBold

_SCREEN.FontName = WAIT_WINDOW_FONT_NAME
_SCREEN.FontSize = WAIT_WINDOW_FONT_SIZE
_SCREEN.FontBold = ("B" $ WAIT_WINDOW_FONT_STYLE)

DO CASE
CASE TYPE("tcParentWindow") # "C"
* center in desktop, the default
WAIT WINDOW ;
tcMessage ;
&tcAddtlParams ;
AT ;
.5*( (SYSMETRIC(2) / ;
(FONTM(1,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE) + ;
FONTM(4,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE) + ;
FONTM(5,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE))) - ;
MEMLINES(tcMessage) ) ;
, ;
.5*( ((SYSMETRIC(1)-WAIT_WINDOW_BORDER_WIDTH) / ;
FONTM(6,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE)) - ;
IIF(MEMLINES(tcMessage) > 1, ;
LEN(MLINE(tcMessage,1,0)), ;
LEN(tcMessage)) )

CASE EMPTY(tcParentWindow)
* center in FoxPro main screen
* bleh...
* figure out area of desktop covered by fox screen and
* center within that!

LOCAL lnScaleMode
lnScaleMode = _SCREEN.ScaleMode
_SCREEN.ScaleMode = 0

WAIT WINDOW ;
tcMessage ;
&tcAddtlParams ;
AT ;
.5*( _SCREEN.Height - MEMLINES(tcMessage) ) ;
+ _SCREEN.Top + ;
( (SYSMETRIC(20) + SYSMETRIC(9)) / ;
(FONTM(1,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE) + ;
FONTM(4,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE) + ;
FONTM(5,WAIT_WINDOW_FONT_NAME, ;
WAIT_WINDOW_FONT_SIZE, ;
WAIT_WINDOW_FONT_STYLE))) ;
, ;
.5*( _SCREEN.Width - ;
IIF(MEMLINES(tcMessage) > 1, ;
LEN(MLINE(tcMessage,1,0)), ;
LEN(tcMessage)) ) + _SCREEN.Left

_SCREEN.ScaleMode = lnScaleMode

CASE WEXIST(tcParentWindow)
WAIT WINDOW NOWAIT ;
tcMessage+ CHR(13)+CHR(13)+;
"WAIT WINDOW centered in parent window "+ CHR(13)+ ;
"is left as an exercise for the graduate student."
* bleh...
OTHERWISE
* error message
ENDCASE

_SCREEN.FontName = lcFont
_SCREEN.FontSize = lnFont
_SCREEN.FontBold = llFont


RETURN


* M_DWAIT.PRG
* utility program for the MasterClass Framework
* to position the wait window in top form
* Lisa Slater Nicholls

#DEFINE WAIT_WINDOW_STANDARD_MESSAGE "Press any key to continue ..."

LPARAMETERS tcMessage, tcAddtlParams

* second thing can be string like "TIMEOUT 1"

IF TYPE("tcMessage") # "C"
tcMessage = WAIT_WINDOW_STANDARD_MESSAGE
ENDIF

IF TYPE("tcAddtlParams") # "C"
tcAddtlParams = ""
ENDIF

IF _VFP.StartMode > 0 AND ;
ATC("NOWA",tcAddtlParams) = 0 AND ;
ATC("TIME",tcAddtlParams) = 0
* OLE server
tcAddtlParams = tcAddtlParams + " NOWAIT"
ENDIF

* The AT clause "thinks" in Fox rows and
* columns, not pixels. <sigh>
* However, unexpected bonus: Use silly numbers
* that are outside the possibilities of the
* current display and not so big that they
* give you "invalid coordinates" and it
* puts the WAIT WINDOW into "expected WAIT WINDOW top-right
* Position", but in the current top form rather than the _SCREEN!

* So that's what I'm doing here.

* note: what give you "invalid coordinates" will be dependent on the current
* font information <sigh> either for the top window or _SCREEN.
* the following expression will work for fontsizes up to 64,
* apparently regardless of resolution, which should be good enough!

* the "1" in the first parameter to the AT clause, of course, represents
* the first row of the window, in whatever fontsize is current.
* The SYSM(1)/2 in the second parameter is what makes the WAIT WINDOW
* weird out and go to top form rather than desktop.


WAIT WINDOW ;
tcMessage ;
AT 1,SYSM(1)/2 &tcAddtlParams

RETURN

"Jack Jackson" <jackn...@pebbleridge.com> wrote in message news:gkbgb0dbbogodrh1p...@4ax.com...

Jack Jackson

unread,
May 29, 2004, 11:57:00 AM5/29/04
to
Thanks, I'll play around with this.

On Sat, 29 May 2004 09:30:58 -0400, "Rick Bean"
<rgb...@unrealmelange-inc.com> wrote:

>Jack,

0 new messages