Page 1 of 1

Bold in MessageRequester (messagebox_()) ?

Posted: Wed Jun 03, 2009 5:01 pm
by NoahPhense
Anyone have code for this? I know it's possible, as nothing is impossible
in PB land.. ;)

- np

Posted: Wed Jun 03, 2009 9:44 pm
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)

Posted: Wed Jun 03, 2009 10:41 pm
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)