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

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • 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: 1899
    • 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

  • Full Member
  • ***
  • Posts: 105
    • 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: 1145
    • 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: 1145
    • 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: 1899
    • 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: 1145
    • 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: 1899
    • 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: 1899
    • 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: 1145
    • 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: 1145
    • 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.

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: Resize Reposition Labels ???
« Reply #11 on: January 05, 2023, 03:22:31 PM »
Hi MrBCX:

I noticed in your BEd editor that the dialogs all adjust very neatly to the Dialog Font size setting.

I have looked through the code and have not been able to find the point where the adjustment is made to the dialogs.

I see the CASE 5009 user input interface and have looked at the SetFonts SUB but do not see where the adjustment is made.

Is the adjustment in the BEd code or is it done in the SciLexer.dll ?

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1899
    • View Profile
Re: Resize Reposition Labels ???
« Reply #12 on: January 05, 2023, 04:00:43 PM »
Hi Robert,

I think I understand what you're asking.  Here's some info that might help.

First, the global variables g_FontFace$ and g_FontSize largely control the appearance of the dialogs.
That means it's a Windows thing, not a Scintilla thing.

You might recognize this, for example,  inside Event_Loop.inc

'**************************
   CASE IDM_EDITOROPT, IDT_CONFIG
 '**************************
 BCX_MDIALOG (Configure, "Settings", Form1, 0, 0, 370, 260, 0, 0, g_FontFace$, g_FontSize)


Let that soak in and if you still have question, gimme a jingle.

PS ... be careful not to confuse g_FontFace$ with g_EditFontFace$ or g_FontSize with g_EditFontSize
        The latter two -do- control the Scintilla Editor font.

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: Resize Reposition Labels ???
« Reply #13 on: January 05, 2023, 07:45:30 PM »
Hi Robert,

I think I understand what you're asking.  Here's some info that might help.

First, the global variables g_FontFace$ and g_FontSize largely control the appearance of the dialogs.
That means it's a Windows thing, not a Scintilla thing.

You might recognize this, for example,  inside Event_Loop.inc

'**************************
   CASE IDM_EDITOROPT, IDT_CONFIG
 '**************************
 BCX_MDIALOG (Configure, "Settings", Form1, 0, 0, 370, 260, 0, 0, g_FontFace$, g_FontSize)


Let that soak in and if you still have question, gimme a jingle.

PS ... be careful not to confuse g_FontFace$ with g_EditFontFace$ or g_FontSize with g_EditFontSize
        The latter two -do- control the Scintilla Editor font.

Very good. Just what I needed to know.

Reading the BCX_MDIALOG Documentation carefully, I found that it states

Quote
Note that if the optional FontFace parameter is used then the DS_SETFONT style is added automatically as an argument to the WinStyle% parameter.

MS docs say about DS_SETFONT

Quote
The system passes a handle to the font to the dialog box and to each control by sending them the WM_SETFONT message.

So that's the mechanics of it, something I did not know.

Thanks for the help.