• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

[SDK] 07 - Take control of your window(s) [????? LOOK]

Started by Patrice Terrier, August 12, 2007, 06:13:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

WORK IN PROGRESS

In this version we introduce the use of the extended style: WS_EX_LAYERED and WS_EX_COMPOSITED
We need them to perform compositing and alphablending that is the key to create amazing effects.

Compositing means that we paint our controls from bottom to top as multiple overlaping layers just like you could do in painting softwares like PhotoShop the Gimp or zDraw...

Layered window they can only be used with 2000, XP and VISTA, but this tutorial anyway is targeted only to the NT technology.

To create a transparent window, not only it must have the WS_EX_LAYERED extended style but you must also setup the alpha channel like this:

DECLARE FUNCTION SetLayeredWindowAttributes (BYVAL LONG, BYVAL LONG, BYVAL BYTE, BYVAL LONG) AS LONG
' Allows to use Windows translucency with 2000 and XP
FUNCTION zSetLayeredAlpha (BYVAL hWnd AS LONG, BYVAL TransLevel AS BYTE) AS LONG
    STATIC hLib???, hProc???
    IF hLib??? = 0 THEN hLib??? = LoadLibrary ("User32.dll")
    IF hLib??? AND zOsVersion > 499 THEN ' If Windows 2000 or XP
       IF hProc??? = 0 THEN hProc??? = GetProcAddress(hLib???, "SetLayeredWindowAttributes")
       IF hProc??? THEN
          OldStyle& = GetWindowLong(hWnd&, %GWL_EXSTYLE)
          CALL SetWindowLong(hWnd&, %GWL_EXSTYLE, OldStyle& OR %WS_EX_LAYERED)
        ' Use this with a transparent color
        ' CALL DWORD hProc??? USING SetLayeredWindowAttributes (hWnd&, RGB(255,0,255), TransLevel?, %LWA_ALPHA OR %LWA_COLORKEY) TO lRet&
          CALL DWORD hProc??? USING SetLayeredWindowAttributes (hWnd&, 0, TransLevel?, %LWA_ALPHA) TO lRet&
          IF lRet& THEN FUNCTION = -1
       END IF
    END IF
END FUNCTION


The TransLevel paremeter ranges from 0 (full transparent mode) to 255 (full opaque mode).
And if you are very attentive, you will see that a special effect is used to show the form while switching from DEFAULT to MAXIMIZE and RESTORE mode.


Starting with this version, you can now paint the background of the form either in tiled or stretched mode, when using the stretched mode there is a new function to compute the zoom factor being used to stretch the background while preserving the aspect of the original image altogether with the necessity to paint the whole form.

'// Computes location and size to stretch a bitmap preserving its aspect.
SUB zComputeAspect (BYVAL xPicSize AS LONG, BYVAL yPicSize AS LONG, BYVAL xCell AS LONG, BYVAL yCell AS LONG, BYREF xPos AS LON
, BYREF yPos AS LONG, BYREF xSize AS LONG, BYREF ySize AS LONG)
    LOCAL scale AS SINGLE
    IF xPicSize THEN scale = xCell / xPicSize
    xSize = xPicSize * scale: ySize = yPicSize * scale
    IF ySize < yCell THEN
       IF yPicSize THEN scale = yCell / yPicSize
       xSize = xPicSize * scale: ySize = yPicSize * scale
    END IF
    xPos = (xCell - xSize) \ 2: yPos = (yCell - ySize) \ 2
END SUB


There are also a couple of functions to help computation of true 32-bit ARG colors:
'// Split a true 32-bit ARGB color into its four components.
SUB zSplitColorARGB (BYVAL ARGB&, Alpha AS BYTE, Red AS BYTE, Green AS BYTE, Blue AS BYTE)

'// Add the alpha channel to RGB color to create true 32-bit ARGB color.
FUNCTION zColorARGB (BYVAL Alpha AS BYTE, BYVAL ColrRGB???) AS LONG

For the purpose of compositing I have added a new function to help changing the z-order of controls.

'// Set control z-order
SUB zSetZorder(BYVAL hWnd AS LONG, BYVAL UseOrder AS LONG)
    CALL SetWindowPos(hWnd, UseOrder, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE OR %SWP_NOACTIVATE)
END SUB


I have added a new zFrameButton to show you two things:
1 - Changing the z-order to put the %ID_AEROBUTTON at the z-order's bottom.
2 - Using the %ANCHOR_CENTER_HORZ_BOTTOM to resize the %ID_AEROBUTTON while resizing the main form.

Double buffer has been reworked to take care of a special case when switching from MAXIMIZE to RESTORE mode. To see the double buffer in action, just move any window hover the Template form and see how it is redrawn, then do the same hover any other application and see the difference.


And now unzip zskin06.zip and see the result of my work...
(many graphic components have been reworked to achieve this ????? LOOK)

The zip file has been updated see it there

Patrice Terrier
www.zapsolution.com



Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Petr Schreiber

Patrice,

another eye-candy - great work !
We don't need Vista anymore :)

Which software do you use to design buttons ?


Bye,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Patrice Terrier

QuoteWhich software do you use to design buttons ?
PhotoShop
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Eros Olmi

thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Kent Sarikaya

That looks so sweet! It just gives such a wonderful new feel and look that is very comfortable with beautiful eye candy!

Patrice Terrier

The first post of this thread has been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com