~ Edito ~
12/03/2006 @ 13:39
Depuis la dernière mise à jour (qui remonte à... oulala plusieurs mois), un petit ménage de printemps s'impose. Ca tombe bien, c'est presque la période. Au menu, et progressivement sur les jours à venir, rafraîchissement de plusieurs fonctions et procédures, nouvelles APIs et nouveaux programmes. ~ Rechercher ~
~ Annuaire VB ~
~ Partenaires ~
|
Procédure : MargesNonImprimables Const PHYSICALOFFSETY = 113 Const LOGPIXELSX = 88 Const LOGPIXELSY = 90 Declare Function GetDeviceCaps Lib "gdi32" (_ ByVal hdc As Long, ByVal nIndex As Long) As Long Public Sub MargesNonImprimables(sgMargeGauche As Single, sgMargeHaute As Single) ' Retourne les marges non imprimables de l'imprimante par défaut, ' exprimées selon le ScaleMode en cours. Dim sgPrinterOffsetX As Single, sgPrinterOffsetY As Single Dim sgPixelsPerInchX As Single, sgPixelsPerInchY As Single ' Obtenir les marges non imprimables (en pixels) : sgPrinterOffsetX = GetDeviceCaps(Printer.hdc, PHYSICALOFFSETX) sgPrinterOffsetY = GetDeviceCaps(Printer.hdc, PHYSICALOFFSETY) ' Obtenir la résolution de l'imprimante (en pixels par pouce) : sgPixelsPerInchX = GetDeviceCaps(Printer.hdc, LOGPIXELSX) sgPixelsPerInchY = GetDeviceCaps(Printer.hdc, LOGPIXELSY) ' Calculer les marges avec le ScaleMode en cours : Select Case Printer.ScaleMode Case 1 ' Twips sgMargeGauche = sgPrinterOffsetX / sgPixelsPerInchX * 1440 sgMargeHaute = sgPrinterOffsetY / sgPixelsPerInchY * 1440 Case 2 ' Points sgMargeGauche = sgPrinterOffsetX / sgPixelsPerInchX * 72 sgMargeHaute = sgPrinterOffsetY / sgPixelsPerInchY * 72 Case 3 ' Pixels sgMargeGauche = sgPrinterOffsetX sgMargeHaute = sgPrinterOffsetY Case 4 ' Caractères sgMargeGauche = sgPrinterOffsetX / sgPixelsPerInchX * 1440 / 120 sgMargeHaute = sgPrinterOffsetY / sgPixelsPerInchY * 1440 / 240 Case 5 ' Pouces sgMargeGauche = sgPrinterOffsetX / sgPixelsPerInchX sgMargeHaute = sgPrinterOffsetY / sgPixelsPerInchY Case 6 ' Millimètres sgMargeGauche = sgPrinterOffsetX / sgPixelsPerInchX * 25.4 sgMargeHaute = sgPrinterOffsetY / sgPixelsPerInchY * 25.4 Case 7 ' Centimètres sgMargeGauche = sgPrinterOffsetX / sgPixelsPerInchX * 2.54 sgMargeHaute = sgPrinterOffsetY / sgPixelsPerInchY * 2.54 Case Else MsgBox "ScaleMode non géré !", 16, "Sub MargesNonImprimables" End Select End Sub |