Announcement

Collapse
No announcement yet.

Changing Font style in PBDLL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Changing Font style in PBDLL

    I am presently quite proud of myself, having written my first ever Windows programme.

    The font is the default font of PBDLL60, MS Sans, I think.

    I have a Listbox in which I wish to use Courier or another fixed width font so that certain data lines up in columns.

    Can anyone offer advice on changing the font for the text in the listbox?

    Regards,
    Brian.

    Brian.

    #2
    Create a font (search for MAKEFONT in the forums and you should find some example subroutines), and then send a %WM_SETFONT message to the control in question. This can be done in the %WM_INITDIALOG message handler in your dialog callback.

    Don't forget to hold the font handle in a STATIC variable in your dialog callback, and use DeleteObject() in response to the %WM_DESTROY message (this ensures that the font is destroyed and you don't cause a memory leak while your app is running).

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


      #3
      Brian --
      Simple sample
      Code:
      #Compile Exe
      #Dim All
      #Register None
      #Include "win32api.inc"
      
      Function PbMain
          Local hDlg As Long
          Dialog New 0, "Test", 0, 0, 150, 60, %WS_SYSMENU To hDlg
          Dim a(1 : 2) As String
          a$(1) = "Item 1": a$(2) = "Item 2"
          Local lf As LOGFONT
          Local hFont As Long, lResult As Long
          GetObject GetStockObject(%ANSI_VAR_FONT), SizeOf(lf), ByVal VarPtr(lf)
          lf.lfHeight = -14
          lf.lfWeight = %FW_BOLD
          lf.lfFaceName = "Arial"
          hFont = CreateFontIndirect(lf)
          Control Add ListBox, hDlg, 101, a$(), 10, 10, 50, 40
          Control Add ComboBox, hDlg, 102, a$(), 70, 10, 60, 40, %CBS_DROPDOWNLIST Or %WS_TABSTOP
          Control Send hDlg, 101, %WM_SETFONT, hFont, 0
          Control Send hDlg, 102, %WM_SETFONT, hFont, 0
          Dialog Show Modal hDlg
          Deleteobject hFont
      End Function
      ------------------

      Comment


        #4
        Thank you Lance and Semen.

        ------------------
        Ron

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎