Article View: borland.public.cppbuilder.migration
Article #146Re: Call to SystemParametersInfo() no longer works under Borland C++ Builder 7
From: Piet
Date: Thu, 02 Oct 2008 09:59
Date: Thu, 02 Oct 2008 09:59
71 lines
4374 bytes
4374 bytes
On Aug 5, 10:45 pm, "Remy Lebeau \(TeamB\)" <no.s...@no.spam.com>
wrote:
> "James O'Brien" <obr...@niscnet.com> wrote in message
>
> news:4898b6ce$1@newsgroups.borland.com...
>
> > I have code which performs custom painting to a window's title
> > bar(non-client area). I recently migrated from "C++ Build v6" to
> > "C++ Builder 2007" and calls to SystemParametersInfo() no
> > longer work.
>
> That is because the NONCLIENTMETRICS structure changed between those two
> versions. BCB2007 has a newer Platform SDK, where the structure has an
> additional iPaddedBorderWidth that did not exist yet in the SDK that BCB6
> has. You are setting the cbSize member to the newer structure size, which
> is not valid on the OS you are calling SystemParametersInfo() on. You have
> to take the OS version into account when using API structures that have a
> cbSize member, such as NONCLIENTMETRICS. This is clearly stated in the
> documentation for NONCLIENTMETRICS:
>
> http://msdn.microsoft.com/en-us/library/ms724506(VS.85).aspx
>
> If the iPaddedBorderWidth member of the NONCLIENTMETRICS structure is
> present, this structure is 4 bytes larger than for an application that is
> compiled with _WIN32_WINNT less than or equal to 0x0502. For more
> information about conditional compilation, see Using the Windows Headers
> (http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx).
>
> Windows Server 2003 and Windows XP/2000: If an application that is
> compiled for Windows Server 2008 or Windows Vista must also run on Windows
> Server 2003 or Windows XP/2000, use the GetVersionEx function to check the
> operating system version at run time and, if the application is running on
> Windows Server 2003 or Windows XP/2000, subtract the size of the
> iPaddedBorderWidth member from the cbSize member of the NONCLIENTMETRICS
> structure before calling the SystemParametersInfo function.
>
> In other words, you need to update your code to do something like the
> following:
>
> NONCLIENTMETRICS NCM = {0};
> NCM.cbSize = sizeof(NONCLIENTMETRICS);
>
> if( Win32MajorVersion < 6 )
> {
> NCM.cbSize -= 4;
>
> // alternatively:
> // NCM.cbSize = offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
> }
>
> SystemParametersInfo(SPI_GETNONCLIENTMETRICS, NCM.cbSize, (PVOID)&NCM,
> 0);
>
> Gambit
Hi
I had the same problem except that my code worked in debug mode but
not in release. I tried Gambit's trick but eventually found that the
structure size is correct as given by sizeof(). What's not correct is
that iPaddedBorderWidth is defined in release build but not in debug
build, indicating that WINVER >= 0x600 when checked in winuser.h
during release build. When I comment iPaddedBorderWidth out as below,
everything is fine. I now have a solution that's ok for me, but I
don't understand where the incorrect WINVER comes from.
#if(WINVER >= 0x0600)
// int iPaddedBorderWidth;
#endif /* WINVER >= 0x0600 */
} NONCLIENTMETRICSA, *PNONCLIENTMETRICSA, FAR* LPNONCLIENTMETRICSA;
Piet
Technical Details
Message-ID:
<9e971233-00e5-4363-af80-54dc99486e0c@64g2000hsm.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!64g2000hsm.googlegroups.com!not-for-mailReferences:
<4898b6ce$1@newsgroups.borland.com> <4898bc71$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!64g2000hsm.googlegroups.com!not-for-mail From: Piet <pterblan@gmail.com> Newsgroups: borland.public.cppbuilder.migration Subject: Re: Call to SystemParametersInfo() no longer works under Borland C++ Builder 7 Date: Thu, 2 Oct 2008 02:59:59 -0700 (PDT) Organization: http://groups.google.com Lines: 71 Message-ID: <9e971233-00e5-4363-af80-54dc99486e0c@64g2000hsm.googlegroups.com> References: <4898b6ce$1@newsgroups.borland.com> <4898bc71$1@newsgroups.borland.com> NNTP-Posting-Host: 146.64.81.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1222941599 16809 127.0.0.1 (2 Oct 2008 09:59:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 2 Oct 2008 09:59:59 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 64g2000hsm.googlegroups.com; posting-host=146.64.81.8; posting-account=wRkXowoAAAA_KATXcZsV1y3r9-KqUpMI User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 hermes.csir.co.za:3128 (squid/2.5.STABLE12)