ComboBoxGadget und große Bilder nutzen

Windowsspezifisches Forum , API ,..
Beiträge, die plattformübergreifend sind, gehören ins 'Allgemein'-Forum.
Benutzeravatar
kunstlust
Beiträge: 259
Registriert: 12.04.2012 23:47
Wohnort: Hannover
Kontaktdaten:

ComboBoxGadget und große Bilder nutzen

Beitrag von kunstlust »

Gibt es eine Möglichkeit, innerhalb eines ComboBoxGadget die Bilder in der Größe zu ändern?
Ich würde gerne so 100x100 Pixelbild anzeigen, welche als Vorlage für eine Berechnung ausgewällt werden sollte. Alle 6-8 Bilder in die Form zu legen, würde einfach zu viel Platz kosten und eine ComboBox die ein Image per Event ändert, finde ich noch nicht so schön, oder jemand eine andere Idee?

Danke für Tipps

Also der Geebee2 hat 128x128 Pixel und die wüde ich auch gerne ComboBoxGadget sehen :freak:

Code: Alles auswählen

LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/Geebee2.bmp") 
  If OpenWindow(0, 0, 0, 150, 320, "Geebee2", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ComboBoxGadget(1, 10, 40, 128, 128, #PB_ComboBox_Image)
      AddGadgetItem(1, -1, "", ImageID(0))
      SetGadgetState(1, 0)
      ButtonImageGadget(2, 10, 180, 128, 128, ImageID(0))
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
__________________________________________________
Thread verschoben
Grafik & Sound - Programmierung>Windows
29.07.2013
RSBasic
Benutzeravatar
RSBasic
Admin
Beiträge: 8047
Registriert: 05.10.2006 18:55
Wohnort: Gernsbach
Kontaktdaten:

Re: ComboBoxGadget und große Bilder nutzen

Beitrag von RSBasic »

Basierend auf den folgenden Code: http://www.purebasic.fr/english/viewtop ... 47#p301247

Ich habe den Code mal angepasst:

Code: Alles auswählen

EnableExplicit

Define EventID
Define hIcon1
Define hIcon2
Define hIcon3
Global CBID = 1
Global CBIconSize = 32;oder 64
Global CBTextTopPos = 10;oder 28

hIcon1 = ExtractIcon_(0, #PB_Compiler_Home + "PureBasic.exe", 1)
hIcon2 = ExtractIcon_(0, "shell32.dll", 10)
hIcon3 = ExtractIcon_(0, "shell32.dll", 20)

Global Dim CBIcons(2)
CBIcons(0) = hIcon1
CBIcons(1) = hIcon2
CBIcons(2) = hIcon3

Procedure FreehIcons()
  Protected k
  
  For k = 0 To ArraySize(CBIcons())
    DestroyIcon_(CBIcons(k))
  Next
  
EndProcedure

Procedure WinProc(hwnd, msg, wparam, lparam)
  Protected result
  Protected *dis.DRAWITEMSTRUCT
  Protected text$
  Protected hBrush
  Protected oldbrush
  Protected *mis.MEASUREITEMSTRUCT
  
  result = #PB_ProcessPureBasicEvents
  
  Select msg
    Case #WM_DRAWITEM
      *dis.DRAWITEMSTRUCT = lparam
      If *dis\ctlid = CBID
        With *dis
          text$ = GetGadgetItemText(\ctlid, \itemid)
          If \itemstate & #ODS_SELECTED 
            hBrush = CreateSolidBrush_(GetSysColor_(#COLOR_HIGHLIGHT))
            oldbrush = SelectObject_(\hdc, hBrush)
            FillRect_(\hdc, \rcitem, hBrush)
            DeleteObject_(hBrush)
            DrawFocusRect_(\hdc, \rcitem)
            If \itemid >=0 And \itemid <= CountGadgetItems(\ctlid)-1
              DrawIconEx_(\hdc, 4,\rcitem\top+1, CBIcons(\itemid),CBIconSize,CBIconSize, 0,0,#DI_NORMAL|#DI_COMPAT)
            EndIf
            SelectObject_(\hdc, oldbrush)
            SetBkColor_( \hdc, GetSysColor_(#COLOR_HIGHLIGHT))
            TextOut_( \hdc, \rcItem\left+CBIconSize+8, \rcItem\top+CBTextTopPos, text$, Len(text$))
          Else
            hBrush = CreateSolidBrush_(#White)
            oldbrush = SelectObject_(\hdc, hBrush)
            FillRect_(\hdc, \rcitem, hBrush)
            DeleteObject_(hBrush)
            SelectObject_(\hdc, oldbrush)
            If \itemid >=0 And \itemid <= CountGadgetItems(\ctlid)-1
              DrawIconEx_(\hdc, 4,\rcitem\top+1, CBIcons(\itemid),CBIconSize,CBIconSize, 0,0,#DI_NORMAL)
            EndIf
            SetBkColor_( \hdc, #White)
            TextOut_( \hdc, \rcItem\left+CBIconSize+8, \rcItem\top+CBTextTopPos, text$, Len(text$))
          EndIf
        EndWith
      EndIf
      
    Case #WM_MEASUREITEM
      *mis.MEASUREITEMSTRUCT = lparam
      If *mis\ctlid = CBID
        *mis\itemheight = CBIconSize+2
      EndIf
  EndSelect
  
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WinProc())
  
  ComboBoxGadget(1, 10, 10, 200, CBIconSize+8, #CBS_OWNERDRAWVARIABLE | #CBS_HASSTRINGS)
  AddGadgetItem(1, -1, "Eintrag 1", 0, 0)
  AddGadgetItem(1, -1, "Eintrag 2", 0, 0)
  AddGadgetItem(1, -1, "Eintrag 3", 0, 0)
  
  SetGadgetState(1, 0)
  
  Repeat
    EventID = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
      FreehIcons()
      End
    EndIf
  ForEver
EndIf
Aus privaten Gründen habe ich leider nicht mehr so viel Zeit wie früher. Bitte habt Verständnis dafür.
Bild
Bild
Benutzeravatar
kunstlust
Beiträge: 259
Registriert: 12.04.2012 23:47
Wohnort: Hannover
Kontaktdaten:

Re: ComboBoxGadget und große Bilder nutzen

Beitrag von kunstlust »

@RSBasic

:bounce: Danke es geht sogar CBIconSize = 128, was reichen sollte.
Ich schaue wohl doch beim nähsten Problem, erst in das englische Forum rein :o
Antworten