Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #1121
| From | "Craig Dawson" <craig@control.nospam.net.au> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| References | (7 earlier) <4dccc7db$0$18690$91cee783@newsreader03.highway.telekom.at> <4dcdb621$0$47014$c30e37c6@pit-reader.telstra.net> <4dce2c3c$0$47014$c30e37c6@pit-reader.telstra.net> <4dceae1f$0$47016$c30e37c6@pit-reader.telstra.net> <iqpis8$qgv$1@news.m-online.net> |
| Subject | Re: Highlighting Buttons on tab page freezes program - Solved! |
| Date | 2011-05-17 21:55 +1000 |
| Message-ID | <4dd26220$0$32865$c30e37c6@pit-reader.telstra.net> (permalink) |
Thanks Gerhard,
Yes understood, nice bit of code! Will check things out here and very much
appreciated.
Regards, Craig.
"Gerhard Bunzel" <g.bunzel@domonet.de> wrote in message
news:iqpis8$qgv$1@news.m-online.net...
> Craig,
>
> ...
> dwSize := DWORD(_CAST, MakeLong(WORD(_CAST, winSize.cx),
> WORD(_CAST,winSize.cy)))
> nWidth := LoWord( dwSize )
> ....
>
> ...why call a MAKELONG(...) to use the LoWord(..)? You can simply use
> winSize.cx.
>
> Have a look at this function, to get the Textsize:
>
> FUNCTION GetTextExtentWidth ( hWnd AS PTR, sText AS STRING ) AS LONG
> PASCAL
> LOCAL oSize AS _winSIZE
> LOCAL iWidth AS LONG
>
> oSize := MemAlloc( _SizeOf( _winSIZE ) )
> GetTextExtentPoint32( GetDC( hWnd), String2Psz(sText), INT(SLen(sText)),
> oSize )
> iWidth := oSize.cx
> MemFree( oSize )
>
> RETURN iWidth
>
>
> HTH
>
> Gerhard
>
>
>
> "Craig Dawson" <craig@control.nospam.net.au> schrieb im Newsbeitrag
> news:4dceae1f$0$47016$c30e37c6@pit-reader.telstra.net...
>> Aha - found the culprit!
>>
>> The Expose() method calls GetDisplayTextWidth() to work out if the length
>> of each button's caption text to determine if it is multiline text or
>> not. GetDisplayTextWidth() creates ptrs for fonts during the
>> calculations, however these ptrs are never destroyed after use so just
>> keep building up.
>>
>> By deleting these ptrs after use solves the problem!
>>
>> Thanks to all for your help, really appreciated.
>> Revised GetDisplayTextWidth() code below for those who want it.
>>
>> FUNCTION getDisplayTextWidth( cText, xFont )
>>
>> // returns the width of a text string in PIXELS
>>
>> // needs to get a pointer to a font!
>>
>> LOCAL dwSize AS DWORD
>>
>> LOCAL winSize IS _winSize
>>
>> LOCAL nWidth AS DWORD
>>
>> LOCAL hOldFont AS PTR
>>
>> LOCAL hFont AS PTR
>>
>> LOCAL hDC AS PTR
>>
>> hDC := CreateIC( String2Psz( "DISPLAY" ), NULL_PSZ, NULL_PSZ, NULL_PTR )
>>
>> IF !(hDC == NULL_PTR)
>>
>> IF IsPtr(xFont)
>>
>> hFont := xFont
>>
>> ELSEIF IsInstanceOfUsual(xFont,#font)
>>
>> hFont := xFont:handle()
>>
>> ELSE
>>
>> (errorBox{,"Error: invalid font parameter in function
>> getDisplayTextWidth( cText, xFont )"}):show()
>>
>> ENDIF
>>
>> IF !(hFont == NULL_PTR)
>>
>> hOldFont := SelectObject( hDC, hFont )
>>
>> ENDIF
>>
>> GetTextExtentPoint32( hDC, Cast2Psz( cText ), SLen( cText ), @winSize )
>>
>> dwSize := DWORD(_CAST, MakeLong(WORD(_CAST, winSize.cx),
>> WORD(_CAST,winSize.cy)))
>>
>> nWidth := LoWord( dwSize )
>>
>> IF !(hOldFont == NULL_PTR)
>>
>> SelectObject( hDC, hOldFont )
>>
>> ENDIF
>>
>> // CWD
>>
>> DeleteDC(hDC)
>>
>> DeleteDC(hOldFont)
>>
>> DeleteDC(hFont)
>>
>> ENDIF
>>
>>
>> // CWD
>>
>> hDC := NULL_PTR
>>
>> hOldFont := NULL_PTR
>>
>> hFont := NULL_PTR
>>
>> RETURN nWidth
>>
>>
>>
>
>
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-10 07:39 +1000
Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-09 21:51 -0500
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-10 14:09 +1000
Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-10 05:52 -0500
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-11 01:53 +1000
Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-10 11:57 -0500
Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-10 11:57 -0500
Re: Highlighting Buttons on tab page freezes program "Bernhard Mayer" <Idonotexisthere@nowhere.com> - 2011-05-11 07:35 +0200
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-13 06:59 +1000
Re: Highlighting Buttons on tab page freezes program "Stephen Quinn" <stevejqNO@bigpondSPAM.net.au> - 2011-05-13 08:57 +1000
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-14 08:47 +1000
Re: Highlighting Buttons on tab page freezes program "Bernhard Mayer" <Idonotexisthere@nowhere.com> - 2011-05-13 07:55 +0200
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-14 08:52 +1000
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-14 17:16 +1000
Re: Highlighting Buttons on tab page freezes program - Solved! "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-15 02:30 +1000
Re: Highlighting Buttons on tab page freezes program - Solved! "Gerhard Bunzel" <g.bunzel@domonet.de> - 2011-05-16 00:08 +0200
Re: Highlighting Buttons on tab page freezes program - Solved! "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-17 21:55 +1000
Re: Highlighting Buttons on tab page freezes program - Solved! "Willie Moore" <williem@wmconsulting.com> - 2011-05-17 07:19 -0500
Re: Highlighting Buttons on tab page freezes program - Solved! "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-05-18 17:00 +0200
Re: Highlighting Buttons on tab page freezes program Sherlock <sherlock@sherlock.com.au> - 2011-05-10 05:01 -0700
Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-11 01:58 +1000
Re: Highlighting Buttons on tab page freezes program "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-05-18 16:39 +0200
Re: Highlighting Buttons on tab page freezes program "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-05-18 16:42 +0200
csiph-web