PB6.30B4 - MenuItemState not visible with images

Just starting out? Need help? Post your questions and find answers here.
dige
Addict
Addict
Posts: 1424
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

PB6.30B4 - MenuItemState not visible with images

Post by dige »

SetMenuItemState(0, 1, 1) --> Menu status is set to true, but the check mark is not visible.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Menu example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------

CreateImage(0, 16, 16, 24, #Red)
CreateImage(1, 16, 16, 24, #Blue)

If CreatePopupMenu(0)
  MenuItem(1, "Option 1", ImageID(0))
  MenuItem(2, "Option 2", ImageID(1))
EndIf

SetMenuItemState(0, 1, 1)

;
If OpenWindow(0, 100, 100, 300, 260, "PureBasic - PopupMenu Example")

  Repeat

    Select WaitWindowEvent()
        
      Case #PB_Event_RightClick       ; rechte Maustaste wurde gedrückt =>
        DisplayPopupMenu(0, WindowID(0))  ; zeige jetzt das Popup-Menü an

      Case #PB_Event_CloseWindow
        Quit = 1

    EndSelect

  Until Quit = 1

EndIf

End

"Daddy, I'll run faster, then it is not so far..."
Fred
Administrator
Administrator
Posts: 18393
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB6.30B4 - MenuItemState not visible with images

Post by Fred »

I don't think you can have both. Was it working before ?
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 507
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: PB6.30B4 - MenuItemState not visible with images

Post by Mindphazer »

It doesn't work with PB6.21 either
I think it's specific to Windows, as it does work fine on MacOS (both check mark and image are visible)
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
normeus
Enthusiast
Enthusiast
Posts: 485
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PB6.30B4 - MenuItemState not visible with images

Post by normeus »

Using "CreatePopupImageMenu(0)",
It works with PB 6.12 LTS x64 windows( it displays image and checkmark)
However, it does not work with 6.30 beta 4 pbx64 windows( only image is displayed )


Code: Select all

CreateImage(0, 16, 16, 24, #Red)
CreateImage(1, 16, 16, 24, #Blue)

If OpenWindow(0, 100, 100, 300, 260, "PureBasic - PopupMenu Example")
If CreatePopupImageMenu(0)
  MenuItem(1, "Option 1", ImageID(0))
  MenuItem(2, "Option 2", ImageID(1))
EndIf

SetMenuItemState(0, 1, 1)
  Repeat

    Select WaitWindowEvent()
        
      Case #PB_Event_RightClick       ; rechte Maustaste wurde gedrückt =>
        DisplayPopupMenu(0, WindowID(0))  ; zeige jetzt das Popup-Menü an

      Case #PB_Event_CloseWindow
        Quit = 1

    EndSelect

  Until Quit = 1

EndIf

End



Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Fred
Administrator
Administrator
Posts: 18393
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB6.30B4 - MenuItemState not visible with images

Post by Fred »

We now use full Windows API menus instead of custom drawing one, and it's not supported by Windows, so we can't do anything here.
dige
Addict
Addict
Posts: 1424
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: PB6.30B4 - MenuItemState not visible with images

Post by dige »

PB 6.21
Image

PB 6.30
Image

Menuitem "Alle Dateien" is checked
"Daddy, I'll run faster, then it is not so far..."
dige
Addict
Addict
Posts: 1424
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: PB6.30B4 - MenuItemState not visible with images

Post by dige »

Workaround by ChatGPT: SetMenuItemBitmap ()
@Fred: what do you think?

Code: Select all

EnableExplicit

Enumeration
  #Win
  #Canvas
EndEnumeration

Enumeration
  #Pop
EndEnumeration

Enumeration 1000
  #MI_Toggle
EndEnumeration

; --- WinAPI: MENUITEMINFO (minimal, damit SetMenuItemInfo_() sauber klappt)
Structure MENUITEMINFO_PB Align #PB_Structure_AlignC
  cbSize.l
  fMask.l
  fType.l
  fState.l
  wID.i
  hSubMenu.i
  hbmpChecked.i
  hbmpUnchecked.i
  dwItemData.i
  dwTypeData.i
  cch.l
  hbmpItem.i
EndStructure

#MIIM_BITMAP = $00000080

Procedure SetMenuItemBitmap(Menu, ItemID, hBitmap.i)
  Protected mii.MENUITEMINFO_PB
  mii\cbSize   = SizeOf(MENUITEMINFO_PB)
  mii\fMask    = #MIIM_BITMAP
  mii\hbmpItem = hBitmap
  SetMenuItemInfo_(MenuID(Menu), ItemID, #False, @mii) ; by command (ID), nicht by position
EndProcedure

Procedure.i MakeCheckedIcon(SrcImg, DstImg = #PB_Any)
  Protected out = CopyImage(SrcImg, DstImg)

  If StartDrawing(ImageOutput(out))
    DrawingMode(#PB_2DDrawing_AlphaBlend)

    ; kleines “Badge” links oben (optional, hilft Kontrast)
    Box(0, 0, 8, 8, RGBA(0, 0, 0, 110))

    ; Häkchen (2px “dick” durch doppelte Linien)
    Protected c = RGBA(255, 255, 255, 235)
    LineXY(1, 4, 3, 6, c) : LineXY(1, 5, 3, 7, c)
    LineXY(3, 6, 7, 2, c) : LineXY(3, 7, 7, 3, c)

    StopDrawing()
  EndIf

  ProcedureReturn out
EndProcedure

; --- Demo-Icons (16x16)
Procedure.i MakeBaseIcon(Color.l, Img = #PB_Any)
  Protected out = CreateImage(Img, 16, 16, 32, RGBA(0,0,0,0))
  If StartDrawing(ImageOutput(out))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(0,0,16,16, RGBA(0,0,0,0))
    Box(1,1,14,14, Color)
    StopDrawing()
  EndIf
  ProcedureReturn out
EndProcedure

; ---------------- Main ----------------
If OpenWindow(#Win, 0, 0, 360, 220, "PopupImageMenu – Checked Workaround", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(#Canvas, 0, 0, WindowWidth(#Win), WindowHeight(#Win))
  If StartDrawing(CanvasOutput(#Canvas))
    DrawText(12, 12, "Rechtsklick hier -> Popup-Menü. Item toggelt + Icon zeigt Häkchen.", RGB(30,30,30))
    StopDrawing()
  EndIf

  ; Images: normal + checked (mit Overlay)
  Define imgNormal = MakeBaseIcon(RGBA(0,120,215,255))
  Define imgChecked = MakeCheckedIcon(imgNormal)

  ; Popup-Menu
  CreatePopupImageMenu(#Pop)
  MenuItem(#MI_Toggle, "Option (sichtbar checked)", ImageID(imgNormal))

  ; initial checked
  SetMenuItemState(#Pop, #MI_Toggle, 1)
  SetMenuItemBitmap(#Pop, #MI_Toggle, ImageID(imgChecked))

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventGadget() = #Canvas And EventType() = #PB_EventType_RightClick
          DisplayPopupMenu(#Pop, WindowID(#Win))
        EndIf

      Case #PB_Event_Menu
        Select EventMenu()
          Case #MI_Toggle
            Define newState = Bool(GetMenuItemState(#Pop, #MI_Toggle) = 0)
            SetMenuItemState(#Pop, #MI_Toggle, newState)

            If newState
              SetMenuItemBitmap(#Pop, #MI_Toggle, ImageID(imgChecked))
            Else
              SetMenuItemBitmap(#Pop, #MI_Toggle, ImageID(imgNormal))
            EndIf
        EndSelect

      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf

"Daddy, I'll run faster, then it is not so far..."
BarryG
Addict
Addict
Posts: 4269
Joined: Thu Apr 18, 2019 8:17 am

Re: PB6.30B4 - MenuItemState not visible with images

Post by BarryG »

See this bug report too (it's relevant): viewtopic.php?p=648796#p648796
Fred
Administrator
Administrator
Posts: 18393
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB6.30B4 - MenuItemState not visible with images

Post by Fred »

You can do it by yourself by putting a checkbox on the birmap, but we won't mess with hack anymore for this kind of issues (standard Windows apps don't add a check over an icon, it just use the checkbox).
Post Reply