Announcement

Collapse
No announcement yet.

Rich Edit Font and KillFocus Problem

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

  • Danny Faris
    replied
    Hi, Borje and Timm:

    Thank you both for your prompt and helpful replies.

    Borje, the rich edit seems to be functioning fine now, the font is identical to the font of the other controls which is excelent.

    Timm, the WM_ActivateApp message works wonders. I don't know why WM_KillFocus was acting so strangely, but WM_ActivateApp is reliable every time.

    Thanks again for all your help, and have a great day!

    Cheers,

    Danny.

    [This message has been edited by Danny Faris (edited July 01, 2001).]

    Leave a comment:


  • Timm Motl
    replied
    Danny:

    Regarding the focus...
    Code:
       SELECT CASE CBMSG
       '
       CASE %WM_ACTIVATEAPP
          IF CBWPARAM THEN
             ' Your window is about to be reactivated
          ELSE
             ' Your window is about to be deactivated
          END IF
          FUNCTION = 0
       '
       END SELECT
    Timm

    Leave a comment:


  • Borje Hagsten
    replied
    What font? Like for WingDing, the character-set needs to be determined.
    I once posted a CharacterMap to source code forum, with following
    functions for creating a working font. Even does WingDing ok:
    Code:
    GLOBAL CharSet AS LONG
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create a desirable font and return its handle. Original code by Dave Navarro
    ' NOTE: enhanced with proper enumeration of character set via EnumFontDataProc
    ' Call like:   hFont = MakeFontEx(hDlg, "Times New Roman", 10, %FW_BOLD, 0, 0)
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION MakeFontEx(BYVAL hWnd AS LONG, BYVAL Font AS STRING, BYVAL PointSize AS LONG, _
                         BYVAL fBold AS LONG, BYVAL fItalic AS LONG, BYVAL fUnderline AS LONG) AS LONG
     
      LOCAL hDC AS LONG, CyPixels AS LONG, lf AS LOGFONT
     
      hDC = GetDC(%HWND_DESKTOP)
      CyPixels  = GetDeviceCaps(hDC, %LOGPIXELSY)
      EnumFontFamilies hDC, BYVAL STRPTR(Font), CODEPTR(EnumFontDataProc), BYVAL VARPTR(hWnd)
      ReleaseDC %HWND_DESKTOP, hDC
      PointSize = 0 - (PointSize * CyPixels) \ 72
     
      FUNCTION = CreateFont( _
                 PointSize, 0, _        'height, width(default=0)
                 0, 0, _                'escapement(angle), orientation
                 fBold, _               'weight (%FW_DONTCARE = 0, %FW_NORMAL = 400, %FW_BOLD = 700)
                 fItalic, _             'Italic
                 fUnderline, _          'Underline
                 %FALSE, _              'StrikeThru
                 CharSet, %OUT_TT_PRECIS, _
                 %CLIP_DEFAULT_PRECIS, %DEFAULT_QUALITY, _
                 %FF_DONTCARE , BYCOPY Font)
     
    END FUNCTION
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Get type of character set - ansi, symbol.. a must for some fonts.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION EnumFontDataProc(lf AS LOGFONT, tm AS TEXTMETRIC, BYVAL FontType AS LONG, hWnd AS LONG) AS LONG
      CharSet = lf.lfCharSet
      FUNCTION = 0 'only needed it for this font, so return zero and break action
    END FUNCTION
    Otherwise, simple way should work, like:
    Code:
      LOCAL lf AS LogFont, hFont as long
      lf.lffacename = "Times New Roman"
      lf.lfWeight   = %FW_BOLD
      hFont = CreateFontIndirect(lf)
      SendMessage rEdit, %WM_SETFONT, hFont, 0
    Also, remember to "DeleteObject hFont" before program exits, to avoid
    memory leaks.

    As for focus: I think you can use wParam (CBWPARAM) in WM_KILLFOCUS.
    If focus is set to another program, wParam contains a handle of window
    getting focus. If focus switches to other control in program, wParam
    is %NULL. Same with WM_SETFOCUS. So, "IF wParam THEN" maybe can help?


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

    Leave a comment:


  • Danny Faris
    started a topic Rich Edit Font and KillFocus Problem

    Rich Edit Font and KillFocus Problem

    Hi All:

    I've got a couple of quick questions.

    First of all, how would I go about setting the font of a Rich Edit control? I am currently sending the window that created the Rich Edit a WM_SetFont message with a handle to a font created by CreateFondIndirect. This stratigy works for all controls - buttons, combo and list boxes, even standard text boxes - but when it comes to the rich edit it doesn't seem to set the text font and weight. Everything else works, the size and italic, strikeout and underline portions of the font are set just fine in the rich edit. What am I doing wrong?

    Also, I'm trying to find out when my program recieves and looses the keyboard focus, so the back ground music I have playing only plays when the user is actually using my program. WM_SetFocus is sent just fine, but as near as I can figure, the WM_KillFocus message is sent to my callback directly after WM_SetFocus is sent - totally rediculous, I know, but that is what it seems to do. It does send EN_KillFocus messages when I Alt+Tab away from the program, but those are also sent when I tab out of the edit box to another control so that is unreliable, and different messages are sent if I switch away and a button (for example) has the keyboard focus. Any other ideas?

    Thanks for your help. I've been battling these 2 little things for a while now. Just thought someone might have a magical solution for them.

    Have a great weekend!

    Danny.
Working...
X