Author Topic: SystemParametersInfo and NONCLIENTMETRICS  (Read 3051 times)

0 Members and 1 Guest are viewing this topic.

efgee

  • Guest
SystemParametersInfo and NONCLIENTMETRICS
« on: December 04, 2011, 07:46:06 PM »
The following code works in 32bit but not in 64bit  :'(
Don't know what I do wrong...

Code: OxygenBasic
  1. $FileName "test.exe"
  2.  
  3. includepath "..\inc\"
  4. 'include "RTL32.inc"
  5. include "RTL64.inc"
  6. include "MinWin.inc"
  7.  
  8. type NONCLIENTMETRICS
  9.   uint    cbSize;
  10.   int     iBorderWidth;
  11.   int     iScrollWidth;
  12.   int     iScrollHeight;
  13.   int     iCaptionWidth;
  14.   int     iCaptionHeight;
  15.   LOGFONT lfCaptionFont;
  16.   int     iSmCaptionWidth;
  17.   int     iSmCaptionHeight;
  18.   LOGFONT lfSmCaptionFont;
  19.   int     iMenuWidth;
  20.   int     iMenuHeight;
  21.   LOGFONT lfMenuFont;
  22.   LOGFONT lfStatusFont;
  23.   LOGFONT lfMessageFont;
  24. '#if (WINVER >= 0x0600)
  25.  int     iPaddedBorderWidth;
  26. '#endif
  27. end type
  28.  
  29. declare function SystemParametersInfo lib "user32"   Alias "SystemParametersInfoA" (byval uiAction as long, byval uiParam as long, byref pvParam as long, byval fWinIni as long) as bool
  30.  
  31. #define SPI_GETNONCLIENTMETRICS 0x0029
  32.  
  33. NONCLIENTMETRICS Metrics
  34. Metrics.cbSize = sizeof(NONCLIENTMETRICS)
  35.  
  36. if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), @Metrics, 0)
  37.     print "All Fine !"
  38. else
  39.     print "SystemParametersInfo Error !"
  40. end if
  41.  

BTW: can't write "unsigned int cbSize" inside the structure   ???
« Last Edit: December 04, 2011, 08:01:31 PM by efgee »

Charles Pegge

  • Guest
Re: SystemParametersInfo and NONCLIENTMETRICS
« Reply #1 on: December 04, 2011, 11:44:30 PM »
Hi Frank,

I've changed the prototype... main thing is to ensure that handles and pointers are sys type.


Oxygen Update:

I have also adjusted the Oxygen padding rules slightly for inherited structures. I found that both 32 bit and 64 bit versions require your structure to be 344 bytes. Then Windows is happy.

Code: OxygenBasic
  1. $FileName "t.exe"  
  2.  
  3. 'includepath "..\inc\"  
  4. 'include "RTL32.inc"  
  5. include "RTL64.inc"  
  6. include "MinWin.inc"  
  7.  
  8.  
  9. type NONCLIENTMETRICS  
  10.   uint    cbSize;  
  11.   int     iBorderWidth;  
  12.   int     iScrollWidth;  
  13.   int     iScrollHeight;  
  14.   int     iCaptionWidth;  
  15.   int     iCaptionHeight;  
  16.   LOGFONT lfCaptionFont;  
  17.   int     iSmCaptionWidth;  
  18.   int     iSmCaptionHeight;  
  19.   LOGFONT lfSmCaptionFont;  
  20.   int     iMenuWidth;  
  21.   int     iMenuHeight;  
  22.   LOGFONT lfMenuFont;  
  23.   LOGFONT lfStatusFont;  
  24.   LOGFONT lfMessageFont;  
  25.   int     iPaddedBorderWidth;  
  26. end type  
  27.  
  28.  
  29. /*
  30. BOOL WINAPI SystemParametersInfo(
  31.   __in     UINT uiAction,
  32.   __in     UINT uiParam,
  33.   __inout  PVOID pvParam,
  34.   __in     UINT fWinIni
  35. );
  36. */
  37. declare function SystemParametersInfo lib "user32"   Alias "SystemParametersInfoA" _
  38. (long uiAction, long uiParam, sys pvParam, long fWinIni) as bool  
  39.  
  40. #define SPI_GETNONCLIENTMETRICS 0x0029  
  41.  
  42. NONCLIENTMETRICS Metrics  
  43. Metrics.cbSize =  sizeof(NONCLIENTMETRICS)
  44.  
  45. 'print metrics.cbsize  
  46.  
  47. if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), @Metrics, 0)  
  48.     print "All Fine !"  
  49. else  
  50.     print "SystemParametersInfo Error !"  
  51. end if  
  52.  

Charles

Peter

  • Guest
Re: SystemParametersInfo and NONCLIENTMETRICS
« Reply #2 on: December 05, 2011, 03:12:56 AM »
Hi,

runs with 64 bit!
Code: [Select]
Type LOGFONT
     lfHeight         As Long
     lfWidth          As Long
     lfEscapement     As Long
     lfOrientation    As Long
     lfWeight         As Long
     lfItalic         As Byte
     lfUnderline      As Byte
     lfStrikeOut      As Byte
     lfCharSet        As Byte
     lfOutPrecision   As Byte
     lfClipPrecision  As Byte
     lfQuality        As Byte
     lfPitchAndFamily As Byte
     lfFaceName(LF_FACESIZE) As Byte
End Type


Type NONCLIENTMETRICS
     cbSize           As Long
     iBorderWidth     As Long
     iScrollWidth     As Long
     iScrollHeight    As Long
     iCaptionWidth    As Long
     iCaptionHeight   As Long
     lfCaptionFont    As LOGFONT
     iSMCaptionWidth  As Long
     iSMCaptionHeight As Long
     lfSMCaptionFont  As LOGFONT
     iMenuWidth       As Long
     iMenuHeight      As Long
     lfMenuFont       As LOGFONT
     lfStatusFont     As LOGFONT
     lfMessageFont    As LOGFONT
End Type

Def LF_FACESIZE = 32
Def SPI_GETNONCLIENTMETRICS 0x0029
Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long

NONCLIENTMETRICS Metrics 
Metrics.cbSize = sizeof(NONCLIENTMETRICS) 
 
if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &Metrics, 0) 
    print "Okay Fine !" 
else 
    print "SystemParametersInfo Error !" 
end if 

efgee

  • Guest
Re: SystemParametersInfo and NONCLIENTMETRICS
« Reply #3 on: December 05, 2011, 07:50:19 PM »
Charles, Peter,
your guys code didn't work either.

So I downloaded the newest version (from December 5th) replaced the one from December 4th and...
to my surprise all 3 examples work  :o

bye

Charles Pegge

  • Guest
Re: SystemParametersInfo and NONCLIENTMETRICS
« Reply #4 on: December 05, 2011, 09:27:59 PM »

Yes padding was the main problem, but your code appears to be incorrect in that you are passing an (@) address byref. This is one level of indirection too many.

I suspect another quirk in the compiler :)

Charles