BCX Basic Forum

You must log on, to access files that were uploaded by BCX forum members. => Tips & Tricks => Topic started by: MrBcx on March 23, 2021, 06:55:38 PM

Title: One is easier ...
Post by: MrBcx on March 23, 2021, 06:55:38 PM
The following function was written by Jose Roca and is found in his PowerBasic AfxWin.inc file

Code: [Select]
'==============================================================================
' Sets the current process as dots per inch (dpi) aware.
' Note SetProcessDPIAware is subject to a possible race condition if a DLL caches dpi
' settings during initialization. For this reason, it is recommended that dpi-aware be set
' through the application (.exe) manifest rather than by calling SetProcessDPIAware.
' =============================================================================
FUNCTION AfxSetProcessDPIAware () AS LONG
  LOCAL bRes AS LONG
  LOCAL hLib AS DWORD
  LOCAL pProc AS DWORD
  hLib = LOADLIBRARY( "user32.dll" )
  IF hLib = 0 THEN EXIT FUNCTION
  pProc = GetProcAddress(hLib, "SetProcessDPIAware")
  IF pProc THEN CALL DWORD pProc USING AfxSetProcessDPIAware() TO bRes
  FreeLibrary hLib
  FUNCTION = bRes
END FUNCTION

BCX makes it much easier to invoke the SetProcessDPIAware function.

Result = SetProcessDPIAware ( LIB "user32.dll" )

Or you can roll the call into your own BCX function, similar to what Jose Roca did, only BCX needs less code.

Code: [Select]
FUNCTION AfxSetProcessDPIAware AS LONG
  FUNCTION = SetProcessDPIAware ( LIB "user32.dll" )
END FUNCTION

Be aware, these tips only work with your 32-bit BCX apps.
These will not compile as 64-bit because the LIB keyword relies
on some internal inline ASM that no Windows C/C++ compiler supports.

Title: Re: One is easier ...
Post by: Robert on March 28, 2021, 01:32:10 AM
DECLARE FUNCTION AfxSetProcessDPIAware LIB "user32.dll" ALIAS "SetProcessDPIAware" () AS LONG

Compiles as 64 bit with CLang.


Title: Re: One is easier ...
Post by: MrBcx on March 28, 2021, 10:31:26 AM
+1