[Windows] Fenêtre : Quelques données systèmes

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

[Windows] Fenêtre : Quelques données systèmes

Message par Mesa »

J'ai eu besoin de savoir quelques données sur les fenêtres, voilà le code trouvé sur le forum uk, augmenté et debuggé :

Code : Tout sélectionner

; INFO WINDOWS : NONCLIENTMETRICS
;================================
; Pour interpréter les valeurs qui semblent incohérentes voir :
; http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx
; http://msdn.microsoft.com/en-us/library/windows/desktop/ff729175%28v=vs.85%29.aspx
; http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037%28v=vs.85%29.aspx

Structure NONCLIENTMETRICS_VISTA Extends NONCLIENTMETRICS
  iPaddedBorderWidth.l
EndStructure

Procedure isVistaOrGreater()   
  Protected OSVerInfo.OSVERSIONINFOEX
  
  OSVerInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFOEX)
  GetVersionEx_(@OSVerInfo)   
  
  ProcedureReturn Bool(OSVerInfo\dwMajorVersion>=6)
EndProcedure

Define.NONCLIENTMETRICS_VISTA NCM
Define MessageFont

If isVistaOrGreater()   
  NCM\cbSize = SizeOf(NONCLIENTMETRICS_VISTA)
Else   
  NCM\cbSize = SizeOf(NONCLIENTMETRICS)
EndIf

Procedure GetFontInfo(FontID)
  
  If FontID
    fnt.LOGFONT    
    GetObject_(FontID,SizeOf(fnt),@fnt)
    FName$ =  PeekS(@fnt\lfFaceName[0])
    If FName$ = "MS Shell Dlg"
      FName$ = "MS Shell Dlg/MS Sans Serif"
    EndIf
    ;(1 point = 1/72 pouce) et 96 ou DPI pixels/pouce
    ; hauteur (en pixels) = hauteur (en points) / 72 * DPI
    ; hauteur = 0 - (72 * fontsize / DPI) 
    FontSize = Int(Round((-fnt\lfHeight * 72 / GetDeviceCaps_(GetDC_(0),#LOGPIXELSY)),#PB_Round_Nearest))
    ;Debug "DPI = #LOGPIXELSY= "+GetDeviceCaps_(GetDC_(0),#LOGPIXELSY)
    
    textmetric.TEXTMETRIC
    GetTextMetrics_(GetDC_(0),@textmetric)
    
    Debug "Nom " + FName$
    Debug "Taille " + FontSize    
    Debug "Hauteur " + fnt\lfHeight
    Debug "Largeur " + fnt\lfWidth          
    Debug "Echappement " + fnt\lfEscapement
    Debug "Orientation " + fnt\lfOrientation  
    Debug "Graisse " + fnt\lfWeight		
    Debug "Italique " + fnt\lfItalic
    Debug "Souligné " + fnt\lfUnderline    
    Debug "Barré " + fnt\lfStrikeOut
    Debug "Charset " + fnt\lfCharSet
    Debug "OutPrecision " + fnt\lfOutPrecision
    Debug "ClipPrecision " + fnt\lfClipPrecision
    Debug "Qualité " + fnt\lfQuality                      
    Debug "Pitch et Famille " + fnt\lfPitchAndFamily
    Debug "Espace interlignes " + textmetric\tmInternalLeading
    
  EndIf
EndProcedure

;SystemParametersInfo_ renvoie une valeur non nulle en cas de succès
;http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx
Debug SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS, NCM\cbSize, @NCM, 0)

Debug "La taille de la structure, en octets."
Debug NCM\cbSize

Debug "L'épaisseur de la bordure de redimensionnement, en pixels. Par défaut 1 pixel."
Debug NCM\iBorderWidth

Debug "La largeur barre de défilement verticale standard, en pixels." 
Debug NCM\iScrollWidth

Debug "La hauteur d'une barre de défilement horizontale, en pixels."
Debug NCM\iScrollHeight

Debug "La largeur de boutons 'caption', en pixels."
Debug NCM\iCaptionWidth

Debug "La hauteur des boutons 'caption', en pixels."
Debug NCM\iCaptionHeight

Debug "une structure LOGFONT qui contient des informations sur la police 'caption'."
Debug NCM\lfCaptionFont
CaptionFont = CreateFontIndirect_(@NCM\lfCaptionFont)
GetFontInfo(CaptionFont)
Debug"------------------------------------------"

Debug "La largeur des petits boutons 'caption', en pixels."
Debug NCM\iSmCaptionWidth

Debug "La hauteur des petits boutons 'caption', en pixels."
Debug NCM\iSmCaptionHeight

Debug "une structure LOGFONT qui contient des informations sur la petite police 'caption'."
Debug NCM\lfSmCaptionFont
SmCaptionFont = CreateFontIndirect_(@NCM\lfSmCaptionFont)
GetFontInfo(SmCaptionFont)
Debug"------------------------------------------"

Debug "La largeur de bouton menu bar, en pixels."
Debug NCM\iMenuWidth

Debug "La hauteur de la barre de menu, en pixels."
Debug NCM\iMenuHeight

Debug "une structure LOGFONT qui contient des informations sur la police utilisée dans les barres de menus."
Debug NCM\lfMenuFont
MenuFont = CreateFontIndirect_(@NCM\lfMenuFont)
GetFontInfo(MenuFont)
Debug"------------------------------------------"

Debug "une structure LOGFONT qui contient des informations sur la police utilisée dans les statutbarres et les info-bulles."
Debug NCM\lfStatusFont
StatusFont = CreateFontIndirect_(@NCM\lfStatusFont)
GetFontInfo(StatusFont)
Debug"------------------------------------------"

Debug "une structure LOGFONT qui contient des informations sur la police utilisée dans les boîtes de dialogue."
Debug NCM\lfMessageFont
MessageFont = CreateFontIndirect_(@NCM\lfMessageFont)
GetFontInfo(MessageFont)
Debug"------------------------------------------"

Debug "L'épaisseur de la bordure 'vista', en pixels. Vista ou +"
Debug NCM\iPaddedBorderWidth
Debug"------------------------------------------"

;Font système par défaut
Debug "Font système DEFAULT_GUI_FONT"
GetFontInfo(GetStockObject_(#DEFAULT_GUI_FONT))	
Debug"------------------------------------------"
Debug "Font système #SYSTEM_FONT"
GetFontInfo(GetStockObject_(#SYSTEM_FONT))	


;http://msdn.microsoft.com/en-us/library/windows/desktop/ff729175%28v=vs.85%29.aspx
; typedef struct tagNONCLIENTMETRICS {
;   UINT    cbSize;
;   int     iBorderWidth;
;   int     iScrollWidth;
;   int     iScrollHeight;
;   int     iCaptionWidth;
;   int     iCaptionHeight;
;   LOGFONT lfCaptionFont;
;   int     iSmCaptionWidth;
;   int     iSmCaptionHeight;
;   LOGFONT lfSmCaptionFont;
;   int     iMenuWidth;
;   int     iMenuHeight;
;   LOGFONT lfMenuFont;
;   LOGFONT lfStatusFont;
;   LOGFONT lfMessageFont;
; #if (WINVER >= 0x0600)
;   int     iPaddedBorderWidth;
; #endif 
; } NONCLIENTMETRICS, *PNONCLIENTMETRICS, *LPNONCLIENTMETRICS;

;http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037%28v=vs.85%29.aspx
; typedef struct tagLOGFONT {
;   LONG  lfHeight;
;   LONG  lfWidth;
;   LONG  lfEscapement;
;   LONG  lfOrientation;
;   LONG  lfWeight;
;   BYTE  lfItalic;
;   BYTE  lfUnderline;
;   BYTE  lfStrikeOut;
;   BYTE  lfCharSet;
;   BYTE  lfOutPrecision;
;   BYTE  lfClipPrecision;
;   BYTE  lfQuality;
;   BYTE  lfPitchAndFamily;
;   TCHAR lfFaceName[LF_FACESIZE];
; } LOGFONT, *PLOGFONT;
M.