Solved

Systemparametersinfo Api Code Won't Work?

Posted on 1998-06-03
5
1,323 Views
Last Modified: 2010-04-15
Systemparametersinfo Api Code Won't Work?

From Tim Brockway.   Email : BROCKWAYJT@AOL.COM
VB Version = Visual Basic 5, Windows 95

PROBLEM DESCRIPTION.

The following code to call the  SystemParametersInfo api won't work.  Calls to other functions of this api have worked fine ok for me but not the SPI_GETNONCLIENTMETRICS function.

Can anybody get this call to work.?? Any ideas ? Any thoughts would be most welcome.

Many thanks,
Tim

Option Explicit
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const LF_FACESIZE = 32
Private Const SPI_GETNONCLIENTMETRICS = 41
Private Const SPI_SETDRAGFULLWINDOWS = 37
Private Const SPI_SETNONCLIENTMETRICS = 42
Private Const SPIF_SENDWININICHANGE = &H2
Const SPIF_UPDATEINIFILE = &H1

Private 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
Private 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
Private Sub Form_Load()
Dim x As Long
Dim Struct As NONCLIENTMETRICS
Struct.cbSize = Len(Struct)
x = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, Struct.cbSize, Struct, 0&)
MsgBox (x)
End
End Sub
0
Comment
Question by:brockway
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 100 total points
Comment Utility
The 2nd param should be 0, according to the API reference
0
 

Author Comment

by:brockway
Comment Utility
Sorry Mike the api reference (in the small print) requires that the second parameter be set to the length of the main structure as quoted below:

Any other ideas?

SPI_GETNONCLIENTMETRICS
Retrieves the metrics associated with the nonclient area of nonminimized windows. The pvParam parameter must point to a NONCLIENTMETRICS structure that receives the information. Set the cbSize member of this structure and the uiParam parameter to sizeof(NONCLIENTMETRICS).
0
 
LVL 8

Expert Comment

by:MikeP090797
Comment Utility
This is taken from VC4.1 help:
PI_GETNONCLIENTMETRICS      Windows 95 only: Retrieves the metrics associated with the nonclient area of nonminimized windows. The pvParam parameter points to the NONCLIENTMETRICS structure to fill in.

uiParam
Depends on the system parameter being queried or set. For more information about systemwide parameters, see the uiAction parameter. If not otherwise indicated, specify zero.

0
 

Author Comment

by:brockway
Comment Utility
Exactly we are agreeing,

Your quote says "set to zero if not otherwise indicated by the the Uactions parameter.

When the uaction parameter is set to SPI_GETNONCLIENTMETRICS  the length must be put in the second parameter.

To settle the matter I tried a zero in the parameter you suggest and it did not work.

Thanks for the ideas, keep 'em comming.

Cordially

Tim.
0
 
LVL 1

Expert Comment

by:dtivmk
Comment Utility
// http://chabster.blogspot.com/2010/01/systemparametersinfo-with.html

NONCLIENTMETRICS ncm = { sizeof(NONCLIENTMETRICS), 0 };
#if (WINVER >= 0x0600)
OSVERSIONINFO osvi = { sizeof(OSVERSIONINFO), 0 };
VERIFY(GetVersionEx(&osvi));
if (osvi.dwMajorVersion < 6) {
    ncm.cbSize -= sizeof(int);
}
#endif
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)) {
    _defaultLogFont = ncm.lfMessageFont;
}
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now