It is currently Thu Jul 18, 2019 8:32 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Requester's font
PostPosted: Fri Dec 07, 2018 2:56 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Jan 30, 2007 5:47 am
Posts: 329
Location: Hong Kong
Does anybody know how to change the font of the requesters, such as MessageRequester, FontRequester, etc?


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Fri Dec 07, 2018 3:29 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 11:08 pm
Posts: 438
Here's my solution for MessageRequesters (Windows only), cobbled together from various tips found here.
It's not elegant, but it works! :D

The code Text + Space(1.0 * Len(Text)) + #LF$ + #LF$ + " " is my attempt to allow more space for the bigger font.
It requires some trial and error to make sure the text fits, especially because it varies depending on the font you use, as well as the Windows version.
If anyone knows how to have Windows automatically adjust the MessageRequester size based on the font, I would love to know.

Code:
;- dialog hook to set font in MessageRequester
Global Hook.L
Global IDYesText.S, IDNoText.S, IDCancelText.S

Global FontID_12Regular.L, FontID_12Bold.L

Procedure ChangeTextFont(hwnd, lParam)
  ; find messagebox text control and buttons
  CN.S = Space(#MAX_PATH)
  GetClassName_(hwnd, @CN, #MAX_PATH)
  Select UCase(CN)
    Case "STATIC"
      If GetWindowLong_(hwnd, #GWL_STYLE) & #SS_BITMAP = 0
        ; change font
        SendMessage_(hwnd, #WM_SETFONT, FontID_12Regular, 1)
        UnhookWindowsHookEx_(Hook)
        ProcedureReturn #False
      EndIf
    Case "BUTTON"
      If GetWindowLong_(hwnd, #GWL_STYLE) & #SS_BITMAP = 0
        ; change font
        SendMessage_(hwnd, #WM_SETFONT, FontID_12Bold, 1)
        ProcedureReturn #True
      EndIf
  EndSelect
 
  ProcedureReturn #True
EndProcedure

Procedure.L HookProc(nCode, wParam, lParam)
  If nCode = #HCBT_ACTIVATE
    ; find text control and change font
    EnumChildWindows_(wParam, @ChangeTextFont(), 0)
    ; change button(s) text
    If IDYesText
      SetDlgItemText_ (wParam, #IDYES, IDYesText)
      SetDlgItemText_ (wParam, #IDNO, IDNoText)
      SetDlgItemText_ (wParam, #IDCANCEL, IDCancelText)
    EndIf
    UnhookWindowsHookEx_ (Hook)
  EndIf
 
  ;ProcedureReturn CallNextHookEx_(Hook, nCode, wParam, lParam)
EndProcedure

;- message requester with customized font/button captions
Procedure.L MessageRequesterEBS(Title.S, Text.S, flags.L = #PB_MessageRequester_Ok, YesText.S = #Null$, NoText.S = #Null$, CancelText.S = #Null$)
  ; set button(s) text
  ; NB: "Yes" text controls all buttons:
  ; if set, ALL buttons are changed
  ; if empty, NO buttons are changed
  IDYesText = YesText
  IDNoText = NoText
  IDCancelText = CancelText
 
  Hook = SetWindowsHookEx_(#WH_CBT, @HookProc(), #Null, GetCurrentThreadId_())
 
  ; add more space for bigger font
  ; NB: specific changes for Windows 10!!!
  MaxLength.L = Len(Text)
  result.L = MessageRequester(Title, Text + Space(1.0 * Len(Text)) + #LF$ + #LF$ + " ", flags)
 
  ProcedureReturn result
EndProcedure

FontID_12Regular = LoadFont(0, "Tahoma", 12, #PB_Font_HighQuality)
FontID_12Bold = LoadFont(1, "Tahoma", 12, #PB_Font_Bold|#PB_Font_HighQuality)

MessageRequesterEBS("Change Font in Message Requester", "This is a bigger font (12 pt)" + #LF$ + "in a Message Requester", #MB_ICONINFORMATION|#PB_MessageRequester_YesNoCancel, "One", "Two", "Three")


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Fri Dec 07, 2018 7:10 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 415
It seems a second internal effect can disturb gurj :

Code:
Eax.L = $80000000
Define Rax.Q
Rax = Eax
Here, it seems that the higher 32 bits are set to the same status of Bit #31, what it seems to disturb some tests...

$FFFFFFFF80000000

"Normally" we could expect to this value :

$0000000080000000.

But the hardware is producing differently.


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Fri Dec 07, 2018 8:51 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1033
Location: Germany::Berlin()
@ebs
Nice code!

_________________
ImageImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Sat Dec 08, 2018 8:57 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2967
Location: Boston, MA
You need more code to change the MessageBox window contents. It is not cross platform and easier to create your own PB sticky window for such effects.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Sat Dec 08, 2018 10:19 pm 
Offline
User
User

Joined: Fri Mar 29, 2013 4:55 pm
Posts: 90
Location: Netherland
How to "center" the above code on a existing window ?.

Kind regards,

Little-man


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Tue Dec 11, 2018 6:38 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4462
Location: Not Sydney!!! (Bad water, no goats)
EBS, this is useful stuff. I am running my widescreen in 2560x1080 at 125% upscaling and requesters were still tiny so your code is very, very useful.

Just had to change "hook" to "chookie" and another third party code was using it already.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Tue Dec 11, 2018 3:55 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 11:08 pm
Posts: 438
fangbeast,

Thanks!

A minor improvement to make the buttons slightly larger, so the text fits better.
Just add this line to the ChangeTextFont procedure, under the "Button" case:
Code:
        ; adjust size
        SetWindowPos_(hwnd, 0, 0, 0, 70, 25, #SWP_NOMOVE|#SWP_NOZORDER)


Top
 Profile  
Reply with quote  
 Post subject: Re: Requester's font
PostPosted: Tue Dec 11, 2018 8:40 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4462
Location: Not Sydney!!! (Bad water, no goats)
ebs wrote:
fangbeast,

Thanks!

A minor improvement to make the buttons slightly larger, so the text fits better.
Just add this line to the ChangeTextFont procedure, under the "Button" case:
Code:
        ; adjust size
        SetWindowPos_(hwnd, 0, 0, 0, 70, 25, #SWP_NOMOVE|#SWP_NOZORDER)


Will do that today. I used a few requesters in my Keeper code and will 'massage' them today:):)

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye