Jump to content

How to Create a 'Custom' Listbox ?


sheeva
 Share

Recommended Posts

Hi everybody,

I try to find how can i put a bitmap as backround in a listbox.

Of course just a gradient can be great also. i have find some really good gradient functions on this forum but

i cant apply this function to a ListBox without garbage

It's difficult to explain so i have included a example of what i want to do.

Thank's

Happy New year 2010.

post-10931-12624399919636_thumb.jpg

Link to comment
Share on other sites

I'm of the opinion this could only be done with a listview. You can make a 1 column listview with no header, turn the background transparent and place a shownoactivate guictrlpic behind it that would give you the results you are looking for. If I have a minute I will throw one together.

Link to comment
Share on other sites

I'm of the opinion this could only be done with a listview. You can make a 1 column listview with no header, turn the background transparent and place a shownoactivate guictrlpic behind it that would give you the results you are looking for. If I have a minute I will throw one together.

Thanks Picea,

Ok listBox can be a Listview is not very important for my project.

I'm very interested of an example.

thank's.

Link to comment
Share on other sites

Hi Sheeva

Don't have much time, so used the udf I created to render the gradient. You will need to put the udf in the same directory.

It was a bit harder than I expected. I had to use two gui's in order to do it. I personally think it adds too much unnecessary complexity but you be the judge. I hope this helps.

Picea

#include <GuiConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#Include <Misc.au3>
#include <shapedcontrols_udf.au3>
HotKeySet("{esc}","exited")
Opt("TrayAutoPause", 0)
opt("GUIOnEventMode",1)
TraySetClick(8)

Global $nth=5 ; how many inputboxes
Global $stopit

global $dll = DllOpen("user32.dll")

Global $gwidth=500, $gheight=355,$initialpsx=200,$initialpsy=200, $rndclo

; change GUI name to change widget name
Global $Gui = GUICreate("Outlook Calendar Updater", $gwidth, $gheight,$initialpsx,$initialpsy)
$bckpic= GUICtrlCreatePic("", 0, 5, 210, 300)
    GuiCtrlSetState(-1,$GUI_DISABLE)
    background(-1,"0xCCCCCC","0x222222","0x111111")
$bckpic= GUICtrlCreatePic("", 205, 5, 190, 290)
    GuiCtrlSetState(-1,$GUI_DISABLE)
    background(-1,"0xCCCCCC","0x222222","0x111111")
;;;;;;;;;;;;;;;;;register messages for background gui;;;;;;;;;;;;;;;;;;;;;;;;
    GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "Drag" ) ;sets up drag move on background and x button close
GUISetOnEvent($GUI_EVENT_CLOSE,"exiting")

Global $guicontrols=GUICreate("Outlook",$gwidth, $gheight,$initialpsx,$initialpsy,$WS_POPUP,$WS_EX_LAYERED,$Gui) ;gui holding the controls
;;;;;;;;;;;below is a DLLcall register for the foreground child window;;;;;;;;;;;;;;;;
GUISetBkColor(0xABCDEF)
GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "clickbuttons")

; LIST
GuiCtrlCreateList("", 8, 45, 200, 290)
GUICtrlSetBkColor(-1,0xABCDEF);$GUI_BKCOLOR_TRANSPARENT
GuiCtrlSetData(-1, "a.Sample|b.List|c.Control|d.Here", "b.List")

; LIST VIEW
$listView = GuiCtrlCreateListView("Sample|ListView|", 213, 45, 180, 280)
GUICtrlSetBkColor(-1,0xABCDEF);$GUI_BKCOLOR_TRANSPARENT

GuiCtrlCreateListViewItem("A|One", $listView)
GuiCtrlCreateListViewItem("B|Two", $listView)
GuiCtrlCreateListViewItem("C|Three", $listView)


GUISetBkColor(0x000000,$Gui)

_API_SetLayeredWindowAttributes($guicontrols, 0xABCDEF, 255)
GUISetState(@SW_SHOW, $Gui)
GUISetState(@SW_SHOW, $guicontrols)

GUISwitch($guicontrols)

While 1
    Sleep(40)
    $msg = TrayGetMsg()
    if $msg=$TRAY_EVENT_PRIMARYDOWN and WinActive($guicontrols)=0 then WinActivate($guicontrols)

WEnd
func exiting()
    exit 0
EndFunc
Func Drag() ;allows dragging of widget and click to exit

Local $PosDiff[2]
    While 1
        $MousePos = MouseGetPos ()
        $WinPos = WinGetPos ($Gui,"")
        $PosDiff[0] = $WinPos[0] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        While _IsPressed ("01", $dll)
            $MousePos = MouseGetPos ()
            WinMove ($Gui, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
            WinMove ($guicontrols, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
            $WinPos = WinGetPos ("","")
            Sleep (10)
        WEnd
        ExitLoop
        Sleep (10)
    WEnd
    ;_WinAPI_RedrawWindow($Gui,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN))
    _WinAPI_RedrawWindow($guicontrols,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW))
EndFunc


;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description::    Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                  $hwnd - Handle of GUI to work on
;                  $i_transcolor - Transparent color
;                  $Transparency - Set Transparancy of GUI
;                  $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                  Error: 0
;                   @error: 1 to 3 - Error from DllCall
;                   @error: 4 - Function did not succeed - use
;                               _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency, $isColorRef = False)

Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
Local Const $LWA_ALPHA = 0x2
Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error,0,0)
        Case $ret[0] = 0
            Return SetError(4,0,0)
        Case Else
            Return 1
    EndSelect
EndFunc;==>_API_SetLayeredWindowAttributes
Edited by picea892
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...