1. Help with SystemParametersInfo call
- Posted by Pete Stoner <stoner.pete at gmai?.co?> Nov 06, 2007
- 661 views
Hi Guys, I need some help, I am using my window caption bar for some variable text. To prevent truncation of this I need to detect if the user has his Display Properties set to "large fonts" (Note not the same as DPI - I can detect that OK). A google (http://vbnet.mvps.org/index.html?code/screen/systemparaminfononclientarea.htm) suggests using a SystemParametersInfo call with SPI_GETNONCLIENTMETRICS. I coded the following but it fails with a zero return code. Can anyone tell me where I have gone wrong?
include win32lib.ew without warning constant -- LOGFONT struct lfHeight = w32allot( Long ), lfWidth = w32allot( Long ), lfEscapement = w32allot( Long ), lfOrientation = w32allot( Long ), lfWeight = w32allot( Long ), lfItalic = w32allot( Byte ), lfUnderline = w32allot( Byte ), lfStrikeOut = w32allot( Byte ), lfCharSet = w32allot( Byte ), lfOutPrecision = w32allot( Byte ), lfClipPrecision = w32allot( Byte ), lfQuality = w32allot( Byte ), lfPitchAndFamily = w32allot( Byte ), lfFaceName = w32allot( {32, Strz} ), SIZEOF_LOGFONT = w32allotted_size() constant -- NONCLIENTMETRICS struct NCM_cbSize = w32allot(Long), NCM_iBorderWidth = w32allot(Long), NCM_iScrollWidth = w32allot(Long), NCM_iScrollHeight = w32allot(Long), NCM_iCaptionWidth = w32allot(Long), NCM_iCaptionHeight = w32allot(Long), NCM_lfCaptionFont = w32allot(Ptr), NCM_iSmCaptionWidth = w32allot(Long), NCM_iSmCaptionHeight = w32allot(Long), NCM_lfSmCaptionFont = w32allot(Ptr), NCM_iMenuWidth = w32allot(Long), NCM_iMenuHeight = w32allot(Long), NCM_lfMenuFont = w32allot(Ptr), NCM_lfStatusFont = w32allot(Ptr), NCM_lfMessageFont = w32allot(Ptr), SIZEOF_NCM = w32allotted_size() atom memset atom CaptionFont, SmCaptionFont, MenuFont, StatusFont, MessageFont, NCM_struct memset = w32new_memset() NCM_struct = w32acquire_mem(memset, SIZEOF_NCM) CaptionFont = w32acquire_mem(memset, SIZEOF_LOGFONT) SmCaptionFont = w32acquire_mem(memset, SIZEOF_LOGFONT) MenuFont = w32acquire_mem(memset, SIZEOF_LOGFONT) StatusFont = w32acquire_mem(memset, SIZEOF_LOGFONT) MessageFont = w32acquire_mem(memset, SIZEOF_LOGFONT) w32store ( NCM_struct, NCM_cbSize, SIZEOF_NCM ) w32store ( NCM_struct, NCM_lfCaptionFont, CaptionFont ) w32store ( NCM_struct, NCM_lfSmCaptionFont, SmCaptionFont ) w32store ( NCM_struct, NCM_lfMenuFont, MenuFont ) w32store ( NCM_struct, NCM_lfStatusFont, StatusFont ) w32store ( NCM_struct, NCM_lfMessageFont, MessageFont ) ? w32Func(xSystemParametersInfo,{SPI_GETNONCLIENTMETRICS, SIZEOF_NCM, NCM_struct, 0})
Regards PeteS
2. Re: Help with SystemParametersInfo call
- Posted by Bernie Ryan <xotron at b?uefro?.com> Nov 06, 2007
- 642 views
Pete: A easier way would be to use:
atom lpString, pt, void, width, height lpString = allocate_string("M") pt allocate(8) void = GetTextExtentPoint32A(hDC,lpString,1,pt) -- this is the size of a single font character note -- use capital M because it would be nearest to largest character. width = peek4u(pt) height = peek4u(pt+4)
-- HDC hdc, // handle to device context -- LPCTSTR lpString, // pointer to text string -- int cbString, // number of characters in string -- LPSIZE lpSize // pointer to structure for string size Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
3. Re: Help with SystemParametersInfo call
- Posted by Pete Stoner <stoner.pete at gm?i?.com> Nov 06, 2007
- 617 views
Thanks Bernie, That would be easier - if it worked! it always returns 12 and 16 for the width and height with the fonts set to Normal or Large. I tried the hdc for both the window and for "Screen". It may return different values if the DPI is changed but I need to detect when the Font size is changed (in Display Properties -> Appearance, Font Size). Regards Pete S
4. Re: Help with SystemParametersInfo call
- Posted by Bernie Ryan <xotron at blue?rog.co?> Nov 06, 2007
- 632 views
Pete Stoner wrote: > > > Thanks Bernie, > That would be easier - if it worked! it always returns 12 and 16 for the width > and height with the fonts set to Normal or Large. I tried the hdc for both the > window and for "Screen". It may return different values if the DPI is changed > but I need to detect when the Font size is changed (in Display Properties -> > Appearance, Font Size). > Pete: One question, why aren't you using a status bar to display messages ?? Then you would have an easier job. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
5. Re: Help with SystemParametersInfo call
- Posted by Pete Stoner <stoner.pete at ??ail.com> Nov 06, 2007
- 625 views
- Last edited Nov 07, 2007
Bernie Ryan wrote: > > Pete Stoner wrote: > > > > > > Thanks Bernie, > > That would be easier - if it worked! it always returns 12 and 16 for the > > width > > and height with the fonts set to Normal or Large. I tried the hdc for both > > the > > window and for "Screen". It may return different values if the DPI is > > changed > > but I need to detect when the Font size is changed (in Display Properties -> > > Appearance, Font Size). > > > > Pete: > > One question, why aren't you using a status bar to display messages ?? > > Then you would have an easier job. > > Bernie > Bernie, The text I display is not a "message", but rather some important information that first lived along the top of the client area, but I needed to reduce the window size and it makes sense (and the users like it) to move it to the window title bar. PeteS
6. Re: Help with SystemParametersInfo call
- Posted by Pete Lomax <petelomax at blueyonde?.co?uk> Nov 06, 2007
- 621 views
- Last edited Nov 07, 2007
Pete Stoner wrote: > > but it fails with a zero return code. > Can anyone tell me where I have gone wrong? > > }}} <eucode> > NCM_lfCaptionFont = w32allot(Ptr), > </eucode> {{{ > If I change that and the other 4 to w32allot(SIZEOF_LOGFONT) to match the definition I found in arwen, then the call no longer returns 0. I assume that where msdn states these are pointers, it lies. Regards, Pete
7. Re: Help with SystemParametersInfo call
- Posted by Bernie Ryan <xotron at b?uefrog.com> Nov 06, 2007
- 615 views
- Last edited Nov 07, 2007
Pete Stoner wrote: > > }}} <eucode> > include win32lib.ew > without warning > > constant -- LOGFONT struct > lfHeight = w32allot( Long ), > lfWidth = w32allot( Long ), > lfEscapement = w32allot( Long ), > lfOrientation = w32allot( Long ), > lfWeight = w32allot( Long ), > lfItalic = w32allot( Byte ), > lfUnderline = w32allot( Byte ), > lfStrikeOut = w32allot( Byte ), > lfCharSet = w32allot( Byte ), > lfOutPrecision = w32allot( Byte ), > lfClipPrecision = w32allot( Byte ), > lfQuality = w32allot( Byte ), > lfPitchAndFamily = w32allot( Byte ), > lfFaceName = w32allot( {32, Strz} ), > SIZEOF_LOGFONT = w32allotted_size() > > constant -- NONCLIENTMETRICS struct > NCM_cbSize = w32allot(Long), > NCM_iBorderWidth = w32allot(Long), > NCM_iScrollWidth = w32allot(Long), > NCM_iScrollHeight = w32allot(Long), > NCM_iCaptionWidth = w32allot(Long), > NCM_iCaptionHeight = w32allot(Long), > NCM_lfCaptionFont = w32allot(Ptr), > NCM_iSmCaptionWidth = w32allot(Long), > NCM_iSmCaptionHeight = w32allot(Long), > NCM_lfSmCaptionFont = w32allot(Ptr), > NCM_iMenuWidth = w32allot(Long), > NCM_iMenuHeight = w32allot(Long), > NCM_lfMenuFont = w32allot(Ptr), > NCM_lfStatusFont = w32allot(Ptr), > NCM_lfMessageFont = w32allot(Ptr), > SIZEOF_NCM = w32allotted_size() > > </eucode> {{{ Pete: The problem with your code is the description of your NONCLIENTMETRICS structure is not correct. The size of the structure should be 340 bytes ( your's is 60 ) The LOGFONT structures in the NONCLIENTMETRICS structure are nested structures NOT pointers. In the place of each font pointer in the NONCLIENTMETRICS structure you have to have a LOGFONT structure not a pointer. I don't know how to describe nested structures in the win32lib because my libraries handle this in a different way. You need to end up with a structure thats 340 bytes in size. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
8. Re: Help with SystemParametersInfo call
- Posted by Bernie Ryan <xotron at bl?ef?og.com> Nov 06, 2007
- 606 views
- Last edited Nov 07, 2007
Pete: Here is the structure. <code> constant -- NONCLIENTMETRICS struct NCM_cbSize = w32allot(Long), NCM_iBorderWidth = w32allot(Long), NCM_iScrollWidth = w32allot(Long), NCM_iScrollHeight = w32allot(Long), NCM_iCaptionWidth = w32allot(Long), NCM_iCaptionHeight = w32allot(Long), NCM_lfCaptionFont_lfHeight = w32allot( Long ), NCM_lfCaptionFont_lfWidth = w32allot( Long ), NCM_lfCaptionFont_lfEscapement = w32allot( Long ), NCM_lfCaptionFont_lfOrientation = w32allot( Long ), NCM_lfCaptionFont_lfWeight = w32allot( Long ), NCM_lfCaptionFont_lfItalic = w32allot( Byte ), NCM_lfCaptionFont_lfUnderline = w32allot( Byte ), NCM_lfCaptionFont_lfStrikeOut = w32allot( Byte ), NCM_lfCaptionFont_lfCharSet = w32allot( Byte ), NCM_lfCaptionFont_lfOutPrecision = w32allot( Byte ), NCM_lfCaptionFont_lfClipPrecision = w32allot( Byte ), NCM_lfCaptionFont_lfQuality = w32allot( Byte ), NCM_lfCaptionFont_lfPitchAndFamily = w32allot( Byte ), NCM_lfCaptionFont_lfFaceName = w32allot( {32, Strz} ), NCM_iSmCaptionWidth = w32allot(Long), NCM_iSmCaptionHeight = w32allot(Long), NCM_lfSmCaptionFont_lfHeight = w32allot( Long ), NCM_lfSmCaptionFont_lfWidth = w32allot( Long ), NCM_lfSmCaptionFont_lfEscapement = w32allot( Long ), NCM_lfSmCaptionFont_lfOrientation = w32allot( Long ), NCM_lfSmCaptionFont_lfWeight = w32allot( Long ), NCM_lfSmCaptionFont_lfItalic = w32allot( Byte ), NCM_lfSmCaptionFont_lfUnderline = w32allot( Byte ), NCM_lfSmCaptionFont_lfStrikeOut = w32allot( Byte ), NCM_lfSmCaptionFont_lfCharSet = w32allot( Byte ), NCM_lfSmCaptionFont_lfOutPrecision = w32allot( Byte ), NCM_lfSmCaptionFont_lfClipPrecision = w32allot( Byte ), NCM_lfSmCaptionFont_lfQuality = w32allot( Byte ), NCM_lfSmCaptionFont_lfPitchAndFamily = w32allot( Byte ), NCM_lfSmCaptionFont_lfFaceName = w32allot( {32, Strz} ), NCM_iMenuWidth = w32allot(Long), NCM_iMenuHeight = w32allot(Long), NCM_lfMenuFont_lfHeight = w32allot( Long ), NCM_lfMenuFont_lfWidth = w32allot( Long ), NCM_lfMenuFont_lfEscapement = w32allot( Long ), NCM_lfMenuFont_lfOrientation = w32allot( Long ), NCM_lfMenuFont_lfWeight = w32allot( Long ), NCM_lfMenuFont_lfItalic = w32allot( Byte ), NCM_lfMenuFont_lfUnderline = w32allot( Byte ), NCM_lfMenuFont_lfStrikeOut = w32allot( Byte ), NCM_lfMenuFont_lfCharSet = w32allot( Byte ), NCM_lfMenuFont_lfOutPrecision = w32allot( Byte ), NCM_lfMenuFont_lfClipPrecision = w32allot( Byte ), NCM_lfMenuFont_lfQuality = w32allot( Byte ), NCM_lfMenuFont_lfPitchAndFamily = w32allot( Byte ), NCM_lfMenuFont_lfFaceName = w32allot( {32, Strz} ), NCM_lfStatusFont_lfHeight = w32allot( Long ), NCM_lfStatusFont_lfWidth = w32allot( Long ), NCM_lfStatusFont_lfEscapement = w32allot( Long ), NCM_lfStatusFont_lfOrientation = w32allot( Long ), NCM_lfStatusFont_lfWeight = w32allot( Long ), NCM_lfStatusFont_lfItalic = w32allot( Byte ), NCM_lfStatusFont_lfUnderline = w32allot( Byte ), NCM_lfStatusFont_lfStrikeOut = w32allot( Byte ), NCM_lfStatusFont_lfCharSet = w32allot( Byte ), NCM_lfStatusFont_lfOutPrecision = w32allot( Byte ), NCM_lfStatusFont_lfClipPrecision = w32allot( Byte ), NCM_lfStatusFont_lfQuality = w32allot( Byte ), NCM_lfStatusFont_lfPitchAndFamily = w32allot( Byte ), NCM_lfStatusFont_lfFaceName = w32allot( {32, Strz} ), NCM_lfMessageFont_lfHeight = w32allot( Long ), NCM_lfMessageFont_lfWidth = w32allot( Long ), NCM_lfMessageFont_lfEscapement = w32allot( Long ), NCM_lfMessageFont_lfOrientation = w32allot( Long ), NCM_lfMessageFont_lfWeight = w32allot( Long ), NCM_lfMessageFont_lfItalic = w32allot( Byte ), NCM_lfMessageFont_lfUnderline = w32allot( Byte ), NCM_lfMessageFont_lfStrikeOut = w32allot( Byte ), NCM_lfMessageFont_lfCharSet = w32allot( Byte ), NCM_lfMessageFont_lfOutPrecision = w32allot( Byte ), NCM_lfMessageFont_lfClipPrecision = w32allot( Byte ), NCM_lfMessageFont_lfQuality = w32allot( Byte ), NCM_lfMessageFont_lfPitchAndFamily = w32allot( Byte ), NCM_lfMessageFont_lfFaceName = w32allot( {32, Strz} ), SIZEOF_NCM = w32allotted_size() </code> Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
9. Re: Help with SystemParametersInfo call
- Posted by Pete Stoner <stoner.pete at ?mail.?om> Nov 06, 2007
- 607 views
- Last edited Nov 07, 2007
Pete Lomax wrote: > If I change that and the other 4 to w32allot(SIZEOF_LOGFONT) to match the > definition > I found in arwen, then the call no longer returns 0. I assume that where msdn > states these are pointers, it lies. > > Regards, > Pete Thanks Pete (and Bernie) . More fool me for believing the MS Docs since if specifically says for each of them.. "A pointer to a LOGFONT structure that contains information about the font..." PeteS
10. Re: Help with SystemParametersInfo call
- Posted by Pete Stoner <stoner.pete at g?ail.co?> Nov 06, 2007
- 619 views
- Last edited Nov 07, 2007
Thanks Bernie, That works fine, using your stuct definition I get
if w32Func(xSystemParametersInfo,{SPI_GETNONCLIENTMETRICS, SIZEOF_NCM, NCM_struct, 0}) then printf(1, "%s\n", { w32fetch( NCM_struct, NCM_lfCaptionFont_lfFaceName )}) printf(1, "%d\n", {-w32fetch( NCM_struct, NCM_lfSmCaptionFont_lfHeight )}) end if
I get Trebuchet MS and 11, 12 & 13 for "Normal", "Large Fonts" and "Extra Large Fonts" settings respectively.. Just what I needed. Thanks again, PeteS
11. Re: Help with SystemParametersInfo call
- Posted by CChris <christian.cuvier at agric?lture.g?uv.fr> Nov 07, 2007
- 634 views
There is an inconsistency on MSDN indeed ( http://msdn2.microsoft.com/en-us/library/ms724506.aspx ). The descriotion of the members wrongly refers to them as pointers to LOGFONT structures, but the list in the grey rectangle mentions LOGFONT type parameters, which is correct. By the way, in win32lib 0.70.1 and later: you can say:
-- define a structure member as a LOGFONT structure someStruct_myLogFont = w32allot(ID_LOGFONT) -- define a structure member as an array of LOGFONT structures someStruct_myLogFont = w32allot({3,ID_LOGFONT}) -- nested fields can be specified like this w32store(addr,{someStruct_myLogFont,lfHeight},120)
w32constants.ew has quite a few definitions like this. Check out the docs for further ways to deal with variable size members, or arrays which are counted, or whose ends have a specific marker (some Windows structures are like that :( ). Unions are supported too. CChris