Announcement

Collapse
No announcement yet.

hFont in Static, Button

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

  • Semen Matusovski
    replied
    Borje --
    Guess that you about a code in first message.
    I don't see that DEFAULT_GUI_FONT doesn't work under NT and here it's not important
    Code:
    For i = 1 To 3
       PostMessage GetDlgItem(CbHndl, 100 + i), %WM_SETFONT, hFont1, 1
    Next
    It's possible to expect the same font in CbCtl = 101 ... 103 and this is so for 9x/NT
    Under 2000 I see correct font in Textbox only.
    In button and label - bold font, the same size, but another charset.

    What this means ?
    TextOut, DrawText, as I mentioned, works with charsets correctly also.

    So, in my understanding, buttons/static ... do not use hFont in WM_SETFONT directly. They create a new font.

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Borje Hagsten
    replied
    Hm, in your code, you use %DEFAULT_GUI_FONT with StockObject. MS says
    use DEVICE_DEFAULT_FONT with NT, for "Device-dependent font", whatever
    that means. They also say %DEFAULT_GUI_FONT is for Win95 only..

    Maybe those two return different values in Win2K/XP?
    ------------------
    Easy to test with WM_GETFONT on dialog and see if returned values are the same..


    [This message has been edited by Borje Hagsten (edited September 26, 2001).]

    Leave a comment:


  • Semen Matusovski
    replied
    Lance -
    An app is russian, not international.
    I have no reasons to translate it to Lithuanian, Estonian and so on languages, because -
    1) At first, it's real-time app and, even if to have a wish and money, there is no time.
    2) Foreighn companies work on russian market. So they have employers, which understand Russian language enough good.

    Alone, what I need - the same text, not depends of regional settings on certain PC.
    Well, there are captions, menu, Messagebox, where is impossible to set a font by design.
    So, no choice - ownerdrawn.

    But such controls as Static/Button understand WM_SETFONT and there is no problem under 9x and NT.
    If I created a font with lf.lfCharset = %Russian_Charset, these controls works with my hFont.
    Under 2000/XP happends something terrible and I have no idea how to bypass this problem.
    Meanwhile TextOut/DrawText work correctly.




    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    Internationalization issues can be problematic. Generally you would need to detect Baltic region settings and change the label text acordingly.

    This is one of the key uses for string tables in a DLL... you load all button/label text from specific string table entries. All you need to do is change the string table in the resource file for the region the app is being shipped to.

    Or use a resource DLL, and just ship the appropriate language DLL with the app.

    BTW, can you speak %BALTIC_CHARSET? You do speak %ANSI_CHARSET pretty well!

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

    Leave a comment:


  • Semen Matusovski
    replied
    Lance --
    If you mean that in this sample a big font can lead to overlapping some areas - yes, it's so, because "plabel" doesn't control this (similar BS_GROUPBOX).
    In real app overlapping is impossible, because I locate and size child windows according program selected font (not by user ).
    Or I lost something ?

    A problem, with which I struggle, is following.
    In Win2000, XP such controls as Static, Button, SysTab ... (fortunatelly, except Edit) do not use a handle, which you send in WM_SETFONT.
    They re-create a font with the same lf.lfWidth, lf.lfHeight, lf.lfFacename and so on, but change lf.lfCharset to codeset, which is default for certain PC.

    What this means ... For example, a customer lives in Lithuania.
    Of course, Russian language is more clear for him than English, but no reasons to expect Russian regional settings.
    Typically ise used local Baltic release, sometimes - English (USA).

    In program I create, let's say, Times New Roman/%RUSSIAN_CHARSET and set this font for a button with russian text.
    All works fine on my PC, because I have russian regional settings.
    On customer's PC will be abrakadabra, because "Button" will use Times New Roman/%BALTIC_CHARSET.
    Maybe for some European languages it's not a serious problem - most letters are located in first part (0-127).
    But all russian letters are located in second part (128-255).

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    Make the font size large, then make it much smaller... oops!

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

    Leave a comment:


  • Semen Matusovski
    replied
    Coming back ... I had a possibility to test under Windows XP. The same situation.
    In additional I found that actually affected all popular classes, incl. Tab-Control.

    Some monthes ago I wrote a "small" utility for "unknown" PC settings and used ownerdrawn controls only.
    Just now I write a big app and, unlike previous situation, here I use de-facto all standart classes.
    Like it's possible to imagine, there is a wish to bypass somehow this problem by more easy way.

    Maybe somebody saw Microsoft suggestions ?

    BTW, yesterday re-built a frame, which wrote last time.
    Of course, because this is custom control, I added some new features comparing with BS_GROUPBOX (DDT Frame).
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       #Include "comdlg32.Inc"
       
       %ExStyle = 0 ' %WS_EX_CLIENTEDGE
       
       '========================================================================== For Inc =========================
       
    
       '*****************************
       '*      pLabel               *
       '*****************************
    
       Function Register_pLabel As Long
         Local wc          As WNDCLASS
         Local szClassName As Asciiz * 7
         szClassName      = "pLabel"
         wc.lpfnWndProc   = CodePtr(pLabelProc)
         wc.hInstance     = GetModuleHandle(ByVal 0&)
         wc.hCursor       = LoadCursor(ByVal 0&, ByVal %IDC_ARROW)
         wc.hBrBackGround = GetStockObject(%NULL_BRUSH)
         wc.lpszClassName = VarPtr(szClassName)
         wc.cbWndExtra    = 16
         Function = RegisterClass(wc)
       End Function
    
       %PL_Frame = 1
       
       %PL_SETTEXTCOLOR   = %WM_USER + 4001 ' wParam = RGB or (&H01000000& + %COLOR_xxx)   lParam = redraw option (0/1)
       %PL_SETBKGBRUSH    = %WM_USER + 4002 ' wParam = hBrush or (%COLOR_xxx + 1)          lParam = redraw option (0/1)
       %PL_SETBORDERTYPE  = %WM_USER + 4003 ' wParam = 0 - Sunken 1 - Raised               lParam = redraw option (0/1)
       %PL_SETALIGNMENT   = %WM_USER + 4004 ' wParam = %SS_LEFT / %SS_CENTER / %SS_RIGHT   lParam = redraw option (0/1)
           
       %PL_REDRAW         = %WM_USER + 4005
    
       Function pLabelEnumChildWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
    
          ReDim InfoForEnum(6) As Local Long At lParam
          Local rc1 As RECT, rc2 As RECT
          
          If hWnd <> InfoForEnum(0) Then
             GetWindowRect hWnd, rc1
             GetWindowRect InfoForEnum(0), rc2
    
             If rc1.nLeft  > rc2.nLeft And _
                rc1.nTop   > rc2.nTop  And _
                rc1.nRight < rc2.nRight And _
                rc1.nBottom < rc2.nBottom Then _
                BitBlt InfoForEnum(2), rc1.nLeft  - rc2.nLeft, rc1.nTop   - rc2.nTop, _
                   rc1.nRight - rc1.nLeft, rc1.nBottom - rc1.nTop, _
                   InfoForEnum(1), rc1.nLeft - rc2.nLeft, rc1.nTop - rc2.nTop, %SRCCOPY
          End If
          Function = 1
       End Function
    
       Function pLabelProc (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
          Local ForegroundColor As Dword, BackgroundBrush As Dword
          Local BorderType As Long, Alignment As Long, DrawAsFrame As Long
          Local Caption As Asciiz * 255, CaptionSize As SIZEL, CaptionOffset As SIZEL
          Local hDC As Long, rcWnd As RECT, rcFrm As RECT, rcTmp As RECT
          Local hMemDC As Long, hMemBmp As Long
          Dim InfoForEnum(2) As Local Long
          
          Select Case wMsg
             Case %WM_CREATE
                
             Case %PL_SETTEXTCOLOR
                SetWindowLong hWnd, 0, wParam
                If lParam Then PostMessage hWnd, %PL_REDRAW, 0, 0
    
             Case %PL_SETBKGBRUSH
                SetWindowLong hWnd, 4, wParam
                If lParam Then PostMessage hWnd, %PL_REDRAW, 0, 0
    
             Case %PL_SETBORDERTYPE
                SetWindowWord hWnd, 8, wParam
                If lParam Then PostMessage hWnd, %PL_REDRAW, 0, 0
    
             Case %PL_SETALIGNMENT
                SetWindowWord hWnd, 10, wParam
                If lParam Then PostMessage hWnd, %PL_REDRAW, 0, 0
    
             Case %WM_SETFONT
                SetWindowLong hWnd, 12, wParam
                If lParam Then PostMessage hWnd, %PL_REDRAW, 0, 0
    
             Case %WM_SETTEXT, %WM_PAINT
                PostMessage hWnd, %PL_REDRAW, 0, 0
               
             Case %WM_NCHITTEST
                Function = %HTTRANSPARENT: Exit Function
                
             Case %PL_REDRAW
                ForegroundColor = GetWindowLong (hWnd, 0)
                If ForegroundColor = 0 Then ForegroundColor = &H1000000& + %COLOR_BTNTEXT
                If ForegroundColor > &HFFFFFF& Then ForegroundColor = GetSysColor(ForegroundColor And &HFFFFFF)
       
                BackgroundBrush = GetWindowLong (hWnd, 4)
                If BackgroundBrush = 0 Then BackgroundBrush = %COLOR_BTNFACE + 1
                If BackgroundBrush <= 64 Then BackGroundBrush = GetSysColorBrush(BackgroundBrush - 1)
                
                DrawAsFrame = IsTrue((GetWindowLong(hWnd, %GWL_STYLE) And %PL_Frame) = %PL_Frame)
                
                BorderType = GetWindowLong (hWnd, 8)
                Alignment = HiWrd(BorderType)
                If LoWrd(BorderType) = 0 Then BorderType = %EDGE_ETCHED Else BorderType = %EDGE_BUMP
                If (Alignment <> %SS_RIGHT) And (Alignment <> %SS_CENTER) Then Alignment = %SS_LEFT
                            
                GetWindowText hWnd, Caption, SizeOf(Caption)
                GetClientRect hWnd, rcWnd
                  
                hDC = GetDC (hWnd)
                hMemDC  = CreateCompatibleDC(hDC)
                hMemBmp = CreateCompatibleBitmap(hdc, rcWnd.nRight, rcWnd.nBottom)
                SelectObject hMemDC, hMemBmp
    
                FillRect hMemDC, rcWnd, BackgroundBrush
                SetBkMode hMemDC, %TRANSPARENT
                SelectObject hMemDC, GetWindowLong(hWnd, 12) ' font
                SetTextColor hMemDC, ForegroundColor
                GetTextExtentPoint32 hMemDC, Caption, Len(Caption), CaptionSize
                rcFrm = rcWnd
    
                If DrawAsFrame Then
                   If Caption = "" Then GetTextExtentPoint32 hMemDC, " ", 1, CaptionSize
                   InflateRect rcFrm, - CaptionSize.cy / 2, - CaptionSize.cy / 2
                   DrawEdge hMemdc, rcFrm, BorderType, %BF_RECT
                   Select Case Alignment
                      Case %SS_CENTER: CaptionOffset.cx = Max(0, (rcFrm.nRight - rcFrm.nLeft - CaptionSize.cx) \ 2)
                      Case %SS_LEFT  :  CaptionOffset.cx = Min(CaptionSize.cy, rcFrm.nRight - rcFrm.nLeft - CaptionSize.cx)
                      Case %SS_RIGHT : CaptionOffset.cx = Max(0, (rcFrm.nRight - rcFrm.nLeft - CaptionSize.cy) - CaptionSize.cx)
                   End Select
                   CaptionOffset.cy = 0
                   
                   If Caption <> "" Then
                      rcTmp.nLeft = CaptionOffset.cx
                      rcTmp.nTop = CaptionOffset.cy
                      rcTmp.nRight = CaptionOffset.cx + CaptionSize.cx
                      rcTmp.nBottom = CaptionOffset.cy + CaptionSize.cy
                      FillRect hMemDC, rcTmp, BackgroundBrush
                   End If
                   
                   InfoForEnum(0) = hWnd: InfoForEnum(1) = hDC: InfoForEnum(2) = hMemDC
                   EnumChildWindows GetParent(hWnd), CodePtr(pLabelEnumChildWindowsProc), VarPtr(InfoForEnum(0))
                   
                Else
                   Select Case Alignment
                      Case %SS_CENTER: CaptionOffset.cx = Max(0, (rcWnd.nRight - CaptionSize.cx) \ 2)
                      Case %SS_LEFT:   CaptionOffset.cx = 0
                      Case %SS_RIGHT:  CaptionOffset.cx = Max(0, rcWnd.nRight - CaptionSize.cx)
                   End Select
                   
                   CaptionOffset.cy = Max(0, (rcWnd.nBottom - CaptionSize.cy) \ 2)
                End If
                If Caption <> "" Then TextOut hMemDC, CaptionOffset.cx, CaptionOffset.cy, Caption, Len(Caption)
    
                BitBlt hDC, 0, 0, rcWnd.nRight, rcWnd.nBottom, hMemDC, 0, 0, %SRCCOPY
                ReleaseDC hWnd, hDC
                DeleteDC hMemDC
                DeleteObject hMemBmp
    
                Exit Function
          End Select
    
          Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       '==============================================================================================================
    
       CallBack Function DlgProc
          Static hEdit As Long
          Select Case CbMsg
             Case %WM_INITDIALOG
                Control Add "pLabel",  CbHndl,  101, " My frame ", _
                   10, 10, 380, 85, %WS_CHILD Or %WS_VISIBLE Or %PL_Frame, %ExStyle
                Control Add TextBox, CbHndl, 102, " ÀÁÂÃÄ àáâãä ABCDEF abcdef ", 20, 30, 120, 15, _
                   %WS_CHILD Or %WS_VISIBLE Or %DS_CONTROL Or %WS_TABSTOP, %WS_EX_CLIENTEDGE
                Control Add Button, CbHndl, 103,  "Change caption",             150, 30, 110, 15
                Control Add Button, CbHndl, 104,  "Choose font and text color", 150, 48, 110, 15
                Control Add Button, CbHndl, 105,  "Choose background color",    270, 30, 110, 15
                Control Add Button, CbHndl, 106,  "Change border",              270, 48, 110, 15
                Control Add Button, CbHndl, 107,  "Align left",                 150, 66, 70, 15
                Control Add Button, CbHndl, 108,  "Align center",               230, 66, 70, 15
                Control Add Button, CbHndl, 109,  "Align right",                310, 66, 70, 15
                
                Control Add Frame,  CbHndl,  201, " Classic frame ", 10, 110, 380, 50
    
             Case %WM_COMMAND
                If CbCtl = 103 Then
                   Local Txt As String
                   Control Get Text CbHndl, 102 To Txt
                   Control Set Text CbHndl, 101, Txt
                   Control Set Text CbHndl, 201, Txt
    
                ElseIf CbCtl = 104 Then
                   Local cf As CHOOSEFONTAPI
                   Static lf As LOGFONT
    
                   Static hFontNew As Long, hFontOld As Long
                   
                   cf.lStructSize = Len(CHOOSEFONTAPI)
                   cf.hwndOwner   = CbHndl
                   cf.lpLogFont = VarPtr(lf)
                   cf.Flags = %CF_SCREENFONTS  Or %CF_TTONLY Or %CF_EFFECTS Or %CF_INITTOLOGFONTSTRUCT
                   cf.nFontType = %SCREEN_FONTTYPE
                   
                   If ChooseFont (cf) Then
                      hFontNew = CreateFontIndirect (lf)
                      Control Send CbHndl, 101, %PL_SETTEXTCOLOR, cf.rgbColors, 0
                      Control Send CbHndl, 101, %WM_SETFONT, hFontNew, 1
                      Control Send CbHndl, 201, %WM_SETFONT, hFontNew, 1
                      
                      If hFontOld Then DeleteObject hFontOld
                      hFontOld = hFontNew
                   End If
                 
                ElseIf CbCtl = 105 Then
                   Local cc As CHOOSECOLORAPI
                   Static hBrushNew As Long, hBrushOld As Long
                   Dim lCustomColor(15) As Static Long
                   
                   cc.lStructSize  = Len(CHOOSECOLORAPI)
                   cc.hwndOwner    = CbHndl
                   cc.lpCustColors = VarPtr(lCustomColor(0))
      
                   If ChooseColor(cc) Then
                      hBrushNew = CreateSolidBrush (cc.rgbResult)
                      Control Send CbHndl, 101, %PL_SETBKGBRUSH, hBrushNew, 1
                      If hBrushOld Then DeleteObject hBrushOld
                      hBrushOld = hBrushNew
                   End If
                   
                ElseIf CbCtl = 106 Then
                   Static BorderType As Long
                   BorderType = 1 - BorderType
                   Control Send CbHndl, 101, %PL_SETBORDERTYPE, BorderType, 1
                   
                ElseIf CbCtl = 107 Then
                   Control Send CbHndl, 101, %PL_SETALIGNMENT, %SS_LEFT, 1
       
                ElseIf CbCtl = 108 Then
                   Control Send CbHndl, 101, %PL_SETALIGNMENT, %SS_CENTER, 1
    
                ElseIf CbCtl = 109 Then
                   Control Send CbHndl, 101, %PL_SETALIGNMENT, %SS_RIGHT, 1
    
               End If
            Case %WM_DESTROY
               If hFontOld Then DeleteObject hFontOld
               If hBrushOld Then DeleteObject hBrushOld
          End Select
       End Function
    
    
       Function PbMain As Long
          If Register_pLabel = 0 Then Exit Function
    
          Local hDlg As Long
          Dialog New 0, "Test for pLabel",,, 400, 180, %WS_CAPTION Or %WS_OVERLAPPEDWINDOW To hDlg
          Dialog Show Modal hDlg Call DlgProc
       End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Semen Matusovski
    replied
    Borje --
    About 98 - good question. Here all works as expected.

    %DS_SETFONT and similar. First time, when I found this "feature", I used API directly to create Dialogs.
    But always "...A" functions, not "...W".

    It looks that this problem somehow linked with Unicode (which is native in Win2000).
    Probably, using Unicode functions fixes this problem, but it's not interesting.


    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Borje Hagsten
    replied
    Interesting. Is it Win2000 specific? Some other crazy ideas:

    Create the DDT dialog with %DS_SETFONT OR %WS_SYSMENU style?

    Send WM_SETFONT with lParam set to zero and invalidate/update the
    control manually?

    Send WM_SETFONT in PBMAIN instead?

    Send WM_SETFONT to hDlg before sending it to the controls? Could
    work if the dialog somehow controls the controls, so to speak..


    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Borje --
    Something wrong in DefWindowProc as it is.
    For owner-drawn all is correct.

    Code:
    #Compile Exe
    #Register None
    #Include "Win32Api.Inc"
    %ID_Button1 = 101
    %ID_Button2 = 102
    %ID_Button3 = 103
    CallBack Function hDlg_CB
       Dim hBrush1 As Static Long, hBrush2 As Static Long
       Dim cxb As Static Long, cyb As Static Long, cxi As Static Long, cyi As Static Long
       Local tDrawItem As DRAWITEMSTRUCT Ptr, Icon As Long, ry As Long, tRect As Rect
       Select Case CbMsg
          Case %WM_INITDIALOG
             Dim i As Long, lf As Logfont, hFont1 As Static Long, hFont2 As Static Long
             Dim Text As Static String
             Text = Chr$(209, 229, 236, 229, 237)
             
             Control Add Button, CbHndl, %ID_Button1, "", 10, 5, 80, 16, %WS_TABSTOP Or %BS_OWNERDRAW
             Control Add Button, CbHndl, %ID_Button2, "", 10, 25, 80, 16, %WS_TABSTOP Or %BS_OWNERDRAW
             Control Add Button, CbHndl, %ID_Button3, Text, 10, 50, 80, 14
             
             i = GetStockObject(%DEFAULT_GUI_FONT)
             GetObject i, SizeOf(lf), ByVal VarPtr(lf)
             lf.lfCharset = %TURKISH_CHARSET
             lf.lfFaceName = "Times New Roman"
             lf.lfWeight = %FW_BOLD
             hFont1 = CreateFontIndirect(lf)
             For i = 1 To 3
                PostMessage GetDlgItem(CbHndl, 100 + i), %WM_SETFONT, hFont1, 1
             Next
             
             
          
             Local Lb As LOGBRUSH
             Lb.lbStyle = %BS_SOLID
             Lb.lbColor = %Blue: hBrush1 = CreateBrushIndirect(Lb)
             Lb.lbColor = %Yellow: hBrush2 = CreateBrushIndirect(Lb)
             cxb = GetSystemMetrics(%SM_CXBORDER): cyb = GetSystemMetrics(%SM_CYBORDER)
             cxi = GetSystemMetrics(%SM_CXSMICON): cyi = GetSystemMetrics(%SM_CYSMICON)
          Case %WM_DESTROY
             DeleteObject hBrush1: DeleteObject hBrush2
          Case %WM_DRAWITEM
             tDrawItem = CbLparam
             Select Case @tDrawItem.CtlID
                Case %ID_Button1, %ID_Button2
                   Icon = LoadIcon(0, ByVal %IDI_ASTERISK)
                   tRect = @tDrawItem.RcItem: ry = tRect.nBottom
                   If @tDrawItem.CtlID = %ID_Button2 Then tRect.nLeft = 4 * cxb + cxi
                   FrameRect @tDrawItem.hDc,@tDrawItem.rcItem, GetStockObject(%BLACK_BRUSH)
                   If (@tDrawItem.itemState And %ODS_SELECTED) Then
                      FillRect @tDrawItem.hDc, @tDrawItem.rcItem, hBrush2
                      DrawEdge @tDrawItem.hDC, @tDrawItem.rcItem, %Edge_Sunken, %BF_RECT
                      SetBkMode @tDrawItem.hDC, %TRANSPARENT
                      SetTextColor @tDrawItem.hDC, %BLACK
                      DrawText @tDrawItem.hDC, ByCopy Text, -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
                   Else
                      Call FillRect(@tDrawItem.hDc, @tDrawItem.rcItem, hBrush1)
                      DrawEdge @tDrawItem.hDC, @tDrawItem.rcItem, %Edge_Raised, %BF_RECT
                      SetBkMode @tDrawItem.hDC, %TRANSPARENT
                      SetTextColor @tDrawItem.hDC, %WHITE
                      DrawText @tDrawItem.hDC, ByCopy Text, -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
                   End If
                   If (@tDrawItem.itemState And %ODS_FOCUS) Then
                      InflateRect @tDrawItem.RcItem, -3 * cxb, -3 * cyb
                      DrawFocusRect @tDrawItem.hDC, @tDrawItem.rcItem
                    End If
                    If @tDrawItem.CtlID = %ID_Button2 Then DrawIconEx @tDrawItem.hDC, 7 * cxb, (ry - cyi) / 2, icon, cxi, cyi, 0, ByVal 0, %DI_Normal
                    Function = %False
                Case Else
                    Function = %True
                End Select
        End Select
    End Function
    
    Function PbMain
      Local hDlg As Long
      Dialog New 0 ,"Owner-drawn", 0, 0, 105, 90, %DS_CENTER Or %WS_SYSMENU  To hDlg
      Dialog Show Modal hDlg Call hDlg_CB
    End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Borje Hagsten
    replied
    A wild shot, but maybe you need to send a WM_FONTCHANGE message
    with hwnd set to HWND_BROADCAST, so all top-level windows gets it?
    Shouldn't have to do that in this case, but who knows - Windows
    sometimes moves in mysterious ways..


    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Borje --
    Unf. the same story
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "WIN32API.INC"
    
       Function WinMain (ByVal hInstance As Long, ByVal hPrevInstance As Long, _
          lpCmdLine As Asciiz Ptr, ByVal nCmdShow  As Long) As Long
    
          Local Msg As tagMsg, wClass  As WndClassEx,  hWnd As Dword, szClassName As Asciiz * 9
          szClassName = "BtnLook"
          wClass.cbSize        = SizeOf(wClass)
          wClass.hInstance     = hInstance
          wClass.lpszClassName = VarPtr(szClassName)
          wClass.lpfnWndProc   = CodePtr(MainWndProc)
          wClass.hbrBackground = GetStockObject(%WHITE_BRUSH)
          RegisterClassEx wClass
    
          hWnd = CreateWindow (szClassName, "Test", %WS_OVERLAPPEDWINDOW, _
             10, 10, 240, 180, %NULL, %NULL, hInstance, %NULL)
    
          %ID_TEXTBOX = 101
          %ID1 = 102
          %ID2 = 103
          CreateWindow "edit", "Ñåìåí", %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %WS_TABSTOP, _
               10, 10, 200, 30, hWnd, %ID_TEXTBOX, hInstance, 0&
          CreateWindow "button", "&Ñåìåí", %WS_CHILD Or %WS_VISIBLE Or %BS_PUSHBUTTON Or %WS_TABSTOP, _
              10, 55, 200, 30, hWnd, %ID1, hInstance, 0&
          CreateWindow "static", "&Ñåìåí", %WS_CHILD Or %WS_VISIBLE  Or %WS_TABSTOP Or %SS_RIGHT Or %WS_BORDER, _
              10, 100, 200, 30, hWnd, %ID2, hInstance, 0&
          SetFocus GetDlgItem(hWnd, %ID_TEXTBOX)
          Dim i As Long, hFont1 As Long, lf As LOGFONT
          i = GetStockObject(%DEFAULT_GUI_FONT)
          GetObject i, SizeOf(lf), ByVal VarPtr(lf)
          lf.lfCharset = %TURKISH_CHARSET
          lf.lfFaceName = "Times New Roman"
          lf.lfWeight = %FW_BOLD
          hFont1 = CreateFontIndirect(lf)
          For i = 1 To 3
             PostMessage GetDlgItem(hWnd, 100 + i), %WM_SETFONT, hFont1, 1
          Next
    
    
          ShowWindow  hWnd, nCmdShow
          UpdateWindow hWnd
    
          While GetMessage(Msg, %NULL, 0, 0)
             If IsDialogMessage (hWnd, msg) Then
             Else
                TranslateMessage Msg
                DispatchMessage  Msg
             End If
          Wend
          Function = Msg.wParam
       End Function
    
       Function MainWndProc(ByVal hWnd As Dword, ByVal wMsg As Dword,_
                            ByVal wParam As Dword, ByVal lParam As Dword) Export As Long
          Select Case wMsg
            Case %WM_COMMAND: SetWindowText hWnd, "ID = " + Format$(LoWrd(wParam))
            Case %WM_DESTROY: PostQuitMessage 0: Exit Function
         End Select
         Function = DefWindowProc(hWnd, wMsg, wParam, lParam)  'performs default processing of message
      End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Borje Hagsten
    replied
    Have you tried creating a STATIC via SDK and see how that works?
    The DDT engine has some strange behaviour with labels, like you
    can't place other controls inside a DDT label, so one must use
    SDK style creation to be able to do that.

    Maybe using CreateWindow instead will fix the font problem too..


    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Lance --
    It's not substitution and not depends of LF.lfFaceName.
    For example, if to set "Times New Roman", results will be the same - in button / label will be Times New Roman, but with system charset.
    Meanwhile if to use hFont with TextOut results are correct.
    Exactly this surprise me. It looks that Button / Label do not use hFont directly and re-create new font.
    Is it possible ?


    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    Usually that kind of effect means that Windows could not create a font with the exact attributes you specified, or it found a "substitute" font with the exact attributes before it enumerated down to the one you actually wanted.

    Try specifying the name of the font in the LF.lfFaceName to reduce the chance of a substitution.


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

    Leave a comment:


  • Semen Matusovski
    replied
    Jim --
    I am not sure that US release includes the same fonts as local Europian.
    Each font, which I have, has following charsets:
    Windows Latin 1 (US, Western Europe) / Greece / Russian / Turkish and so on.

    What I see. Default charset is Russian.
    $Text, written using russian ASCII, looks approx. "Cemeh"

    In hFont I set turkish charset and see in first textbox "Natai" (as expected)
    But in first label and first button I see "Cemeh". This means that charset in logfont is ignored.

    To avoid possible jokes fronm browser's side I decided to write Text using CHR.
    And expanded a sample a little.

    First three elements should have the same font-1
    Other three elements should have font-2.

    [This message has been edited by Semen Matusovski (edited March 02, 2001).]

    Leave a comment:


  • Jim Huguley
    replied

    Hi Semen...

    It works on my computer as expecteded.. Text is all in the same font.

    Win2000 Pro with SP1

    Jim


    ------------------
    Jim..
    [email protected]

    Leave a comment:


  • Semen Matusovski
    started a topic hFont in Static, Button

    hFont in Static, Button

    Under Win2000 with the same hFont I see different results:
    textbox - as expected, label and button - the same font but with default charset.
    Why ? And how it could be ? What is hFont ?
    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "WIN32API.INC"
       CallBack Function DlgProc
          Select Case CbMsg
             Case %WM_INITDIALOG
                Dim i As Long, lf As Logfont, hFont1 As Static Long, hFont2 As Static Long
                Dim Text As String
                Text =  Chr$(209, 229, 236, 229, 237)
                Control Add Button, CbHndl, 101, Text, 10, 10, 100, 15
                Control Add TextBox, CbHndl, 102, Text, 10, 30, 100, 15
                Control Add Label, CbHndl, 103, Text, 10, 50, 100, 15
                Control Add Button, CbHndl, 104, Text, 10, 80, 100, 15
                Control Add TextBox, CbHndl, 105, Text, 10, 110, 100, 15
                Control Add Label, CbHndl, 106, Text, 10, 140, 100, 15
                i = GetStockObject(%DEFAULT_GUI_FONT)
                GetObject i, SizeOf(lf), ByVal VarPtr(lf)
                lf.lfCharset = %TURKISH_CHARSET
                lf.lfWeight = %FW_BOLD
                hFont1 = CreateFontIndirect(lf)
                For i = 1 To 3
                   PostMessage GetDlgItem(CbHndl, 100 + i), %WM_SETFONT, hFont1, 1
                Next
                lf.lfCharset = %RUSSIAN_CHARSET
                hFont2 = CreateFontIndirect(lf)
                For i = 4 To 6
                   PostMessage GetDlgItem(CbHndl, 100 + i), %WM_SETFONT, hFont2, 1
                Next
             Case %WM_DESTROY
                DeleteObject hFont1
                DeleteObject hFont2
          End Select
       End Function
       
       Function PbMain
          Dim hDlg As Long
          Dialog New %HWND_DESKTOP, "", , , 200, 200, %WS_SYSMENU To hDlg
          Dialog Show Modal hDlg Call DlgProc
       End Function
    [This message has been edited by Semen Matusovski (edited March 02, 2001).]
Working...
X
😀
🥰
🤢
😎
😡
👍
👎