Results 1 to 2 of 2

Thread: about CreateFont

  1. #1

    about CreateFont

    i was playing with CreateFont, trying different values for it to affect fonts in TextBox
    http://winapi.freetechsecrets.com/wi...CreateFont.htm
    some times we need to display other than English words so we should use a charset for that language look :
    https://www.powerbasic.com/help/pbcc..._statement.htm

    if we install Greek and then trying to type inside the text box we get gibberish characters if the CHARSET = 0, but if we change it to CHARSET = 161 then we can type Greek inside the TextBox

    gibberish.PNGgreek.PNG

    the next code display bold and big chars, it is very thick FW_BOLD = 700 , also it is very wide (stretched)
    the -18 (height) : if we write it as 18 the chars have some chaos.
    i think we can't affect specific words in the TextBox. for affecting specific words we need rich edit control. but i may be wrong regarding the TextBox.
    as you can see the CreateFont is complex but it is useful if we want to try more options for the fonts
      USES "UI"
    
      Begin ControlID
        %ID_TextBox1 
        %ID_TextBox2
        
      End ControlID
        
      function TBMain()  
        Dim hDlg, hFont   As Long
        
        Dialog New 0, "TextBox experiments", -1, -1, 500, 400, _
                                                      %WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU, _
                                                      0 TO hDlg
    
        Control Add Textbox , hDlg, %ID_TextBox1, "Text box: read only" , 5,  10, 185, 15, %WS_BORDER Or %WS_TABSTOP Or %ES_READONLY  , %WS_EX_CLIENTEDGE
    
    
        Control Add Textbox , hDlg, %ID_TextBox2, "Oki" , 5,  25, 450, 310, %WS_BORDER      Or _
                                                                         %WS_TABSTOP     OR _
                                                                         %ES_WANTRETURN  OR _
                                                                         %ES_MULTILINE   OR _
                                                                         %ES_AUTOHSCROLL OR _
                                                                         %ES_AUTOVSCROLL OR _
                                                                         %WS_VSCROLL     OR _
                                                                         %WS_HSCROLL
    Integer FW_BOLD, CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH
    FW_BOLD = 700: CHARSET = 0: OUT_DEFAULT_PRECIS =0:CLIP_DEFAULT_PRECIS =0:DEFAULT_QUALITY=0: DEFAULT_PITCH=0
    hfont = CreateFont(-18, 30, 0, 0, FW_BOLD, FALSE,_
            FALSE, FALSE, CHARSET, OUT_DEFAULT_PRECIS,_
            CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,"Arial")
                
    Control Set Color hDlg, %ID_TextBox2, Rgb(0,0,255), Rgb(200,255,200)    
                
    Control Send hDlg,%ID_TextBox2, %WM_SETFONT, hFont, 0     
        
    Control Append Text hDlg, %ID_TextBox2, $CRLF  & $CRLF & "to be or not to be" & $CRLF      
    
        '---Show dialog in MODAL
        DIALOG SHOW MODAL hDlg, call dlgCallback
      end function
      
      callback function dlgCallback() as long
      
        select case cbMsg
          case %WM_CLOSE
        end select  
      
      end function
    
    Last edited by primo; 16-12-2016 at 16:53.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Primo,

    thanks a lot for sharing! If I may - one hint: int in C/C++ is not the same as Integer in thinBasic!

    You should use Int32 or Long datatype (they are aliases, both 32bit, signed), instead of Integer, as Integer has very restricted range of values.

    There are 3 types of signed integers in thinBasic, please learn more at: http://www.thinbasic.com/public/prod...cvariables.htm

    Also - there is no need to initialize numeric variables to 0, it is done automatically. Again, unlike C++, which does initialize global numeric variables to 0 and local numeric variables keeps undefined unless assigned.

    So you could easily replace this:
    Integer FW_BOLD = 700, CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH
    FW_BOLD = 700: CHARSET = 0: OUT_DEFAULT_PRECIS =0:CLIP_DEFAULT_PRECIS =0:DEFAULT_QUALITY=0: DEFAULT_PITCH=0
    
    With this:
    dim FW_BOLD = 700, CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH as long
    

    Petr
    Last edited by Petr Schreiber; 16-12-2016 at 21:40.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. CreateFont or Font_create
    By Michael Clease in forum Fixed or cleared errors in help material
    Replies: 8
    Last Post: 31-01-2010, 18:36
  2. createfont and font_create
    By sandyrepope in forum UI (User Interface)
    Replies: 2
    Last Post: 28-01-2008, 16:05

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •