Re: [WIN32LIB] Transparent Labels

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here you go... I already told you this in the chatroom, but I though I might 
as well share it.

Use this code as the Paint routine of the label you want to be transparent:

global procedure PaintTransparentLabel(atom hWnd)
    atom client_rect, szText, pFont, pOldFont, dwStyle, dwText, void,len

    atom dc -- device context for painting
    hWnd = getHandle(hWnd)
    dc = w32Func(xGetDC, {hWnd})

    -- Where to draw text
    client_rect = allocate(16)
    void = w32Func(xGetClientRect, {hWnd, client_rect})

    -- Get the caption
    len = w32Func(xGetWindowTextLength, {hWnd})
    szText = allocate(len)
    void = w32Func(xGetWindowText, {hWnd, szText, len})

    -- Get the font
    pFont = w32Func(xSendMessage, {hWnd, WM_GETFONT, 0, 0})
    pOldFont = w32Func(xSelectObject, {dc, pFont})

    -- Map "Static Styles" to "Text Styles"
    dwStyle = w32Func(xGetWindowLong, {hWnd, GWL_STYLE})
    dwText = 0
    if and_bits(dwStyle, SS_RIGHT) then
        dwText = or_bits(dwText, DT_RIGHT)
    end if
    if and_bits(dwStyle, SS_CENTER) then
        dwText = or_bits(dwText, DT_CENTER)
    end if
    if and_bits(dwStyle, SS_CENTERIMAGE) then
        dwText = or_all({dwText, DT_VCENTER, DT_SINGLELINE})
    end if
    if and_bits(dwStyle, SS_NOPREFIX) then
        dwText = or_bits(dwText, DT_NOPREFIX)
    end if
    if and_bits(dwStyle, SS_WORDELLIPSIS) then
        dwText = or_bits(dwText, DT_WORD_ELLIPSIS)
    end if
    if and_bits(dwStyle, SS_ENDELLIPSIS) then
        dwText = or_bits(dwText, DT_END_ELLIPSIS)
    end if
    if and_bits(dwStyle, SS_PATHELLIPSIS) then
        dwText = or_bits(dwText, DT_PATH_ELLIPSIS)
    end if

    if not(and_bits(dwStyle, or_all({SS_LEFTNOWORDWRAP, SS_CENTERIMAGE, 
SS_WORDELLIPSIS, SS_ENDELLIPSIS, SS_PATHELLIPSIS}))) then
        dwText = or_bits(dwText, DT_WORDBREAK)
    end if

    -- Set transparent background
    void = w32Func(xSetBkMode, {dc, TRANSPARENT})

    -- Draw the text
    --void = w32Func(xDrawText, {dc, szText, len - 1, client_rect, dwText})
    -- Some win32lib versions incorrectly define it as a procedure....
    -- Win32Lib v 0.58.2 seems to have it right
    w32Proc(xDrawText, {dc, szText, len - 1, client_rect, dwText})

    -- Select old font
    void = w32Func(xSelectObject, {dc, pOldFont})
    void = w32Func(xReleaseDC, {hWnd, dc})
    free(client_rect)
    free(szText)
end procedure

>From: Travis Beaty <t_beaty at mchsi.com>
>Reply-To: EUforum at topica.com
>To: EUforum <EUforum at topica.com>
>Subject: [WIN32LIB] Transparent Labels
>Date: Mon, 10 Mar 2003 14:00:56 -0600
>
>
>Hello everyone!
>
>I have a quick question.  I am working on a project, but not in Euphoria 
>due to the fact that I haven't been able to create a transparent label 
>using win32lib.ew.  The basic idea is that the main form has, as a 
>background, an image.  The labels are placed on top of this image, and 
>ideally, the image would be seen through the label, so that the text would 
>appear to be written directly on top of the background image. Yes, I 
>suppose I could use putsw to write the text directly on the form using 
>wPuts(), but I am worried about a "flashing" effect, as most of the text 
>would need to be updated once per second, and a few every 1/8 second, so 
>this might be a little better achieved via a transparent label and 
>setText().
>
>I've been able to do this with Borland C++, using VCL and transparent 
>labels, but I would much, MUCH rather write this application in Euphoria.
>
>Any ideas?
>
>
>Travis Beaty
>Mason City, Iowa
>
>
>
>TOPICA - Start your own email discussion group. FREE!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu