Shaped Window


Windows don't need to be rectangular. Change the shape with API calls.

'Demo of shaped window, created from region.
'Window is also framed.
'You may use this code in your programs.
'You may not redistribute this code.
'Alyce Watson, May, 2001
'updated for LB4, April, 2008
'
'For best results, use the "region" GDI functions
'to color the window.  This demo uses PaintRgn
'and FrameRgn.

nomainwin
    calldll #gdi32, "CreateEllipticRgn",_
        0 as long,_
        30 as long,_
        300 as long,_
        200 as long,_
        hRgn as ulong

    WindowWidth=350:WindowHeight=250
    open "Elliptic Window" for window_popup as #1
    print #1, "trapclose [quit]"

    h=hwnd(#1)
    crColor=hexdec("&HFFDD99")
    calldll #gdi32, "CreateHatchBrush",_
        _HS_VERTICAL  as long,_
        crColor as long,_
        hBrush as ulong

    calldll #user32, "GetDC",h as ulong, hDC as ulong

    calldll #gdi32,"SelectObject",_
        hDC as ulong,_
        hBrush as ulong,_
        result as ulong

    calldll #gdi32, "PaintRgn",_
        hDC as ulong,_
        hRgn as ulong,_
        result as ushort

    calldll #gdi32,"DeleteObject",hBrush as ulong,r as long

    crColor=hexdec("&H55DDFF")
    calldll #gdi32, "CreateSolidBrush",_
        crColor as long,_
        hBrush as ulong

    calldll #gdi32, "FrameRgn",_
        hDC as ulong,_
        hRgn as ulong,_
        hBrush as ulong,_
        5 as long,_    'frame width thickness
        5 as long,_    'frame height thickness
        r as long

    calldll #user32, "SetWindowRgn",_
    h as ulong, hRgn as ulong, 1 as long, result as long

    text$="Alt-F4 to close"
    length=len(text$)
    calldll#gdi32,"TextOutA",_
        hDC as ulong,_
        105 as long,_
        105 as long,_
        text$ as ptr,_
        length as long,_
        result as long

[loop]
    wait

[quit]
    calldll #gdi32,"DeleteObject",hBrush as ulong,r as long
    calldll #gdi32,"DeleteObject",hRgn as ulong,r as long
    calldll #user32, "ReleaseDC",h as ulong, hDC as ulong, r as long
    close #1:end


Home

Source Code

Utilities

Internet

Games

Graphics

Media Demos

Snippets

DLL's

API Resources

Freeware

LB 4 Companion

Mastering LB 3

LB Workshop

Game Workshop

Links

Index