Author Topic: Resize Reposition Labels ???  (Read 163 times)

Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Resize Reposition Labels ???
« on: June 28, 2021, 07:06:42 PM »
Resize and reposition label controls based on font and font size?


MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Resize Reposition Labels ???
« Reply #1 on: June 28, 2021, 10:40:23 PM »
Resize and reposition label controls based on font and font size?

Robert,

I threw this together in 10 minutes, so not extensively tested.  It seems to work
but it may be horribly wrong too.  Or it may be a good starting point.  Or not!
Caveat Emptor

Code: [Select]
GUI "Test For Robert"

GLOBAL Form1 AS HWND
GLOBAL Label AS HWND
CONST  ID_Label = 101

SUB FormLoad
  Form1 = BCX_FORM("Form1")
  Label = BCX_LABEL("Now is the time .. blah blah blah",Form1,ID_Label, 10,10,0,0 )
  BCX_SET_FONT(Label, "Arial", 20 )  ' Uncomment this and re-compile
  '******************************************************************
  CALL AdjustForFont(Label)
  '******************************************************************
  CENTER (Form1)
  SHOW   (Form1)
END SUB


BEGIN EVENTS
END EVENTS


SUB AdjustForFont (hObj AS HWND)
  DIM Txt$
  DIM LTxt
  DIM AS SIZE MySize
  DIM AS HDC hdc
  DIM X, Y

  Txt$ =  BCX_GET_TEXT$(hObj)
  LTxt = LEN(Txt$)

  hdc = GetDC(hObj)
  GetTextExtentPoint32 (hdc, Txt$, LEN(Txt$), &MySize)
  ReleaseDC(hObj, hdc)

  X = MySize.cx
  Y = MySize.cy

  SetWindowPos(hObj, NULL, 0, 0, X*LTxt, Y*LTxt, SWP_NOMOVE)
END SUB


iancasey

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Resize Reposition Labels ???
« Reply #2 on: June 28, 2021, 11:32:56 PM »
Hi Robert,
another way, the 1 entry in my personal BCXOLR snippets from 2006

Sub AutosizeStaticCtrl(Ctrl as HWND)
'syntax:   Call AutosizeStaticCtrl(controlname)

Dim NewText as String
Dim rc1 as RECT
Dim hfont as HFONT
Dim fsize as SIZE PTR

GetWindowRect(Ctrl,&rc1)
hfont = (HFONT) SendMessage(Ctrl,WM_GETFONT,0,0)
NewText$ = trim$(BCX_GET_TEXT$(Ctrl)& "A")               '<--add extra letter as filler only for size
fsize = GETTEXTSIZE(NewText$,Ctrl, hfont)

SetWindowPos(Ctrl,0,rc1.left,rc1.top,fsize->cx,rc1.bottom,SWP_NOMOVE | SWP_NOZORDER)

End Sub


Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Resize Reposition Labels ???
« Reply #3 on: June 28, 2021, 11:53:11 PM »
Resize and reposition label controls based on font and font size?

Robert,

I threw this together in 10 minutes, so not extensively tested.  It seems to work
but it may be horribly wrong too.  Or it may be a good starting point.  Or not!
Caveat Emptor

Code: [Select]
GUI "Test For Robert"

GLOBAL Form1 AS HWND
GLOBAL Label AS HWND
CONST  ID_Label = 101

SUB FormLoad
  Form1 = BCX_FORM("Form1")
  Label = BCX_LABEL("Now is the time .. blah blah blah",Form1,ID_Label, 10,10,0,0 )
  BCX_SET_FONT(Label, "Arial", 20 )  ' Uncomment this and re-compile
  '******************************************************************
  CALL AdjustForFont(Label)
  '******************************************************************
  CENTER (Form1)
  SHOW   (Form1)
END SUB


BEGIN EVENTS
END EVENTS


SUB AdjustForFont (hObj AS HWND)
  DIM Txt$
  DIM LTxt
  DIM AS SIZE MySize
  DIM AS HDC hdc
  DIM X, Y

  Txt$ =  BCX_GET_TEXT$(hObj)
  LTxt = LEN(Txt$)

  hdc = GetDC(hObj)
  GetTextExtentPoint32 (hdc, Txt$, LEN(Txt$), &MySize)
  ReleaseDC(hObj, hdc)

  X = MySize.cx
  Y = MySize.cy

  SetWindowPos(hObj, NULL, 0, 0, X*LTxt, Y*LTxt, SWP_NOMOVE)
END SUB


Hi MrBCX:

I appreciate your effort. I was trying to find an example in my Archive, I was sure there was something in the past but found nothing. I was planning on using GetTextExtentPoint32 and you have saved me a couple of steps. I'm trying to get the font/label resizing working in Mike Sanders ColorTool. The font resizes as advertised but the label doesn't so at anything above the default size the labels and info overlap.


Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Resize Reposition Labels ???
« Reply #4 on: June 29, 2021, 12:06:49 AM »
Hi Robert,
another way, the 1 entry in my personal BCXOLR snippets from 2006

Sub AutosizeStaticCtrl(Ctrl as HWND)
'syntax:   Call AutosizeStaticCtrl(controlname)

Dim NewText as String
Dim rc1 as RECT
Dim hfont as HFONT
Dim fsize as SIZE PTR

GetWindowRect(Ctrl,&rc1)
hfont = (HFONT) SendMessage(Ctrl,WM_GETFONT,0,0)
NewText$ = trim$(BCX_GET_TEXT$(Ctrl)& "A")               '<--add extra letter as filler only for size
fsize = GETTEXTSIZE(NewText$,Ctrl, hfont)

SetWindowPos(Ctrl,0,rc1.left,rc1.top,fsize->cx,rc1.bottom,SWP_NOMOVE | SWP_NOZORDER)

End Sub

Hi Ian:

Thank you for this snippet. I think that there must have been something on the Yahoo Forum that is in the back of my mind. Your code does look familiar. Between this and MrBCX's contribution I will be able to solve the problem.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Resize Reposition Labels ???
« Reply #5 on: June 29, 2021, 12:15:44 AM »
Robert -- If you can send me a link to Mike Sanders ColorTool, I'll have a look.

Alternatively -- upload a zip to this thread.

Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Resize Reposition Labels ???
« Reply #6 on: June 29, 2021, 12:43:47 AM »
Robert -- If you can send me a link to Mike Sanders ColorTool, I'll have a look.

Alternatively -- upload a zip to this thread.

Hi MrBCX:

It's very handy but but was built in the heyday of LCCWin32 and needs several tweaks. You may be able to compile it as is with your LCC.

This is the original March 8 2004 version from

http://groups.yahoo.com/group/BCX/files/Michael_Sanders/colortool.zip

When he moved all his stuff to the Curiosities site, he didn't post the ColorTool or other utilities. Today I noticed in the ColorTool Helpfile that most pages have a Copyright Vega-Tek notice at the bottom. Vega-Tek ???

Anyway, here it is attached. Virustotal: 2 warnings

https://www.virustotal.com/gui/file/d5d70f937087d354af856a12220354f5cb273b435f4a258e6e8d2289a32f7c3f/detection

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Resize Reposition Labels ???
« Reply #7 on: June 29, 2021, 09:08:41 AM »
Robert -- If you can send me a link to Mike Sanders ColorTool, I'll have a look.

Alternatively -- upload a zip to this thread.

Hi MrBCX:

It's very handy but but was built in the heyday of LCCWin32 and needs several tweaks. You may be able to compile it as is with your LCC.

This is the original March 8 2004 version from

http://groups.yahoo.com/group/BCX/files/Michael_Sanders/colortool.zip

When he moved all his stuff to the Curiosities site, he didn't post the ColorTool or other utilities. Today I noticed in the ColorTool Helpfile that most pages have a Copyright Vega-Tek notice at the bottom. Vega-Tek ???

Anyway, here it is attached. Virustotal: 2 warnings

https://www.virustotal.com/gui/file/d5d70f937087d354af856a12220354f5cb273b435f4a258e6e8d2289a32f7c3f/detection

Thanks Robert ... I'll tinker and share what I learn.

Re: Vega-Tek,  I tracked this down:

https://web.archive.org/web/20031202170854/http://www.vega-tek.com/index.html



MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: Resize Reposition Labels ???
« Reply #8 on: June 29, 2021, 10:46:15 AM »
Robert,

Attached is a tweaked copy of Mike's 2004 "C" file that compiles with Pelles v10

I had to rebuild the .res using Lcc's resource compiler to make Pelles' happy. 
With a little more work, that too could be made Pelles PORC compatible.

Finally, I've included a batch file to build it all. 
It assumes the paths and resources are as they exist in the zip.

This should give you something to work with and tweak to your needs.



Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Resize Reposition Labels ???
« Reply #9 on: June 29, 2021, 12:56:37 PM »
Robert,

Attached is a tweaked copy of Mike's 2004 "C" file that compiles with Pelles v10

I had to rebuild the .res using Lcc's resource compiler to make Pelles' happy. 
With a little more work, that too could be made Pelles PORC compatible.

Finally, I've included a batch file to build it all. 
It assumes the paths and resources are as they exist in the zip.

This should give you something to work with and tweak to your needs.

Thank you for your help, MrBCX, I will continue my tweaks.

Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Re: Resize Reposition Labels ???
« Reply #10 on: June 29, 2021, 01:01:48 PM »
Robert -- If you can send me a link to Mike Sanders ColorTool, I'll have a look.

Alternatively -- upload a zip to this thread.

Hi MrBCX:

It's very handy but but was built in the heyday of LCCWin32 and needs several tweaks. You may be able to compile it as is with your LCC.

This is the original March 8 2004 version from

http://groups.yahoo.com/group/BCX/files/Michael_Sanders/colortool.zip

When he moved all his stuff to the Curiosities site, he didn't post the ColorTool or other utilities. Today I noticed in the ColorTool Helpfile that most pages have a Copyright Vega-Tek notice at the bottom. Vega-Tek ???

Anyway, here it is attached. Virustotal: 2 warnings

https://www.virustotal.com/gui/file/d5d70f937087d354af856a12220354f5cb273b435f4a258e6e8d2289a32f7c3f/detection

Thanks Robert ... I'll tinker and share what I learn.

Re: Vega-Tek,  I tracked this down:

https://web.archive.org/web/20031202170854/http://www.vega-tek.com/index.html

Good find. A fine example of if you find something you like, save it to your backup stash. Everyday, stuff vanishes from the internet, never again to be seen.