OS2.org Site Index - Feedback - Impressum
Sprachauswahl / Choose your Language News Software Hardware Projekte Forum Tipps Links Verschiedenes
Editorial Diskussion HelpDesk Umfrage
[Forum]
in nach (Erweiterte Suche)
[Forum]
( Archiv ) ( Neues Thema )
19.02.2002
Was und Wie: Fenstergröße und Schriftgröße unter C++ (von: GA, 17:18:50) ^
Diese Quelle ist nicht mehr auf dem neuesten Stand, aber da dies Thema schon einmal hier ohne konkrete Lösungsvorschläge nachgefragt wurde, finde ich, das dies wenigstens eine Anregung sein könnte: Vielleicht geben die Profis hier dann bessere Vorschläge:

The size of a displayed window should not normally be predetermined, but should be calculated from the size of the screen and the size of the characters.

This is important so that the window fits within the screen and contains a reasonable amount of information.

It is possible to design only for VGA (640x480) screens, but this will then not take advantage of larger screens, and will also be very limiting on DBCS systems (where characters can take 2 positions on the screen).

The WinQuerySysValue call can be used to query the screen size, and the GpiQueryFontMetrics call can be used to query the character size, as shown in the code fragment shown in "Figure: Calculating Window Size and Position".

This code queries the screen size and character size, and then positions a window in the center of the screen with a width of 40 characters and height of 20 characters.

Calculating Window Size and Position

/* Constants */

#define WIN_WIDTH 40
#define WIN-HEIGHT 20

/* Declarations */

HPS hps;
LONG lCxScreen, lCyScreen,lCharWidth,lCharHeight;
LONG lInitW, /* Width of the frame window */
lInitH, /* Height of the frame window */
lInitX, /* Horizontal position of the frame window */
lInitY; /* Vertical position of the frame window */

FONTMETRICS fm;

/* Create a standard window */

hwnd = WinCreateStdWindow(HWND_DESKTOP,
WS_VISIBLE,
&flCreate1,
NLS_1,
NLS_2,
0L,
hModNLVSSAMP,
ID_,
(PHWND) &hwndc1);

/* Query the screen size */

lCxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);

lCyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);

/* Query the character size */

hps = WinGetPS(hwnd);
GpiQueryFontMetrics(hps, (LONG)sizeof(fm), &fm);
lCharWidth = fm.lAveCharWidth;
lCharHeight = fm.lMaxBaselineExt+fm.lExternalLeading;

/* Decide the window size based on the character size */

lInitW = lCharWidth * WIN_WIDTH;
lInitH = lCharHeight * WIN_HEIGHT;

/* Center the window based on the window size and screen size */

lInitX = (lCxScreen - lInitW) /2;
lInitY = (lCyScreen - lInitH) /2;

/* Set the window position */

WinSetWindowPos(hwnd,
HWND_TOP,
(SHORT)lInitX,
(SHORT)lInitY,
(SHORT)lInitW,
(SHORT)lInitH,
SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);

Eine erweiterte Fragestellung mit Rettung und Restaurierung der Fenstergrößen findet man hier:

http://web.singnet.com.sg/~hannwei/html/OS2P5.html



[ Leser: 43 ]

Datum Thema
06.01.2017 *

*

Name: * eMail: Benachrichtigung

Mit * markierte Felder müssen ausgefüllt werden !

( Zeige alle Einträge ) ( Zur Startübersicht )
Thema von: Leser Datum Zeit
 Was und Wie: Fenstergröße und Schriftgröße unter C++
GA4319.02.200217:18


php.net OpenIT © 1998-2017 by WebTeam OS2.org