Newsgroup: it.comp.appl.access
Titolo: Centrare una form

Ciao a tutti. "Ancora con sta storia della centratura delle form", direte
voi. Lo so che c'e' una proprieta' che ti fa autocentrare la form, ma il
fatto e' che  a me serve poterla centrare esplicitamente in un determinato
momento della sua vita. Ho infatti una form con un pulsantino ">>>" che, se
premuto, mi allarga le dimensioni della form in modo che si scoprano e
divengano utilizzabili alcuni campi nascosti al di fuori delle dimensioni
normali. Se si ripreme il pulsantino, il cui testo e' diventato "<<<", la
finestra torna alle sue dimensioni normali. E'il comportamento tipico di
molte finestre Windows, l'avrete sicuramente visto moltissime volte.
Ora: quando la finestra si apre a dimensioni "normali", e' centrata (come da
proprieta') automaticamente. Ma quando ne modifico le dimensioni, dovrei
ri-centrarla esplicitamente!
L'istruzione con la quale ne modifico le dimensioni e':
    DoCmd.MoveSize , , larghezza, altezza
A me servirebbe conoscere le dimensioni dello schermo (in realta' della
finestra principale sottostante di Access), in modo da poter modificare
questa istruzione in:
    DoCmd.MoveSize (larghezza_schermo - larghezza) / 2, (altezza_schermo -
altezza) / 2 , larghezza, altezza
Ma dove diavolo le vado a pescare le dimensioni dello schermo?!?
Grazie e ciao,
Angelo.-

 ha scritto nel messaggio
news:oAfJ6.6307$DF1.1...@news1.tin.it...

Le dimensioni dello schermo o le dimensioni della finestra sottostante la
maschera da posizionare?
Comunque uno dei problemi è la conversione dei Twips in Pixels o viceversa.
Non per citarmi ma sul sito comune potrai trovare qualcosa che fà al caso
tuo o almeno un buon punto di partenza: "Cambiare al volo la risoluzione
dello schermo".
Infatti tutto dipende dalla risoluzione dello schermo e questa può variare.
Sù, ancora un po' e ci sei.
Ciao, Carlo

dello schermo".
Grazie mille. Controllo immediatamente.
Ciao!
A.-


Prova questo codice.
Copia tutto in modulo e per centrare una form usi:
Call CentraFinestra(nomefinestra)
la usavo con access2, ma dovrebbe funzionare senza modifiche.
-------------
Type RECT_Type
    left As Long
    top As Long
    right As Long
    bottom As Long
End Type
Declare Function apiGetWindowRect Lib "user32" Alias "GetWindowRect"
(ByVal hWnd As Long, lpRect As RECT_Type) As Long
Declare Function apiGetDC Lib "user32" Alias "GetDC" (ByVal hWnd As
Long) As Long
Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hWnd
As Long, ByVal hDC As Long) As Long
Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal hDC As Long, ByVal nIndex As Long) As Long
Declare Function apiGetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal hWnd
As Long) As Long
Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As
Long) As Long
Global Const TWIPSPERINCH = 1440
Public Sub CentraFinestra(FormCenter As String)
    Dim frmCust As Form
    Dim frmCustLeft As Long
    Dim frmCustTop As Long
    Dim frmCustWidth As Long
    Dim frmCustHeight  As Long
    Dim MDIClient As RECT_Type
    Dim MDIClientLeft As Long
    Dim MDIClientTop  As Long
    Dim MDIClientR  As Long
    Dim MDIClientB  As Long
    Set frmCust = Forms(FormCenter)
    apiGetWindowRect apiGetParent(frmCust.hWnd), MDIClient
    MDIClientLeft = MDIClient.left
    MDIClientTop = MDIClient.top
    MDIClientR = MDIClient.right
    MDIClientB = MDIClient.bottom
    MDIClientR = MDIClientR - MDIClientLeft
    MDIClientB = MDIClientB - MDIClient.top
    ConvertPIXELSToTWIPS MDIClientLeft, MDIClientTop
    ConvertPIXELSToTWIPS MDIClientR, MDIClientB
    GetFormDimensions frmCust, frmCustLeft, frmCustTop, frmCustWidth,
frmCustHeight
    frmCust.SetFocus
    DoCmd.MoveSize (MDIClientR - frmCustWidth) / 2, (MDIClientB -
frmCustHeight) / 2
End Sub
Sub GetFormDimensions(f As Form, FLeft As Long, FTop As Long, FWidth As
Long, FHeight As Long)
    '*************************************************************
    ' PURPOSE: Returns the left, top, width, and height
    '          measurements of a form window in tdwips.
    ' ARGUMENTS:
    '    F: The form object whose measurements are to be determined.
    '    FLeft, FTop, FWidth, FHeight: Measurement variables
    '    that will return the dimensions of form F "by reference."
    ' NOTE: The FWidth and FHeight values will be equivalent to
    '    those provided by the form WindowWidth and WindowHeight
    '    properties.
    '*************************************************************
    Dim FormRect As RECT_Type
    Dim MDIClient As RECT_Type
    Dim MDIClientLeft As Long
    Dim MDIClientTop  As Long
    Dim MDIClientR  As Long
    Dim MDIClientB  As Long
    ' Get the screen coordinates and window size of the form.
    ' The screen coordinates are returned in pixels measured
    ' from the upper-left corner of the screen.
    apiGetWindowRect f.hWnd, FormRect
    FLeft = FormRect.left
    FTop = FormRect.top
    FWidth = FormRect.right - FormRect.left
    FHeight = FormRect.bottom - FormRect.top
    ' Convert the measurements from pixels to twips.
    ConvertPIXELSToTWIPS FLeft, FTop
    ConvertPIXELSToTWIPS FWidth, FHeight
    ' If the form is not a pop-up form, adjust the screen
    ' coordinates to measure from the top of the Microsoft
    ' Access MDIClient window. Position 0,0 for a pop-up form
    ' is the upper-left corner of the screen, whereas position
    ' 0,0 for a normal window is the upper-left corner of the
    ' Microsoft Access client window below the menu bar.
    If GetWindowClass(f.hWnd) = "OFormPopup" And GetWindowClass(f.hWnd)
= "OFormPopupNC" Then
        ' Get the screen coordinates and window size of the
        ' MDIClient window.
        apiGetWindowRect apiGetParent(f.hWnd), MDIClient
        MDIClientLeft = MDIClient.left
        MDIClientTop = MDIClient.top
        MDIClientR = MDIClient.right
        MDIClientB = MDIClient.bottom
        ConvertPIXELSToTWIPS MDIClientLeft, MDIClientTop
        ConvertPIXELSToTWIPS MDIClientR, MDIClientB
        ' Adjust the form dimensions from the MDIClient
        ' measurements.
        FLeft = FLeft + MDIClientLeft
        FTop = FTop + MDIClientTop
    End If
End Sub
Sub ConvertPIXELSToTWIPS(x As Long, Y As Long)
    '*************************************************************
    ' PURPOSE: Converts the two pixel measurements passed as
    '          arguments to twips.
    ' ARGUMENTS:
    '    X, Y: Measurement variables in pixels. These will be
    '          converted to twips and returned through the same
    '          variables "by reference."
    '*************************************************************
    Dim hDC As Long, hWnd As Long, retVal As Long
    Dim XPIXELSPERINCH, YPIXELSPERINCH
    Const LOGPIXELSX = 88
    Const LOGPIXELSY = 90
    ' Retrieve the current number of pixels per inch, which is
    ' resolution-dependent.
    hDC = apiGetDC(0)
    XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
    YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
    retVal = apiReleaseDC(0, hDC)
    ' Compute and return the measurements in twips.
    x = (x / XPIXELSPERINCH) * TWIPSPERINCH
    Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH
End Sub
Function GetWindowClass(hWnd As Long) As String
    '*************************************************************
    ' PURPOSE: Retrieve the class of the passed window handle.
    ' ARGUMENTS:
    '    hWnd: The window handle whose class is to be retrieved.
    ' RETURN:
    '    The window class name.
    '*************************************************************
    Dim Buff As String
    Dim BuffSize As Integer
    Buff = String$(255, " ")
    BuffSize = apiGetClassName(hWnd, Buff, 255)
    GetWindowClass = left$(Buff, BuffSize)
End Function
-------------
-- 
Federico
----------------------------------
Rimuovi paperino. per e-mail
----------------------------------
Tutte le richieste che arrivano
in privato, vengono cestinate.
----------------------------------
Sito Comune di it.comp.appl.access
http://www.sitocomune.com
mailto:
webm...@sitocomune.com
----------------------------------

Call CentraFinestra(nomefinestra)
Mh, grazie mille. API a gogo'...
La provo stasera.
Ciao!
A.-