//**************************************************************************** // $Module type: Package // $Module name: cButtonDPI.pkg // // $Author : Nils Svedmyr, RDC Tools International. // Copyright (c) 2013 RDC Tools International // E-mail : support@rdctools.com // Web-site : http://www.rdctools.com // // Created : 2013-01-05 @ 19:04 (Military date format - Year-Month-Day) // // The code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // This is free software; you can redistribute it and/or modify it under the terms of the // GNU Lesser General Public License - see the "GNU Lesser General Public License.txt" // in the help folder for more details. // //**************************************************************************** Use cButton.pkg // Button class that automatically shows the correct icon size for the current DPI-setting: Class cButtonDPI is a cButton Procedure Construct_Object Integer iIconSize Forward Send Construct_Object #IF (!@ < 180) Property Integer piImageSize Property Integer piImageMarginLeft Property String psImage #ENDIF #IF (Required_FMAC_Build < 107) Get GetCorrectIconSize to iIconSize Set piImageSize to iIconSize Set piImageMarginLeft to 10 #ENDIF End_Procedure // Returns: DPI setting as an integer. // Normal DPI setting: iDPI=96 is "Normal setting" 100% // iDPI=120 is "Medium setting" 125% // iDPI= 144 is "Large setting" 150% Function GetCurrentDPI Returns Integer Handle hDC Integer iPixelsX Move (GetDC(0)) to hDC Move (GetDeviceCaps(hDC, LOGPIXELSX)) to iPixelsX Move (ReleaseDC(0, hDC)) to hDC Function_Return iPixelsX End_Function Function GetCorrectIconSize Returns Integer Integer iPixelsX iIndex iSize Integer[] iaSizes Move 16 to iaSizes[0] Move 24 to iaSizes[1] Move 32 to iaSizes[2] Move 48 to iaSizes[3] Move 64 to iaSizes[4] Get piImageSize to iSize // the "100%" size Move (SearchArray(iSize,iaSizes)) to iIndex Move (0 max iIndex) to iIndex Get GetCurrentDPI to iPixelsX // Use a Case Statement here. Wherever we jump in we will continue onwards, regardless of whether // we match the remaining Case statements or not. So list our Cases in reverse order, meaning we // will increment iIndex as many times as we need here. Case Begin Case (iPixelsX > 144) Increment iIndex Case (iPixelsX = 144) Increment iIndex Case (iPixelsX = 120) Increment iIndex Case End Move (iIndex min 4) to iIndex Function_Return iaSizes[iIndex] End_Function Procedure Set psToolTip String sToolTip String sStatusHelp Get Status_Help to sStatusHelp If (sStatusHelp = "") Begin Set Status_Help to sToolTip End Forward Set psToolTip to sToolTip End_Procedure End_Class