
Type Class_Menu
Private : 
   sWndParent As hWnd
   m_IDC As Long
   Declare Function GetFP() As FormControlsPro_TYPE ptr '返回控件保存数据的指针（一般是类自己用）
   Declare FUNCTION AddIconToMenuItem(BYVAL nMenu AS .HMENU, BYVAL uItem AS ULong , BYVAL fByPosition AS BOOLEAN, BYVAL hIcon AS HICON, BYVAL fAutoDestroy AS BOOLEAN = TRUE, BYVAL phbmp AS HBITMAP PTR = NULL) AS BOOLEAN '将图标关联到菜单
   
Public : 
   Declare Constructor
   Declare Destructor
   Declare Property hMenu() As .hMenu           '返回/设置 菜单的主句柄，就是根级别的菜单句柄 ,创建新菜单 =CreatePopupMenu()
   Declare Property hMenu(hMenuNew As.hMenu)
   Declare Property hWndForm() As hWnd         '返回/设置控件所在的窗口句柄，主要用于多开窗口后，要使用控件前，必须先指定控件所在的窗口句柄，才能正常使用控件。
   Declare Property hWndForm(ByVal hWndParent As hWnd) '获取控件所在的窗口句柄
   Declare Property Text(idItem As Long) As CWSTR    '返回/设置菜单项的文本，字符个数最多50个，多余将会截断
   Declare Property Text(idItem As Long, sText As CWSTR)
   Declare Property Enabled(idItem As Long) As Boolean     '返回/设置菜单项是否允许操作。{=.True.False}
   Declare Property Enabled(idItem As Long, bValue As Boolean)
   Declare Property Check(idItem As Long) As Boolean     '返回/设置菜单项是否选中。{=.True.False}
   Declare Property Check(idItem As Long, bValue As Boolean)
   Declare Function PopupMenu(hWndParent As hWnd = 0, x as Long = 0, y as Long = 0) As Long  '在当前鼠标位置，弹出此菜单，hWndParent 是接收菜单事件的窗口。返回点击的菜单项标识符。
   Declare Function AddMenu(fidItem As Long, sText As CWSTR, idItem As Long, nBmp as String = "", nEnabled as Boolean = True, nCheck as Boolean = False, nDraw as Boolean = False, nKey As String = "") As Long '在fidItem 下增加1个菜单项，文本，fidItem=0 为根菜单，字符个数最多50个，多余将会截断，成功返回0，失败返回非0
   Declare Property IDC() As Long             '返回/设置控件IDC，控件标识符，1个窗口里每个控件IDC都是唯一的，包括控件数组。（不可随意修改，系统自动处理）
   Declare Property IDC(NewIDC As Long)
   Declare Function GetItemhMenu(idItem As Long) As .hMenu   '返回当前菜单项所属于的菜单句柄，由于菜单是树叉结构，子菜单有自己的句柄。失败方法0
   
End Type
'菜单为虚拟控件，数据保存在  fp->nData
Type Class_Menu_Data_s
   zMenu As .hMenu  '菜单句柄，此条菜单是属于那个菜单句柄的，方便使用
   nPos As Long  '位置，在菜单中的位置，从0开始，从上到下
   idItem As ULong '是菜单的 WID
   nEnabled As Byte '
   nCheck As Byte
   nDraw As Byte
   Bmph As HBITMAP '需要卸载时销毁
   BmpT As ZString *31 '在图像管理器中的名称 IMAGE_***  zString 格式，保存31个英文字符，超过截断
   nText As WString *51 '显示的文字，wString格式 最多50个字符，超过截断，英文 “-”为分割线
   nKey As ZString *16  '快捷键保存15个英文字符
End Type
Type Class_Menu_Data
   sMenu As .hMenu  'hMenu 菜单总句柄
   nu As Long    '菜单总个数
   dMenu(0) As Class_Menu_Data_s
End Type


'菜单API
'CreateMenu 创建一个菜单
'CreatePopupMenu 创建一个下拉菜单
'DeleteMenu  从指定菜单中删除项目
'RemoveMenu 删除菜单项或从指定菜单分离子菜单。
'DestroyMenu 销毁指定的菜单并释放该菜单占用的所有内存。
'GetMenu  检索分配给指定窗口的菜单的句柄。
'GetSubMenu   检索由指定菜单项激活的下拉菜单或子菜单的句柄。
'SetMenu   将新菜单分配给指定的窗口。
'AppendMenuA   将新项目追加到指定菜单栏，下拉菜单，子菜单或快捷菜单的末尾。
'InsertMenuItem 在菜单中的指定位置插入新菜单项。
'InsertMenu     将新菜单项插入菜单，将其他项下移菜单。
'ModifyMenu   更改现有菜单项。
'SetMenuItemBitmaps
'GetMenuBarInfo    检索有关指定菜单栏的信息。
'DrawMenuBar  重新绘制指定窗口的菜单栏
Constructor Class_Menu
   '注意：由于窗口类是永久的，全局变量，因此这里从开软件到关软件只执行1次。  
End Constructor

Destructor Class_Menu
   '注意：由于窗口类是永久的，全局变量，因此为了可以完成特殊功能，Destructor 会重复执行
   '1，每次窗口销毁  就执行1次 Destructor  ，多次显示和关窗口就重复操作
   '2，退出软件  执行1次 Destructor
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return 
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      DestroyMenu zz->sMenu
      if zz->nu = 0 Then Return 
      Dim i As Long
      For i = 0 To zz->nu  -1
         Dim hb As HBITMAP = zz->dMenu(i).Bmph
         if hb Then DeleteObject hb
      Next
      fp->nData=""
   end if
End Destructor
Property Class_Menu.hMenu() As .HMENU                    '句柄
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return 0
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      Return zz->sMenu
   End if
End Property
Property Class_Menu.hMenu(ByVal hWndNew As .HMENU)        '句柄
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then fp->nData =String(SizeOf(Class_Menu_Data),0) 
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      zz->sMenu =hWndNew
   End if
End Property
Property Class_Menu.hWndForm() As.hWnd         '用于多开窗口时，要使用控件前，必须先指定控件的父句柄
  Return sWndParent
End Property
Property Class_Menu.hWndForm(ByVal hWndParent As .hWnd)         '用于多开窗口时，要使用控件前，必须先指定控件的父句柄
'  hWndControl = GetMenu(hWndParent)
  sWndParent = hWndParent
End Property
Function Class_Menu.GetFP() As FormControlsPro_TYPE ptr '返回自己控件的指针
   Dim fp As FormControlsPro_TYPE ptr = GetPropW(sWndParent, "FCP_TYPE_PTR")
   While fp
      if fp->IDC = m_IDC Then Return fp      
      fp = fp->VrControls
   Wend

End Function
Property Class_Menu.IDC() As Long    '返回/设置控件IDC，控件标识符，
      Return m_IDC
End Property
Property Class_Menu.IDC(NewIDC As Long)
   m_IDC = NewIDC
End Property
Property Class_Menu.Text(idItem As Long) As CWSTR    '按ID方式:返回/设置菜单项的文本
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return ""
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      if zz->nu = 0 Then Return ""
      Dim i As Long
      For i = 0 To zz->nu  -1
         if zz->dMenu(i).idItem=idItem Then Return zz->dMenu(i).nText 
      Next
   End if 
   
End Property
Property Class_Menu.Text(idItem As Long, sText As CWSTR)
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr, StrPtr(fp->nData))
      if zz->nu = 0 Then Return
      Dim i As Long
      For i = 0 To zz->nu -1
         if zz->dMenu(i).idItem = idItem Then
            zz->dMenu(i).nText = sText
            Dim mType as MenuItemInfoW
            mType.cbSize = SizeOf(mType)
            mType.fMask = MIIM_STRING
            mType.dwTypeData = Cast(LPWSTR, sText.vptr)
            mType.cch = Len(sText)
            SetMenuItemInfoW zz->dMenu(i).zMenu, zz->dMenu(i).nPos, TRUE, VarPtr(mType)
            DrawMenuBar sWndParent
         End if
      Next
   End if
End Property

Property Class_Menu.Enabled(idItem As Long) As Boolean     '按ID方式:返回/设置菜单项是否允许操作。{=.True.False}
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return False
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      if zz->nu = 0 Then Return False
      Dim i As Long
      For i = 0 To zz->nu  -1
         if zz->dMenu(i).idItem=idItem Then Return zz->dMenu(i).nEnabled 
      Next
   End if 
End Property
Property Class_Menu.Enabled(idItem As Long, bValue As Boolean)
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr, StrPtr(fp->nData))
      if zz->nu = 0 Then Return
      Dim i As Long
      For i = 0 To zz->nu -1
         if zz->dMenu(i).idItem = idItem Then
            zz->dMenu(i).nEnabled = bValue
            Dim mType as MenuItemInfo
            mType.cbSize = SizeOf(mType)
            mType.fMask = MIIM_STATE
            mType.fState = IIf(bValue, MFS_ENABLED, MFS_DISABLED)
            'MFS_ENABLED, MFS_GRAYED, MFS_DISABLED, MFS_CHECKED, MFS_UNCHECKED
            'MFS_DEFAULT, MFS_HILITE, MFS_UNHILITE
            SetMenuItemInfo(zz->dMenu(i).zMenu, zz->dMenu(i).nPos, TRUE, VarPtr(mType))
            DrawMenuBar sWndParent
         End if
      Next
   End if
End Property

Property Class_Menu.Check(idItem As Long) As Boolean     '按ID方式:返回/设置菜单项是否选中。{=.True.False}
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return False
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      if zz->nu = 0 Then Return False
      Dim i As Long
      For i = 0 To zz->nu  -1
         if zz->dMenu(i).idItem=idItem Then Return zz->dMenu(i).nCheck 
      Next
   End if 
End Property
Property Class_Menu.Check(idItem As Long, bValue As Boolean)
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr, StrPtr(fp->nData))
      if zz->nu = 0 Then Return
      Dim i As Long
      For i = 0 To zz->nu -1
         if zz->dMenu(i).idItem = idItem Then
            zz->dMenu(i).nCheck = bValue
            Dim mType as MenuItemInfo
            mType.cbSize = SizeOf(mType)
            mType.fMask = MIIM_STATE
            mType.fState = IIf(bValue, MFS_CHECKED, MFS_UNCHECKED)
            'MFS_ENABLED, MFS_GRAYED, MFS_DISABLED, MFS_CHECKED, MFS_UNCHECKED
            'MFS_DEFAULT, MFS_HILITE, MFS_UNHILITE
            SetMenuItemInfo(zz->dMenu(i).zMenu, zz->dMenu(i).nPos, TRUE, VarPtr(mType))
            DrawMenuBar sWndParent
         End if
      Next
   End if
End Property
Function Class_Menu.PopupMenu(hWndParent As HWnd = 0, x as Long = 0, y as Long = 0) As Long      '在当前鼠标位置，弹出此菜单，hWndParent 是接收菜单事件的窗口。
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return 0
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr, StrPtr(fp->nData))
      if x = 0 and y = 0 then
         Dim P As Point
         GetCursorPos @p
         x = p.x
         y = p.y
      End if
      if hWndParent = 0 Then hWndParent = sWndParent
      Dim id As Long = TrackPopupMenu(zz->sMenu, TPM_RETURNCMD Or TPM_NONOTIFY, x, y, 0, hWndParent, Null) '比方说弹出菜单
      PostMessage(hWndParent, WM_Command, id, 0) '默认为 PostMessageW
      Function = id
   End if
End Function
Function Class_Menu.AddMenu(fidItem As Long, sText As CWSTR, idItem As Long, nBmp as String = "", nEnabled as Boolean = True, nCheck as Boolean = False, nDraw as Boolean = False, nKey As String = "") As Long
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return 0
      fp->nData &= String(SizeOf(Class_Menu_Data_s), 0)
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr, StrPtr(fp->nData))
      Dim zMenu As .hMenu
      Dim i As Long, u As Long
      if fidItem = 0 Then
         zMenu = zz->sMenu
      Else
         if zz->nu > 0 Then
            For i = 0 To zz->nu -1
               if zz->dMenu(i).idItem = fidItem Then
                  zMenu = GetSubMenu(zz->dMenu(i).zMenu, zz->dMenu(i).nPos)
                  if zMenu = 0 Then
                     zMenu = CreatePopupMenu
                     Dim uFlags As ULong = MF_BYPOSITION Or MF_POPUP
                     if zz->dMenu(i).nCheck Then uFlags Or= MF_CHECKED
                     if zz->dMenu(i).nEnabled Then uFlags Or= MF_ENABLED Else uFlags Or= MF_DISABLED
                     if zz->dMenu(i).nDraw Then uFlags Or= MF_OWNERDRAW
                     ModifyMenuW zz->dMenu(i).zMenu, zz->dMenu(i).nPos, uFlags, Cast(UINT_PTR, zMenu), zz->dMenu(i).nText
                     if zz->dMenu(i).Bmph Then SetMenuItemBitmaps(zMenu, zz->dMenu(i).nPos, MF_BYPOSITION, zz->dMenu(i).Bmph, null)
                  End if
                  Exit For
               End if
            Next
         End if
      End if
      if zz->nu > 0 Then
         For i = 0 To zz->nu -1
            if zz->dMenu(i).zMenu = zMenu Then u += 1
         Next
      End if
      i = zz->nu
      zz->nu += 1
      zz->dMenu(i).zMenu = zMenu
      zz->dMenu(i).nPos = u
      zz->dMenu(i).idItem = idItem
      zz->dMenu(i).nEnabled = nEnabled
      zz->dMenu(i).nCheck = nCheck
      zz->dMenu(i).nDraw = nDraw
      zz->dMenu(i).nText = sText
      zz->dMenu(i).nKey = nKey
      zz->dMenu(i).BmpT = nBmp
      Dim uFlags As ULong = MF_BYPOSITION
      if sText = "-" Then uFlags Or= MF_SEPARATOR Else uFlags Or= MF_STRING
      if zz->dMenu(i).nCheck Then uFlags Or= MF_CHECKED
      if zz->dMenu(i).nEnabled Then uFlags Or= MF_ENABLED Else uFlags Or= MF_DISABLED
      if zz->dMenu(i).nDraw Then uFlags Or= MF_OWNERDRAW
      if Len(nKey) Then
         Function = AppendMenuW(zMenu, uFlags, idItem, zz->dMenu(i).nText & WChr(9) & nKey)
      Else
         Function = AppendMenuW(zMenu, uFlags, idItem, zz->dMenu(i).nText)
      End if
      if len(nBmp) Then
         Dim nIcon AS HICON
         if Left(nBmp, 7) = "RCDATA_" Then
            nIcon = AfxGdipIconFromRes(App.hInstance, nBmp)
         Elseif Left(nBmp, 7) = "BITMAP_" Then
            zz->dMenu(i).Bmph = LoadImageA(app.hInstance, nBmp, IMAGE_BITMAP, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR)
            SetMenuItemBitmaps(zMenu, u, MF_BYPOSITION, zz->dMenu(i).Bmph, null)
         Elseif Left(nBmp, 5) = "ICON_" Then
            nIcon = LoadImageA(app.hInstance, nBmp, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR Or LR_VGACOLOR ) ' LoadIcon(app.hInstance, nBmp) '从资源里加载图标
         End if
         if nIcon Then AddIconToMenuItem(zMenu, u, True, nIcon, True, @zz->dMenu(i).Bmph)
      End if
      '获取快捷键
      if Len(nKey) Then
         DIM pWindow AS CWindow PTR = AfxCWindowPtr(sWndParent)
         if pWindow->AccelHandle Then
            u = CopyAcceleratorTableW(pWindow->AccelHandle, NULL, 0)
         Else
            u = 0
         End if
         ReDim cAccel(u) As ACCEL
         if u > 0 Then CopyAcceleratorTableW(pWindow->AccelHandle, @cAccel(0), u)
         Dim eKey As Long
         Dim fVirt As Long = FNOINVERT Or FVIRTKEY
         Dim uzz As String = UCase(nKey)
         Dim f As Long = InStr(uzz, "CTRL+")
         If f > 0 Then
            fVirt Or= FCONTROL
            uzz = Mid(uzz, f + 5)
         End If
         f = InStr(uzz, "SHIFT+")
         If f > 0 Then
            fVirt Or= FSHIFT
            uzz = Mid(uzz, f + 6)
         End If
         f = InStr(uzz, "ALT+")
         If f > 0 Then
            fVirt Or= FALT
            uzz = Mid(uzz, f + 4)
         End If
         Select Case uzz
            Case "F1" : eKey = VK_F1
            Case "F2" : eKey = VK_F2
            Case "F3" : eKey = VK_F3
            Case "F4" : eKey = VK_F4
            Case "F5" : eKey = VK_F5
            Case "F6" : eKey = VK_F6
            Case "F7" : eKey = VK_F7
            Case "F8" : eKey = VK_F8
            Case "F9" : eKey = VK_F9
            Case "F10" : eKey = VK_F10
            Case "F11" : eKey = VK_F11
            Case "F12" : eKey = VK_F12
            Case "0" : eKey = VK_0
            Case "1" : eKey = VK_1
            Case "2" : eKey = VK_2
            Case "3" : eKey = VK_3
            Case "4" : eKey = VK_4
            Case "5" : eKey = VK_5
            Case "6" : eKey = VK_6
            Case "7" : eKey = VK_7
            Case "8" : eKey = VK_8
            Case "9" : eKey = VK_9
            Case "A" : eKey = VK_A
            Case "B" : eKey = VK_B
            Case "C" : eKey = VK_C
            Case "D" : eKey = VK_D
            Case "E" : eKey = VK_E
            Case "F" : eKey = VK_F
            Case "G" : eKey = VK_G
            Case "H" : eKey = VK_H
            Case "I" : eKey = VK_I
            Case "J" : eKey = VK_J
            Case "K" : eKey = VK_K
            Case "L" : eKey = VK_L
            Case "M" : eKey = VK_M
            Case "N" : eKey = VK_N
            Case "O" : eKey = VK_O
            Case "P" : eKey = VK_P
            Case "Q" : eKey = VK_Q
            Case "R" : eKey = VK_R
            Case "S" : eKey = VK_S
            Case "T" : eKey = VK_T
            Case "U" : eKey = VK_U
            Case "V" : eKey = VK_V
            Case "W" : eKey = VK_W
            Case "X" : eKey = VK_X
            Case "Y" : eKey = VK_Y
            Case "Z" : eKey = VK_Z
         End Select
         If eKey > 0 Then
            cAccel(u).fVirt = fVirt
            cAccel(u).key = eKey
            cAccel(u).cmd = idItem
           if pWindow->AccelHandle Then DestroyAcceleratorTable pWindow->AccelHandle
            pWindow->AccelHandle = CreateAcceleratorTableW(@cAccel(0), u+1)
         End If
      End if
      DrawMenuBar sWndParent
   End if
End Function
Function Class_Menu.AddIconToMenuItem(BYVAL nMenu AS.HMENU, BYVAL uItem AS ULong, BYVAL fByPosition AS BOOLEAN, BYVAL hIcon AS HICON, BYVAL fAutoDestroy AS BOOLEAN = TRUE, BYVAL phbmp AS HBITMAP PTR = NULL) AS BOOLEAN
   '给菜单加图标，成功返回值为非零，失败，则返回值为零
   'nMenu  [in]处理包含菜单项目的菜单。
   'uItem    [in]获取信息的菜单项的标识符或位置。此参数的含义取决于fByPosition 的值。
   'fByPosition  [in]项目的含义.如果此参数为FALSE，则项目是一个菜单项标识符。否则，这是一个菜单项位置。
   'hIcon        [in]将图标的句柄添加到菜单中。
   'fAutoDestroy   [in]TRUE（默认值）或FALSE。如果为TRUE，AddIconToMenuItem在返回之前销毁图标。
   'phbmp          [out]图标转换为位图后的位图句柄，调用者负责销毁。如果是NULL，不输出句柄。
   
   IF nMenu = NULL OR hIcon = NULL THEN RETURN FALSE
   DIM hbmp AS HBITMAP, sizIcon AS SIZE, rcIcon AS RECT
   sizIcon.cx = GetSystemMetrics(SM_CXSMICON)
   sizIcon.cy = GetSystemMetrics(SM_CYSMICON)
   SetRect(@rcIcon, 0, 0, sizIcon.cx, sizIcon.cy)
   '创建内存DC =============
   DIM hdcDest AS HDC = CreateCompatibleDC(NULL)
   IF hdcDest = NULL THEN RETURN FALSE
   '创建32位位图  ====================
   DIM bmi AS BITMAPINFO
   bmi.bmiHeader.biSize = SIZEOF(BITMAPINFOHEADER)
   bmi.bmiHeader.biPlanes = 1
   bmi.bmiHeader.biCompression = BI_RGB
   bmi.bmiHeader.biWidth = sizIcon.cx
   bmi.bmiHeader.biHeight = sizIcon.cy
   bmi.bmiHeader.biBitCount = 24
   hbmp = CreateDIBSection(hdcDest, @bmi, DIB_RGB_COLORS, NULL, NULL, 0)
   'hbmp = CreateCompatibleBitmap(hdcDest, sizIcon.cx, sizIcon.cy)
   '把位图于DC关联 ===============
   DIM hbmpOld AS HBITMAP = CAST(HBITMAP, SelectObject(hdcDest, hbmp))
   Dim rc As Rect
   rc.bottom = 32 : rc.right = 32
   FillRect hdcDest, @rc, GetSysColorBrush(COLOR_MENU)
   IF hbmpOld THEN
      DrawIconEx(hdcDest, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL)
      'dim p as ICONINFO
      'GetIconInfo hIcon, @p
      'Dim bm As BITMAP
      'If GetObject(p.hbmColor, SizeOf(BITMAP), @bm) Then
      ''iw = bm.bmWidth '/ gg.m_DpiX
      ''ih = bm.bmHeight '/ gg.m_DpiY
      'End If
      ''      DrawState hdcDest, 0, 0, p.hbmMask, 0, 0, 0, sizIcon.cx, sizIcon.cy, DST_BITMAP
      'DrawState hdcDest, 0, 0, p.hbmColor, 0, 0, 0, sizIcon.cx, sizIcon.cy, DST_BITMAP
      'DeleteObject p.hbmColor
      'DeleteObject p.hbmMask
      SelectObject(hdcDest, hbmpOld)
   END IF
   DeleteDC(hdcDest)
   '把位图于菜单关联
   FUNCTION = SetMenuItemBitmaps(nMenu, uItem, IIf(fByPosition, MF_BYPOSITION, MF_BYCOMMAND), hbmp, null)
   IF fAutoDestroy THEN DestroyIcon(hIcon)
   IF phbmp THEN *phbmp = hbmp
   
END FUNCTION
Function Class_Menu.GetItemhMenu(idItem As Long) As .hMenu
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < SizeOf(Class_Menu_Data) Then Return 0
      Dim zz As Class_Menu_Data Ptr = Cast(Any Ptr, StrPtr(fp->nData))
      if zz->nu = 0 Then Return 0
      Dim i As Long
      For i = 0 To zz->nu -1
         if zz->dMenu(i).idItem = idItem Then
            Return zz->dMenu(i).zMenu 
         End if
      Next
   End if
End Function
