• Welcome to Jose's Read Only Forum 2023.
 

How to reduce the size of the Context menu or TrackPopupMenu

Started by Paul Yuen, October 08, 2015, 09:43:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paul Yuen

Hi

Can someone show me how to reduce the width of the Context menu ?  I have attached a screen shot of the Context menu (activated by right mouse click) . 

As shown,  the menu is very wide -- much wider than the menuitems' strings.   There are lots of blank space between the last character of the menuitems' string and the menu border.   How to reduce this width ?  Thank you in advance.


'============================================
' The Call Back function for the Main Dialog
CALLBACK FUNCTION DlgProc() AS LONG
   LOCAL LpLvNm AS NM_LISTVIEW PTR
   LOCAL tempst AS STRING
   LOCAL OrigCol AS LONG
   LOCAL pLVDI AS LV_DISPINFO PTR, lplvcd AS NMLVCUSTOMDRAW PTR
   LOCAL colj , x, y AS LONG
   LOCAL pt AS POINT
   LOCAL st , Newst AS STRING
   LOCAL jrow , Crow AS LONG     



  SELECT CASE CB.MSG

  CASE %WM_INITDIALOG
           CreateContextMenus


  CASE %WM_NOTIFY
         SELECT CASE CB.NMID


          CASE %IDC_ListView   


             SELECT CASE CB.NMCODE 


                 CASE  %NM_RCLICK    ' Right click
                     LpLvNm = CB.LPARAM
                     CurrentRow = @LpLvNm.iiTem + 1
                     CurrentCol = @LpLvNm.iSubItem + 1

                   '  refer to
                   '  https://msdn.microsoft.com/en-us/library/windows/desktop/ms648390%28v=vs.85%29.aspx
                   '    https://msdn.microsoft.com/en-us/library/windows/desktop/ms648002%28v=vs.85%29.aspx
                    GetCursorPos(pt)       '  Retrieves the position of the mouse cursor, in screen coordinates.
                    TrackPopupMenu hContextLV, %TPM_LEFTALIGN,pt.x, pt.y, 0, hDlg, BYVAL 0   'put context menu where mouse is
                    FUNCTION = 0 : EXIT FUNCTION           




              END SELECT

         END SELECT     

END SELECT 




'=================================
' This routine creates  small menus when we
' right click on grid cell -- allowing users
' to  cut , paste and delete  cells values
'
' Note that the context menu hContextTB is invoke by the Right click
' when the cursor is inside a textbox       

SUB  CreateContextMenus
   LOCAL hFill, hRows, hCols, hFormat AS DWORD
     LOCAL mhBmpR AS LONG



  'ListView context menu   -- for  copy row, cut row and paste row and delete row
   MENU NEW POPUP TO hContextLV
   MENU ADD STRING, hContextLV, CHR$(67)+  CHR$(111)+  CHR$(112)+  CHR$(121)+  CHR$(32)+ _
    CHR$(82)+  CHR$(111)+  CHR$(119),   %IDM_gridCopyRw,  %MF_ENABLED
   MENU ADD STRING, hContextLV ,CHR$(67)+  CHR$(117)+  CHR$(116)+  CHR$(32)+  CHR$(82)+ _
    CHR$(111)+  CHR$(119),   %IDM_gridCutRw,  %MF_ENABLED
   MENU ADD STRING, hContextLV, CHR$(80)+  CHR$(97)+  CHR$(115)+  CHR$(116)+  CHR$(101)+ _
    CHR$(32)+  CHR$(82)+  CHR$(111)+  CHR$(119),  %IDM_gridPasteRw,  %MF_ENABLED
   MENU ADD STRING, hContextLV, CHR$(68)+  CHR$(101)+  CHR$(108)+  CHR$(101)+  CHR$(116)+ _
    CHR$(101)+  CHR$(32)+  CHR$(82)+  CHR$(111)+  CHR$(119),  %IDM_gridDelRw,  %MF_ENABLED

   MENU ADD STRING, hContextLV, "-", %IDM_gridSep, %MF_ENABLED
   MENU ADD STRING, hContextLV, "-", %IDM_gridSep, %MF_ENABLED

  '  paste the checked rows
       MENU ADD STRING, hContextLV,   CHR$(80)+  CHR$(97)+  CHR$(115)+  CHR$(116)+  CHR$(101)+ _
                   CHR$(32)+  CHR$(116)+  CHR$(104)+  CHR$(101)+  CHR$(32)+  _
                   CHR$(67)+  CHR$(104)+  CHR$(101)+  CHR$(99)+  CHR$(107)+  _
                  CHR$(101)+  CHR$(100)+  CHR$(32)+  CHR$(114)+  CHR$(111)+  CHR$(119)+  CHR$(115) _
                 ,%IDM_gridPaste5Rw,  %MF_ENABLED
       '  Delete the checked rows
       MENU ADD STRING, hContextLV, CHR$(68)+  CHR$(101)+  CHR$(108)+  CHR$(101)+  CHR$(116)+ _
              CHR$(101)+  CHR$(32)+  CHR$(116)+  CHR$(104)+  CHR$(101)+  _
              CHR$(32)+  CHR$(67)+  CHR$(104)+  CHR$(101)+  CHR$(99)+  _
              CHR$(107)+  CHR$(101)+  CHR$(100)+  CHR$(32)+  CHR$(114)+   _
              CHR$(111)+  CHR$(119)+  CHR$(115) _
              ,%IDM_gridDel5Rw,  %MF_ENABLED


   ' place in the images for the  Copy row , Cut row , Paste row and Delete row ListView context menu
     mhBmpR = LoadImage(GetModuleHandle(""), "#320", %Image_Bitmap, 0, 0, 0)
   SetMenuItemBitmaps hContextLV, 0 , %MF_ByPosition, mhBmpR, mhBmpR
      mhBmpR = LoadImage(GetModuleHandle(""), "#321", %Image_Bitmap, 0, 0, 0)
   SetMenuItemBitmaps hContextLV, 1 , %MF_ByPosition, mhBmpR, mhBmpR
      mhBmpR = LoadImage(GetModuleHandle(""), "#322", %Image_Bitmap, 0, 0, 0)
   SetMenuItemBitmaps hContextLV, 2 , %MF_ByPosition, mhBmpR, mhBmpR
    mhBmpR = LoadImage(GetModuleHandle(""), "#323", %Image_Bitmap, 0, 0, 0)
   SetMenuItemBitmaps hContextLV, 3 , %MF_ByPosition, mhBmpR, mhBmpR      ' Note that 3 is for 4th row
    mhBmpR = LoadImage(GetModuleHandle(""), "#326", %Image_Bitmap, 0, 0, 0)
   SetMenuItemBitmaps hContextLV, 6 , %MF_ByPosition, mhBmpR, mhBmpR
      mhBmpR = LoadImage(GetModuleHandle(""), "#327", %Image_Bitmap, 0, 0, 0)
   SetMenuItemBitmaps hContextLV, 7 , %MF_ByPosition, mhBmpR, mhBmpR


END SUB



José Roca

The only way is to make it owner draw and draw yourself the icons, text, etc. Not advisable because it is very complicated.


Pierre Bellisle

Hey Paul,

There is a nice example on PowerBASIC forum, see Bud Meyer pop-up menu.

Find @lpmis.itemWidth and divide it by 2 for the fun of it...

Pierre

Paul Yuen

Many Thanks  Pierre

Wow , what an awesome owner draw menu.  The author did lot's of work on this menu