(see comments in code ; ##### <----- xxxxx)
Code: Select all
;My Purebasic version 5.11.
EnableExplicit
Enumeration
#WIN_Main
#WIN_Text
#WIN_Button1
#WIN_Button2
EndEnumeration
;-Dialog hook to set font in MessageRequester.
Global Hook.i
Global IDYesText.s, IDNoText.s, IDCancelText.s
Global WinMainX.i, WinMainY.i, WinMainWidth.i, WinMainHeight.i, EventID.i
Global MessageTitle.s, MessageText.s
Global FontID_Body.l = LoadFont(0, "verdana", 8, #PB_Font_HighQuality | #PB_Font_Italic)
Global FontID_Button.l = LoadFont(1, "verdana", 8, #PB_Font_HighQuality | #PB_Font_Italic | #PB_Font_Bold)
Procedure ChangeTextFont(hwnd, lParam)
;Find messagebox text control and buttons.
Global 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 Body.
SendMessage_(hwnd, #WM_SETFONT, FontID_Body, 1)
UnhookWindowsHookEx_(Hook)
ProcedureReturn #False
EndIf
Case "BUTTON"
If GetWindowLong_(hwnd, #GWL_STYLE) & #SS_BITMAP = 0
;Change font Buttons.
SendMessage_(hwnd, #WM_SETFONT, FontID_Button, 1)
ProcedureReturn #True
EndIf
EndSelect
ProcedureReturn #True
EndProcedure
Procedure.l HookProc_HaWi(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 MessageRequester_HaWi(Title.s, Text.s, flags.l = #PB_MessageRequester_Ok, YesText.s = #NULL$, NoText.s = #NULL$, CancelText.s = #NULL$)
Protected.l MaxLength, Result.l
;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_HaWi(), #Null, GetCurrentThreadId_())
;Add more space for bigger font, NB: specific changes for Windows 10!!!.
MaxLength = Len(Text)
;Result = MessageRequester(Title, Text + Space(1.0 * Len(Text)) + #LF$ + #LF$ + " ", flags) ;For Big font changes for Windows 10!!!.
Result = MessageRequester(Title, Text + Space(1.0 * Len(Text)), flags)
ProcedureReturn Result
EndProcedure
Procedure RequesterCallBack(hWnd, uMsg, wParam, lParam)
Protected Cr.Rect, Cr_Main.Rect
Protected.i Width, Height, X, Y
hWnd = FindWindow_("#32770", #Null)
If hWnd
GetWindowRect_(hWnd, Cr.Rect)
GetWindowRect_(WindowID(#WIN_Main), Cr_Main.Rect) ; ##### <----- For every window, how to do it.
WinMainX = WindowX(#WIN_Main) ; ##### <----- ,,
WinMainY = WindowY(#WIN_Main) ; ##### <----- ,,
WinMainWidth = Cr_Main\Right - Cr_Main\Left
WinMainHeight = Cr_Main\Bottom - Cr_Main\Top
Width = Cr\Right - Cr\Left
Height = Cr\Bottom - Cr\Top
X = WinMainX + (WinMainWidth - Width) /2
Y = WinMainY + (WinMainHeight - Height) /2
SetWindowPos_(hWnd, 0, X, Y, 0, 0, #SWP_NOSIZE | #SWP_NOZORDER)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure Main()
OpenWindow(#WIN_Main,0, 0, 320, 140, "Main Window" + ".", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
SetWindowCallback(@RequesterCallBack())
TextGadget(#WIN_Text, 60, 40, 190,30, "Move the window and click on ME" + " " + "!!...", #PB_Text_Center)
ButtonGadget(#WIN_Button1, 80, 80, 150, 25, "- Click on ME -"): SetGadgetFont(#WIN_Button1, FontID_Button)
ButtonGadget(#WIN_Button2, 80, 110, 150, 22, "End"): SetGadgetFont(#WIN_Button2, FontID_Button)
EndProcedure
Main()
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case #WIN_Button1
MessageTitle = Space(2) + "Info" + "."
MessageText = #LF$ + "Information" + ":" + #LF$ + #LF$
MessageText + "The message is centered on the window" + "." + #LF$ + #LF$
Messagetext + "By clicking on the " + Chr(34) + "OK" + Chr(34) + " button this information window is closed" + "."
MessageRequester_HaWi(MessageTitle, MessageText, #MB_ICONEXCLAMATION | #PB_MessageRequester_YesNoCancel, "&Yes", "&No", "&Cancel")
Case #WIN_Button2
End
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
Little_Man