PDA

View Full Version : How to set a font on a control



Michael Clease
28-02-2013, 00:03
Here is a rough example of how to set a font for a windows control in this case a label, the equates are a mystery.



Uses "UI"


' -- ID numbers of controls
Begin ControlID
%bClose
End ControlID


Begin Const
%MAIN_WIDTH = 320
%MAIN_HEIGHT = 240
End Const
'---Controls IDs---
Begin ControlID
%first = 1000
%IDC_STATICLABEL_1
%IDC_STATICLABEL_2
End ControlID


' -- Create dialog here
Function TBMain()
Local sText As String
Local hDlg As Long
Local hFont1 As Long
Local hFont2 As Long
Local lStyle As Long
Local lStyleEx As Long
lStyle = _
%WS_DLGFRAME | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN | _
%WS_CLIPSIBLINGS | _
%DS_CENTER
lStyleEx = 0


Dialog New Pixels, 0, "Form1", -1, -1, 690, 431, lStyle, lStyleEx, To hDlg

' -- Place controls here
Control Add Button, hDlg, %bClose, "Click to close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25, Call cbCloseButton


Control Add Label, hDlg, %IDC_STATICLABEL_1, "FMP firmware tool", 32, 20, 632, 50, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %SS_CENTER, %WS_EX_CLIENTEDGE
Control Set Resize hDlg, %IDC_STATICLABEL_1, 1, 1, 1, 0


Control Add Label, hDlg, %IDC_STATICLABEL_2, "FMP firmware tool", 32, 100, 632, 50, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %SS_CENTER, %WS_EX_CLIENTEDGE
Control Set Resize hDlg, %IDC_STATICLABEL_2, 1, 1, 1, 0


hFont1 = Font_Create("MS Sans Serif", 24,%FONT_BOLD) ' ******************************
hFont2 = Font_Create("MS Sans Serif", 8,0) ' ******************************
Dialog Send (Win_GetDlgItem(hDlg, %IDC_STATICLABEL_1)), %WM_SETFONT, hFont1, 0 ' ******************************
Dialog Send (Win_GetDlgItem(hDlg, %IDC_STATICLABEL_2)), %WM_SETFONT, hFont2, 0 ' ******************************



Dialog Show Modal hDlg, Call cbDialog

Object_Delete(hFont1) ' ******************************
Object_Delete(hFont2) ' ******************************




End Function


' -- Callback for dialog
CallBack Function cbDialog()


End Function

' -- Callback for close button
CallBack Function cbCloseButton()


If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If


End Function