Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [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\CreateImageItem.bas

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

Sub Item_Bitmap.Destroy()
    ID = "" : Title = ""
    DestroyWindow(whwnd)

    Using GDIPLUS
        GdipDisposeImage Origin
        DeleteObject(Image)

        Origin = 0
        Image  = 0
        whwnd  = 0
End Sub

Function CreateImageItem(byref ItemHandle as Item, byref ImageHandle as HBITMAP, byval px as Integer, byval py as Integer, byval iWidth as UInteger = 0, byval iHeight as UInteger = 0) as Item_Bitmap ptr
    Dim as UInteger Style = SS_NOTIFY OR SS_BITMAP OR WS_CHILD OR WS_VISIBLE OR WS_CLIPSIBLINGS OR WS_CLIPCHILDREN
    If ItemHandle = 0 Then return NULL

    Dim as HWND phwnd
    If (ItemHandle -> ID = WindowID) Then
        phwnd = ItemHandle -> whwnd
    ElseIf (ItemHandle -> ID = GroupBoxID) Then
        phwnd = GetParent(ItemHandle -> whwnd)
    Else
        LOGSTRING(Time & " | ERROR | Parent is not an valid Item.")
        Return NULL
    End If

    Using GDIPLUS
        Dim as Item_Bitmap ptr      NewBitmapItem = NEW Item_Bitmap
        Dim as Integer              nWidth, nHeight
        Dim as Integer              oWidth, oHeight
        Dim as GPBITMAP ptr         TempImage

        NewBitmapItem -> Origin = CreateCopy_WINImage_As_GDIImage(ImageHandle)

        GdipGetImageWidth(NewBitmapItem -> Origin, @oWidth)
        GdipGetImageHeight(NewBitmapItem -> Origin, @oHeight)

        nWidth = oWidth : nHeight = oHeight

        If iWidth  Then nWidth  = IIF(iWidth<=oWidth, iWidth, oWidth)
        If iHeight Then nHeight = IIF(iHeight<=oHeight, iHeight, oHeight)

        TempImage = GetRect_From_GDIImage(NewBitMapItem -> Origin, 0, 0, nWidth, nHeight)

        NewBitMapItem -> Image  = CreateCopy_GDIImage_As_WINImage(TempImage)

        GdipDisposeImage TempImage

        NewBitmapItem -> whwnd  = CreateWindowEx( 0, "static", 0, Style, _
                                                 px, py, nWidth, nHeight, phwnd, NULL, Globals.hInstance, NewBitmapItem)

        If (NewBitmapItem -> whwnd = 0) Then
            GdipDisposeImage NewBitmapItem -> Origin
            DeleteObject(NewBitMapItem -> Image)
            Delete NewBitmapItem

            LOGSTRING(Time & " | ERROR | Failed to create " & BitmapID)
            MessageBox(NULL,"Failed to create " & BitmapID, "Error", NULL)
            Return 0
        End If

        SendMessage(NewBitmapItem -> whwnd, STM_SETIMAGE, IMAGE_BITMAP, Cast(LPARAM, NewBitMapItem -> Image))

        NewBitmapItem -> ID      = BitmapID
        NewBitmapItem -> Title   = "w" & str(nWidth) & " h" & str(nHeight)
        NewBitmapItem -> cWidth  = nWidth
        NewBitmapItem -> cHeight = nHeight
        NewBitmapItem -> parent  = ItemHandle

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

        'LOGSTRING(Time & " | INFO  | " & BitmapID & " created.")
        LOGSTRING(Time & " | INFO  | " & BitmapID & " " & NewBitmapItem -> Title & " created on " & ItemHandle -> ID & " " & ItemHandle -> Title & ".")
        Globals.ItemList.AddItem(NewBitmapItem)

        return NewBitmapItem
End Function

Function ResizeImageItem(byref ItemHandle as Item, byval newWidth as UInteger = 0, byval newHeight as Uinteger = 0) as Integer
    If (ItemHandle = 0) orelse ItemHandle -> ID <> BitmapID Then return Not(NULL) 'error
    Using GDIPLUS
        Dim as GPBITMAP ptr     TempImage
        Dim as HBITMAP          NewImage
        Dim as Integer          nWidth, nHeight
        Dim as Integer          oWidth, oHeight

        GdipGetImageWidth(Cast(Item_Bitmap ptr, ItemHandle) -> Origin, @oWidth)
        GdipGetImageHeight(Cast(Item_Bitmap ptr, ItemHandle) -> Origin, @oHeight)

        If newWidth  Then nWidth  = IIF(newWidth<=oWidth, newWidth, oWidth)
        If newHeight Then nHeight = IIF(newHeight<=oHeight, newHeight, oHeight)

        TempImage = GetRect_From_GDIImage(Cast(Item_Bitmap ptr, ItemHandle) -> Origin, 0, 0, nWidth, nHeight) 'get rect
        NewImage  = CreateCopy_GDIImage_As_WINImage(TempImage)

        SendMessage(ItemHandle -> whwnd, STM_SETIMAGE, IMAGE_BITMAP, Cast(LPARAM, NewImage))

        DeleteObject(Cast(Item_Bitmap ptr, ItemHandle) -> Image) 'Delete Old Image

        Cast(Item_Bitmap ptr, ItemHandle) -> Image   = NewImage 'Set
        Cast(Item_Bitmap ptr, ItemHandle) -> Title   = "w" & str(nWidth) & " h" & str(nHeight)

        oWidth  = Cast(Item_Bitmap ptr, ItemHandle) -> cWidth
        oHeight = Cast(Item_Bitmap ptr, ItemHandle) -> cHeight

        Cast(Item_Bitmap ptr, ItemHandle) -> cWidth  = nWidth
        Cast(Item_Bitmap ptr, ItemHandle) -> cHeight = nHeight

        If oWidth<>nWidth or oHeight<>nHeight Then LOGSTRING(Time & " | INFO  | " & BitmapID & " resized. " & Cast(Item_Bitmap ptr, ItemHandle) -> Title)

    Return NULL 'error
End Function

Function ReplaceImageItem(byref ItemHandle as Item, byval newImage as HBITMAP) as Integer
    If (ItemHandle = 0) orelse ItemHandle -> ID <> BitmapID orelse newImage = 0 Then return Not(NULL) 'error
    Using GDIPLUS
        Dim as GPBITMAP ptr     TempImage = CreateCopy_WINImage_As_GDIImage(newImage)
        GdipDisposeImage Cast(Item_Bitmap ptr, ItemHandle) -> Origin
        Cast(Item_Bitmap ptr, ItemHandle) -> Origin = TempImage
        LOGSTRING(Time & " | INFO  | " & BitmapID & " replaced.")
        ResizeImageItem(ItemHandle, Cast(Item_Bitmap ptr, ItemHandle) -> cWidth, Cast(Item_Bitmap ptr, ItemHandle) -> cHeight)
End Function