Announcement

Collapse
No announcement yet.

Context Menu Font Size

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Context Menu Font Size

    As best I know, to change the font/fontsize of a context menu in an app, I'd have to change system level settings, which would apply to all running apps.

    I don't want to affect other apps, so creating a substitute - a custom popup dialog, with perhaps just a ListBox of option - would probably be the easiest approach

    Have anyone done it differently?

  • #2
    Yep, Semen did. :-)

    Comment


    • #3
      Semen's Context menu

      Click image for larger version  Name:	ContextMenu.png Views:	1 Size:	12.3 KB ID:	776925
      Last edited by Pierre Bellisle; 6 Dec 2018, 06:38 PM.

      Comment


      • #4
        Gary,
        OwnerDrawn is the way to go.

        Code:
        '_________________________________________________________________
        '
        ' SUB BuildPopupMenu                                          xBot
        '_________________________________________________________________
        
        SUB BuildPopupMenu(BYVAL hWndX AS DWORD)
          LOCAL MyItemName1      AS STRING
          LOCAL MyItemName2      AS STRING
          LOCAL MyItemName3      AS STRING
          LOCAL CurPos           AS POINT
          DIM   PopItem(1 TO 3)  AS STATIC PopMenuItemType
        
          CALL ClosePopupMenu
          CALL MyPumpMessages(10)
        
          giPopupMenuVisible = 1
          IF giView <> 0 THEN
              gsCmdMessages = "Popup menu is visible." + $CRLF + _
              gsCmdMessages
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
        
          MyItemName1 = "Move"
          MyItemName2 = "Minimize"
          MyItemName3 = "Close          Alt+F4"
        
          GetCursorPos(CurPos)
        
          'CaptionBar 3 and 5 have the Close [X] button highlighted
          'Based on some testing the default Windows behavior
          'is to not allow the popup menu when the Close button
          'is highlighted.
          'IF giCaptionBar = 3 OR giCaptionBar = 5 THEN EXIT SUB
        
          IF hPopup = 0 THEN
              hPopup = CreatePopupMenu
        
              PopItem(1).zItem    = MyItemName1
              PopItem(1).MenuType = "MOV"
              PopItem(1).ED = %MF_ENABLED
        
              PopItem(2).zItem    = MyItemName2
              PopItem(2).MenuType = "MIN"
              PopItem(2).ED = %MF_ENABLED
        
              PopItem(3).zItem    = MyItemName3
              PopItem(3).MenuType = "CLO"
              PopItem(3).ED = %MF_ENABLED
        
              InsertMenu(hPopup, 0, %MF_BYCOMMAND OR %MF_STRING, 1102, MyItemName1 + $NUL)
              InsertMenu(hPopup, 1, %MF_BYCOMMAND OR %MF_STRING, 1103, MyItemName2 + $NUL)
              InsertMenu(hPopup, 2, %MF_BYCOMMAND OR %MF_SEPARATOR, 1104, "-")
              InsertMenu(hPopup, 3, %MF_BYCOMMAND OR %MF_STRING, 1105, MyItemName3 + $NUL)
              'SetMenu(hWnd, hPopup)
        
              ModifyMenu(hPopup, 1102, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1102, BYVAL VARPTR(PopItem(1)))
              ModifyMenu(hPopup, 1103, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1103, BYVAL VARPTR(PopItem(2)))
              ModifyMenu(hPopup, 1105, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1105, BYVAL VARPTR(PopItem(3)))
        
          END IF
          IF giOnTitleBarIcon = 1 THEN
              CurPos.x = rcMainSub.nLeft
              CurPos.y = rcMainSub.nTop + 22
          END IF
        
          TrackPopupMenu(hPopup, %TPM_LEFTALIGN OR %TPM_RIGHTBUTTON, _
                         CurPos.x, CurPos.y, BYVAL 0, hWndX, BYVAL 0)
        
        END SUB
        Code:
        '_________________________________________________________________
        '
        ' SUB ClosePopupMenu                                          xBot
        '_________________________________________________________________
        
        SUB ClosePopupMenu
          IF IsMenu(hPopUp) THEN
              PostMessage(hPopup, %WM_CLOSE, 0, 0)  'send a message to popup menu to close it
              EnableWindow hWndMain, %TRUE
        
              IF giPopupMenuVisible = 1 THEN
                  giPopupMenuVisible = 0
                  giOnTitleBarIcon = 0
                  IF giView <> 0 THEN
                      gsCmdMessages = "Popup menu is not visible." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
              END IF
        
          END IF
        
        END SUB
        Code:
              CASE %WM_MEASUREITEM 'wParam is control identifier, lParam is item-size information
                  '- 9 in item length is important here to make the right menu edge appear correctly
                  'not inflated
                  hdc          = GetDC(hWnd)
                  pPopItemSize = lParam
                  pPopItem     = @pPopItemSize.itemData
                  GetTextExtentPoint32(hdc, @pPopItem.zItem, LEN(@pPopItem.zItem) - 9, @pPopItem.SizeA)
                  @pPopItemSize.itemWidth  = 4 + GetSystemMetrics(%SM_CYSMICON) + @pPopItem.sizeA.cx
                  @pPopItemSize.itemHeight = 3 + MAX(GetSystemMetrics(%SM_CYSMICON), @pPopItem.sizeA.cy)
                  ReleaseDC(hWnd, hdc)
                  FUNCTION = %TRUE
        
              CASE %WM_DRAWITEM 'wParam is control id, lParam is item-drawing info
                  pPopItemDrawInfo = lParam
                  pPopItem         = @pPopItemDrawInfo.itemData
                  IF (@pPopItemDrawInfo.itemState AND %ODS_SELECTED) THEN
                      SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHTTEXT))
                      SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHT))
                      hBrush = GetSysColorBrush(%COLOR_HIGHLIGHT)
                  ELSE 'Item is not selected
                      SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENUTEXT))
                      SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENU))
                      hBrush = GetSysColorBrush(%COLOR_MENU)
                  END IF
                  FillRect(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem, hBrush)
        
        
                  SELECT CASE @pPopItem.MenuType
                      CASE ""
                          'no icon for this item
        
                      CASE "MOV"
                          '<> move icon
                          SELECT CASE @pPopItem.ED
                              CASE %MF_ENABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM00, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                              CASE %MF_DISABLED
                                  'no disabled icon
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM01, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                          END SELECT
        
                      CASE "MIN"
                          '- minimize icon
                          SELECT CASE @pPopItem.ED
                              CASE %MF_ENABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM02, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                              CASE %MF_DISABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM03, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                          END SELECT
        
                      CASE "CLO"
                          'X close icon
                          SELECT CASE @pPopItem.ED
                              CASE %MF_ENABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM04, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                              CASE %MF_DISABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM05, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                          END SELECT
        
                  END SELECT
        
                  @pPopItemDrawInfo.rcItem.nLeft = 4 + @pPopItemDrawInfo.rcItem.nLeft + GetSystemMetrics(%SM_CXSMICON)
                  DrawText(@pPopItemDrawInfo.hDC, @pPopItem.zItem, LEN(@pPopItem.zItem), _
                           @pPopItemDrawInfo.rcItem, %DT_SINGLELINE)
        
                  FUNCTION = %TRUE
        Under WM_MEASUREITEM you can change the width and height of the text area.

        This is part of the main app to draw 3D buttons with 3D text.

        Code:
        '_________________________________________________________________
        '
        '   SUB  DrawItemCommand                                  xBot
        '_________________________________________________________________
        
        SUB DrawItemCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          LOCAL dis         AS DRAWITEMSTRUCT PTR
          LOCAL ColumnRect  AS RECT
          LOCAL PointXY     AS POINTAPI
          LOCAL ItemPosX    AS LONG
          LOCAL COLx        AS LONG
          LOCAL hFont_A     AS LONG
        
          giTheReturn = 0
        
          'IF wParamX = 0 THEN  ' if identifier is 0, message was sent by a menu
          '   DrawMenu lParamX  ' draw the menu
          '   giTheReturn = %TRUE : EXIT sub
          'END IF
        
          dis = lParamX
          'dis is Draw Item Structure
          'lParamX = Pointer to a DRAWITEMSTRUCT structure containing information about the item to be drawn and the type of drawing required.
        
          SELECT CASE @dis.CtlId
              CASE %IDC_Reset, _
                   %IDC_Show, _
                   %IDM_EXI10
                  GOSUB ProcessButton
        
        
          END SELECT
          giTheReturn = %TRUE
          GOTO AroundTheEnd
        
          ProcessButton:
            rc = @dis.rcItem
        
            LOCAL rcText AS RECT
            rcText.Top = rc.Top + 1
            rcText.Bottom = rc.Bottom + 1
            rcText.Left = rc.Left + 1
            rcText.Right = rc.Right + 1
        
            LOCAL rcTextX AS RECT
            rcTextX.Top = rc.Top + 2
            rcTextX.Bottom = rc.Bottom + 2
            rcTextX.Left = rc.Left + 2
            rcTextX.Right = rc.Right + 2
        
            IF (@dis.itemState AND %ODS_DISABLED) THEN
               DrawGradient(@dis.hDc)
               DrawEdge @dis.hDc, rc, %EDGE_RAISED    , %BF_RECT
            ELSE
                IF (@dis.itemState AND %ODS_SELECTED) THEN
                   DrawGradient(@dis.hDc)
                   DrawEdge @dis.hDc, rc, %EDGE_SUNKEN     , %BF_RECT
                   rc.nRight  = rc.nRight +1
                   rc.nbottom = rc.nBottom +1
                   rc.nLeft = rc.nLeft +1
                ELSE
                   DrawGradient(@dis.hDc)
                   DrawEdge @dis.hDc, rc, %EDGE_RAISED    , %BF_RECT
                END IF
            END IF
        
            SetBkMode @dis.hDc, %Transparent
            'SetTextColor @dis.hDc, RGB(200,255,0)
            SendMessage @dis.hWndItem, %WM_GETTEXT, SIZEOF(szText), BYVAL VARPTR(szText)
        
            'hFont_A = MakeFontEx("Arial", 12, %FW_BOLD , 0, 0)
            IF hFont_A THEN
               hFont_A = SelectObject(@dis.hDC, hFont_A)
            END IF
        
        
            IF (@dis.itemState AND %ODS_DISABLED) THEN
                SetTextColor @dis.hDc, RGB(100,120,120)      'disabled gray
                DrawText @dis.hDc, szText, LEN(szText), rc, %DT_CENTER OR %DT_VCENTER OR %DT_SINGLELINE
            ELSE
                SetTextColor @dis.hDc, RGB(100,120,120)         'light black    panelcolor
                DrawText @dis.hDc, szText, LEN(szText), rcTextX, %DT_CENTER OR %DT_VCENTER OR %DT_SINGLELINE 'or %DT_TOP 'OR %DT_VCENTER 'OR %DT_SINGLELINE
        
                SetTextColor @dis.hDc, RGB(0,0,0)
                DrawText @dis.hDc, szText, LEN(szText), rcText, %DT_CENTER OR %DT_VCENTER OR %DT_SINGLELINE 'or %DT_TOP 'OR %DT_VCENTER 'OR %DT_SINGLELINE
        
                SetTextColor @dis.hDc, RGB(0,255,255)  'blue text color
        
                DrawText @dis.hDc, szText, LEN(szText), rc, %DT_CENTER OR %DT_VCENTER OR %DT_SINGLELINE
            END IF
        
            IF hFont_A THEN
               DeleteObject SelectObject(@dis.hDC, hFont_A)
            END IF
            giTheReturn = %TRUE
          RETURN
        
          AroundTheEnd:
        END SUB
        You can set the hFont. The 2 different DrawItems can be put together to do what you need. The top DrawItem was designed to handle a Popup menu on a subclassed Titlebar. The second DrawItem was for drawing 3D buttons.

        Comment

        Working...
        X