Author Topic: One is easier ...  (Read 92 times)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
One is easier ...
« 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.

« Last Edit: March 23, 2021, 07:03:15 PM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 601
    • View Profile
Re: One is easier ...
« Reply #1 on: March 28, 2021, 01:32:10 AM »
DECLARE FUNCTION AfxSetProcessDPIAware LIB "user32.dll" ALIAS "SetProcessDPIAware" () AS LONG

Compiles as 64 bit with CLang.



MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: One is easier ...
« Reply #2 on: March 28, 2021, 10:31:26 AM »
+1