Buchempfehlung
Visual Basic 6 Kochbuch
Visual Basic 6 Kochbuch
Viele praktische Tipps zum Programmieren mit Visual Basic 6, die sich oft auch auf FB übertragen lassen. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

inc\CreateImageComboBox.bas

Uploader:MitgliedEternal_Pain
Datum/Zeit:19.03.2014 04:43:20
Hinweis: Dieser Quelltext ist Bestandteil des Projekts Windows Easy Gui (WEG), zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.

Sub Item_ImageCombo.Destroy()
    ID = "" : Title = ""
    DestroyWindow(whwnd)
    ICount    = 0 : iState    = 0
    wSizeMode = 0 : hSizeMode = 0
    iWidth    = 0 : iHeight   = 0
    If IList Then deallocate(IList)
End Sub


Function CreateImageComboBox(byref ItemHandle as Item, byval px as Integer, byval py as Integer, byval iWidth as UInteger = 0, byval iHeight as UInteger = 0) as Item
    Dim as UInteger ExStyle = WS_EX_CLIENTEDGE
    Dim as UInteger Style   = WS_CHILD OR WS_VSCROLL OR CBS_AUTOHSCROLL OR CBS_DROPDOWNLIST OR CBS_OWNERDRAWVARIABLE OR CBS_HASSTRINGS OR WS_TABSTOP OR WS_CLIPSIBLINGS OR CBS_NOINTEGRALHEIGHT

    If (ItemHandle = 0) Then return NULL

    Dim as RECT    prect
    Dim as HWND    phwnd
    Dim as Integer rx, ry

    If (ItemHandle -> ID = WindowID) Then
        phwnd = ItemHandle -> whwnd
        rx = px : ry = py
    ElseIf (ItemHandle -> ID = GroupBoxID) Then
        phwnd = GetParent(ItemHandle -> whwnd)
        GetClientRect(ItemHandle -> whwnd, @prect)
        MapWindowPoints(ItemHandle -> whwnd, phwnd, Cast(LPPOINT, @prect),2)
        rx = prect.left + px : ry = prect.top + py
    Else
        LOGSTRING(Time & " | ERROR | Parent is not an valid Item.")
        Return NULL
    End If

    Dim as Item_ImageCombo ptr newImageCombo = new Item_ImageCombo

    newImageCombo -> whwnd = CreateWindowEx(ExStyle, "COMBOBOX", NULL, Style, rx, ry, iWidth, 0, phwnd, NULL, Globals.hInstance, newImageCombo)

    If (newImageCombo -> whwnd = 0) Then
        Delete newImageCombo
        LOGSTRING(Time & " | ERROR | Failed to create " & ImageComboID)
        MessageBox(NULL,"Failed to create " & ImageComboID, "Error", NULL)
        Return NULL
    End If

    SetWindowLongPtr(newImageCombo -> whwnd, GWLP_USERDATA, Cast(LONG_PTR, newImageCombo))

    newImageCombo -> ID        = ImageComboID
    newImageCombo -> Title     = str(newImageCombo -> whwnd)
    newImageCombo -> iState    = FALSE
    newImageCombo -> wSizeMode = IIF(iWidth,0,1)
    newImageCombo -> hSizeMode = IIF(iHeight,0,1)
    newImageCombo -> iWidth    = iWidth
    newImageCombo -> iHeight   = iHeight

    LOGSTRING(Time & " | INFO  | " & ImageComboID & " " & newImageCombo -> Title & " created on " & ItemHandle -> ID & " " & ItemHandle -> Title & ".")

    Globals.ItemList.AddItem(newImageCombo)

    return newImageCombo
End Function


Function AddImageComboBox(byref ImageCombo as Item, byref Image as HBITMAP) as Integer
    If (ImageCombo = 0) orelse (ImageCombo -> ID <> ImageComboID) orelse (Image = 0) Then return -1

    Dim as Item_ImageCombo ptr  ImageComboItem  = Cast(Item_ImageCombo ptr, ImageCombo)
    Dim as Integer              iWidth, iHeight, expand
    Dim as HBITMAP ptr          TempPtr
    Dim as BITMAP bm
    Dim as String               SubItemID
    Dim as Integer              resize          = 0
    Dim as Integer              ListHeight
    Dim as RECT                 wRECT

    expand  = GetSystemMetrics(SM_CXVSCROLL)*1.22
    expand += GetSystemMetrics(SM_CXEDGE)*2

    If ImageComboItem -> IList = 0 Then ImageComboItem -> IList = Callocate(sizeof(any ptr))

    GetClientRect(GetParent(ImageCombo -> whwnd), @wRECT)
    ListHeight = wRECT.bottom - wRECT.top

    GetObject(Image, sizeof(BITMAP), @bm)

    If ImageComboItem -> wSizeMode Then
        iWidth = bm.bmWidth+expand
        If iWidth > ImageComboItem -> iWidth Then ImageComboItem -> iWidth = iWidth
    End If

    If ImageComboItem -> hSizeMode Then
        iHeight = bm.bmHeight
        If iHeight > ImageComboItem -> iHeight Then ImageComboItem -> iHeight = iHeight
    End If

    If ImageComboItem -> iHeight > 255 Then ImageComboItem -> iHeight = 255 'maxHeight

    If ((ImageComboItem -> ICount+3) * ImageComboItem -> iHeight) < ListHeight Then ListHeight = ((ImageComboItem -> ICount+3) * ImageComboItem -> iHeight)

    Function = ImageComboItem -> ICount
    ImageComboItem -> ICount += 1

    TempPtr = Reallocate(ImageComboItem -> IList, ImageComboItem -> ICount*sizeof(any ptr))
    ImageComboItem -> IList = TempPtr

    ImageComboItem -> IList[ImageComboItem -> ICount-1] = Image

    SubItemID = str(ImageCombo)

    SendMessage(ImageComboItem -> whwnd, CB_ADDSTRING, NULL, cast(LPARAM,strptr(SubItemID)))

    If SendMessage(ImageCombo -> whwnd, CB_GETCURSEL, NULL, NULL) = -1 Then SendMessage(ImageCombo -> whwnd, CB_SETCURSEL, Cast(WPARAM, 0), NULL)

    Dim as RECT cRECT
    MapWindowPoints(ImageComboItem -> whwnd, GetParent(ImageComboItem -> whwnd), Cast(LPPOINT,@cRECT),2)
    MoveWindow(ImageComboItem -> whwnd, cRECT.left, cRECT.top, ImageComboItem -> iWidth, ListHeight, TRUE)
    SendMessage(ImageComboItem -> whwnd, CB_SETITEMHEIGHT, -1, ImageComboItem -> iHeight)

    If ImageComboItem -> iState = FALSE Then
        ShowWindow(ImageComboItem -> whwnd, SW_SHOW)
        ImageComboItem -> iState = TRUE
    End If
End Function

Function GetImageComboBox(byref ImageCombo as Item) as Integer
    If ImageCombo = 0 orelse ImageCombo -> ID <> ImageComboID Then return -1
    Dim as Integer ID
    ID = SendMessage(ImageCombo -> whwnd, CB_GETCURSEL, NULL, NULL)
    If ID<>CB_ERR Then return ID
    return -1
End Function

Function SetImageComboBox(byref ImageCombo as Item, byval ID as Integer) as Integer
    If ImageCombo = 0 orelse ImageCombo -> ID <> ImageComboID Then return -1
    If ID > -1 andalso ID < Cast(Item_ImageCombo ptr, ImageCombo) -> ICount Then
        SendMessage(ImageCombo -> whwnd, CB_SETCURSEL, Cast(WPARAM, ID), NULL)
        return 0
    End If
    return -1
End Function