Bold in MessageRequester (messagebox_()) ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Bold in MessageRequester (messagebox_()) ?

Post by NoahPhense »

Anyone have code for this? I know it's possible, as nothing is impossible
in PB land.. ;)

- np
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

The following is a simple solution as it makes no attempt to resize the dialog box or the static control to accept the larger text. All I did was add some spaces to the message text to trick the OS into creating them larger:

Code: Select all

Global Hook

Procedure FindText(hwnd, lParam)
  
  cn$ = Space(#MAX_PATH)
  GetClassName_(hwnd, @cn$, #MAX_PATH)
  If UCase(cn$) = "STATIC"
    If GetWindowLong_(hwnd, #GWL_STYLE) & #SS_BITMAP = 0
      SendMessage_(hwnd, #WM_SETFONT, LoadFont(0, "Tahoma", 10, #PB_Font_Bold), 1)
      ProcedureReturn 0
    EndIf
  EndIf
 
  ProcedureReturn 1
EndProcedure


Procedure HookProc(nCode, wParam, lParam) 

  Static hWnd_MessageBox
  
  Select nCode 
  
    Case #HCBT_CREATEWND 
      *pcbt.CBT_CREATEWND = lParam 
      *pcs.CREATESTRUCT = *pcbt\lpcs 
      
      Select *pcs\lpszClass 
      
        Case 32770
          hWnd_MessageBox = wParam
         
      EndSelect
    
    Case #HCBT_ACTIVATE 
      EnumChildWindows_(hWnd_MessageBox, @FindText(), 0)
      
  EndSelect
   
  ProcedureReturn CallNextHookEx_(Hook, nCode, wParam, lParam) 
   
EndProcedure
          

Hook = SetWindowsHookEx_(#WH_CBT, @HookProc(), #Null, GetCurrentThreadId_()) 
result = MessageRequester("Hello", "This is bold text       ", #MB_ICONINFORMATION) 
UnhookWindowsHookEx_(Hook)
Last edited by netmaestro on Thu Jun 04, 2009 1:20 am, edited 1 time in total.
BERESHEIT
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

A bit shorter but less safer :wink:

Code: Select all

Procedure SetBoldMsgBox(*Title)
Repeat
  hwnd = FindWindowEx_(FindWindow_(0, *Title), 0, @"Static", 0)
Until hwnd<>0
SendMessage_(hwnd, #WM_SETFONT, LoadFont(0, "Microsoft Sans Serif", 8, #PB_Font_Bold), 1)
EndProcedure

Title.s = "Bold Text example"
Text.s = "Sample text"

CreateThread(@SetBoldMsgBox(), @Title)
MessageRequester(Title, Text)
Ceterum censeo Carthaginem esse delendam!
Post Reply