Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
End Enum
Global hDlg,ghHook,hFont As Dword
Global FontName As WStringZ * %Max_Path 'font name
Global FontSize, FontAttr As Long 'font size/attr and sort info
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Font", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
SelectMainFont
End Select
End Select
End Function
Sub SelectMainFont
Local fName As String, fPoints, fStyle, fColor, CharSet, Style As Long, temp$
Style = %CF_ForceFontExist Or %CF_NoScriptSel Or %CF_NoSimulations Or %CF_ScreenFonts 'Or %CF_FixedPitchOnly 'OR %CF_ScreenFonts Or
ghHook = SetWindowsHookEx(%WH_CBT, CodePtr(FontDialogProc), GetModuleHandle(""), GetCurrentThreadId)
Display Font hDlg, 100,100, FontName, FontSize, FontAttr, Style To fName, fPoints, fStyle, fColor, CharSet
UnhookWindowsHookEx ghHook
If Len(fName) Then
FontName = fName : FontSize = fPoints : FontAttr = fStyle
End If
End Sub
Function FontDialogProc(ByVal nCode As Long, ByVal WParam As Long, ByVal LParam As Long) As Long
Local szTemp As WStringZ * %Max_Path, cw As CBT_CREATEWND Ptr, cst As CREATESTRUCT Ptr, ghHook As Dword
Function = CallNextHookEx(ByVal ghHook, ByVal nCode, ByVal WParam, ByVal LParam)
If nCode < 0 Then Exit Function
If nCode = %HCBT_ACTIVATE Then UnhookWindowsHookEx ghHook
If nCode = %HCBT_CREATEWND Then
cw = LParam ' Get pointer to CBT_CREATEWND struct so we can... TT: Nick Melnick
cst = @cw.lpcs ' get a pointer to the CREATESTRUCT struct
GetClassName WParam, szTemp, %Max_Path ' for each window / control as it is created
If UCase$(szTemp) = "#32770" Then @cst.cy = @cst.cy - 165 : @cst.cx = @cst.cx - 10 ' -190 works too
End If
End Function
'gbs_01428
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm