📄 menudemo.asm
字号:
INVOKE CreatePopupMenu
mov hSMenu3, eax
mov mii.fType, MFT_STRING
push hSMenu3
pop mii.hSubMenu
mov eax, offset szNewMenu1
mov mii.dwTypeData, eax
INVOKE InsertMenuItem, hMenu, 2, TRUE, addr mii ; Adds new menu
INVOKE DrawMenuBar, hwnd
;---------- [Insert a Menu Item to the New Menu] ----------
.elseif eax == IDM_SET4
cmp Set4, 1
je Ret0
mov Set4, 1
mov mii.fType, MFT_STRING
mov mii.wID, 1020
mov mii.hSubMenu, 0
mov eax, offset szNewSubMenu1
mov mii.dwTypeData, eax
INVOKE InsertMenuItem, hSMenu3, 0, TRUE, addr mii ; Adds to the end
INVOKE DrawMenuBar, hwnd
;---------- [Insert a Seperator and Menu Item to the New Menu] ----------
.elseif eax == IDM_SET5
cmp Set5, 1
je Ret0
mov Set5, 1
INVOKE GetMenuItemCount, hSMenu3 ; Get count of items in the sub menu
mov edx, eax
mov mii.fType, MFT_SEPARATOR
mov mii.dwTypeData, eax
INVOKE InsertMenuItem, hSMenu3, edx, TRUE, addr mii ; Adds to the end
mov mii.fType, MFT_STRING
mov mii.wID, 1021
mov mii.hSubMenu, 0
mov eax, offset szNewSubMenu2
mov mii.dwTypeData, eax
INVOKE InsertMenuItem, hSMenu3, 99, TRUE, addr mii ; Adds to the end
INVOKE DrawMenuBar, hwnd
;---------- [Add Bitmaps to the Edit Menu (Ugly)] ----------
.elseif eax == IDM_SET6
cmp Set6, 1
je Ret0
mov Set6, 1
INVOKE SetMenuItemBitmaps, hSMenu2, IDM_CUT, MF_BYCOMMAND, hMBmp1, hMBmp1
INVOKE SetMenuItemBitmaps, hSMenu2, IDM_COPY, MF_BYCOMMAND, hMBmp2, hMBmp2
INVOKE SetMenuItemBitmaps, hSMenu2, IDM_PASTE, MF_BYCOMMAND, hMBmp3, hMBmp3
INVOKE SetMenuItemBitmaps, hSMenu2, IDM_DEL, MF_BYCOMMAND, hMBmp4, hMBmp4
;---------- [Insert a New Menu and Submenu to the Menu bar] ----------
.elseif eax == IDM_SET7
cmp Set7, 1
je Ret0
mov Set7, 1
INVOKE CreatePopupMenu
mov hSMenu4, eax
INVOKE GetMenuItemCount, hMenu ; Get count of items in the Menu bar
dec eax
mov edx, eax
mov mii.fType, MFT_STRING
mov mii.fState, MFS_ENABLED
push hSMenu4
pop mii.hSubMenu
mov mii.hbmpChecked, 0
mov mii.hbmpUnchecked, 0
mov eax, offset szNewMenu2
mov mii.dwTypeData, eax
INVOKE InsertMenuItem, hMenu, edx, TRUE, addr mii ; Adds new menu
mov mii.fType, MFT_STRING
push hSMenu5
pop mii.hSubMenu ; New Edit Submenu
mov eax, offset szEdit
mov mii.dwTypeData, eax
INVOKE InsertMenuItem, hSMenu4, 0, TRUE, addr mii ; Adds to the top
INVOKE DrawMenuBar, hwnd
;---------- [Change the new Submenu to OwnerDrawn] ----------
.elseif eax == IDM_SET8
cmp Set8, 1
je Ret0
mov Set8, 1
mov mii.fType, MFT_STRING
mov mii.fState, MFS_ENABLED
mov eax, offset szOwner
mov mii.dwTypeData, eax
INVOKE SetMenuItemInfo, hSMenu4, 0, TRUE, addr mii ; Adds to the top
mov mii.fType, MFT_OWNERDRAW
mov mii.fState, MFS_ENABLED
mov mii.hSubMenu, 0
mov mii.wID, 1005
mov mii.dwItemData, IDM_CUT
mov mii.dwTypeData, 0
INVOKE SetMenuItemInfo, hSMenu5, IDM_CUT, FALSE, addr mii
mov mii.wID, 1006
mov mii.dwItemData, IDM_COPY
INVOKE SetMenuItemInfo, hSMenu5, IDM_COPY, FALSE, addr mii
mov mii.wID, 1007
mov mii.dwItemData, IDM_PASTE
INVOKE SetMenuItemInfo, hSMenu5, IDM_PASTE, FALSE, addr mii
mov mii.wID, 1008
mov mii.dwItemData, IDM_DEL
INVOKE SetMenuItemInfo, hSMenu5, IDM_DEL, FALSE, addr mii
INVOKE DrawMenuBar, hwnd
;---------- [Gray or Enable Copy in the Edit Menu] ----------
.elseif eax == IDM_SET9
INVOKE GetMenuItemInfo, hSMenu2, IDM_COPY, FALSE, addr mii
.if mii.fState == MF_GRAYED
INVOKE EnableMenuItem, hMenu, IDM_COPY, MF_ENABLED
.else
INVOKE EnableMenuItem, hMenu, IDM_COPY, MF_GRAYED
.endif
;---------- [Gray or Enable Copy in the OwnerDrawn Edit Menu] ----------
.elseif eax == IDM_SET10
push mii.fMask
mov mii.fMask, MIIM_STATE
INVOKE GetMenuItemInfo, hSMenu5, IDM_COPY, FALSE, addr mii
.if mii.fState == MFS_GRAYED
mov mii.fState, MFS_ENABLED
.else
mov mii.fState, MFS_GRAYED
.endif
.if Set8
mov mii.fType, MFT_OWNERDRAW
.endif
INVOKE SetMenuItemInfo, hSMenu5, IDM_COPY, FALSE, addr mii
pop mii.fMask
;---------- Restore the Menu bar] ----------
.elseif eax == IDM_SET11
INVOKE DestroyMenu, hMenu
INVOKE LoadMenu, hInst, addr MenuName
mov hMenu, eax
INVOKE SetMenu, hWnd, hMenu
INVOKE GetSubMenu, hMenu, 0 ; Get handle to 1st sub menu
mov hSMenu1, eax
INVOKE GetSubMenu, hMenu, 1 ; Get handle to 2nd sub menu
mov hSMenu2, eax
INVOKE LoadMenu, hInst, 700
INVOKE GetSubMenu, eax, 0
mov hSMenu5, eax
xor eax, eax
.while (eax < 9)
and Set1[eax*4], 0
inc eax
.endw
.endif
.elseif wMsg == WM_MEASUREITEM
.if wParam == 0 ; 0 = Menu
mov edx, lParam ; Get pointer to MEASUREITEMSTRUCT
mov (MEASUREITEMSTRUCT ptr [edx]).itemWidth, 80
mov (MEASUREITEMSTRUCT ptr [edx]).itemHeight, 16
.endif
.elseif wMsg == WM_DRAWITEM
.if wParam == 0 ; 0 = Menu
mov esi, lParam
lea edi, dis
mov ecx, sizeof dis
rep movsb
.if dis.itemID != -1
mov dis.rcItem.left, 17
mov dis.rcItem.top, 0
mov dis.rcItem.right, 100
mov dis.rcItem.bottom, 16
mov eax, dis.itemData
sub eax, 1005
mov edx, hMBmp5[eax*4]
mov hMBmp, edx
.if dis.itemData == 1005
INVOKE lstrcpy, addr szBuff, addr szCut
.elseif dis.itemData == 1006
mov dis.rcItem.top, 16
mov dis.rcItem.bottom, 32
INVOKE lstrcpy, addr szBuff, addr szCopy
.elseif dis.itemData == 1007
mov dis.rcItem.top, 32
mov dis.rcItem.bottom, 48
INVOKE lstrcpy, addr szBuff, addr szPaste
.elseif dis.itemData == 1008
mov dis.rcItem.top, 48
mov dis.rcItem.bottom, 64
INVOKE lstrcpy, addr szBuff, addr szDelete
.endif
and Disable, 0
mov dwRob, SRCCOPY
.if dis.itemState == 2 || dis.itemState == 4 || dis.itemState == 6 || dis.itemState == 7
inc Disable
mov dwRob, SRCAND ;NOTSRCCOPY
.endif
INVOKE CreateCompatibleDC, dis.hdc ; Create a compatible dc in memory
mov hMemDC, eax
INVOKE SelectObject, hMemDC, hMBmp ; Select the opened bitmap into the dc
INVOKE BitBlt, dis.hdc, 0, dis.rcItem.top, 16, 16, hMemDC, 0, 0, dwRob ;Copy the bitmap
INVOKE DeleteDC, hMemDC ; Delete the memory dc
.if dis.itemState == ODS_SELECTED
INVOKE CreateSolidBrush, 00000000h
mov hBR, eax
INVOKE FillRect, dis.hdc, addr dis.rcItem, eax
INVOKE SetTextColor, dis.hdc, 00ffff00h
INVOKE SetBkColor, dis.hdc, 00000000h
mov rect.left, 0
push dis.rcItem.top
pop rect.top
mov rect.right, 16
push dis.rcItem.bottom
pop rect.bottom
INVOKE DrawEdge, dis.hdc, addr rect, BDR_RAISEDINNER, BF_TOPLEFT
INVOKE DrawEdge, dis.hdc, addr rect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT
.elseif Disable
INVOKE GetSysColor, COLOR_GRAYTEXT
INVOKE SetTextColor, dis.hdc, eax
INVOKE SetBkMode, dis.hdc, TRANSPARENT
.else
INVOKE GetBkColor, dis.hdc
INVOKE CreateSolidBrush, eax
mov hBR, eax
INVOKE FillRect, dis.hdc, addr dis.rcItem, eax
INVOKE SetTextColor, dis.hdc, 00ff0000h
INVOKE SetBkMode, dis.hdc, TRANSPARENT
.endif
add dis.rcItem.left, 4
INVOKE DrawText, dis.hdc, addr szBuff, -1, addr dis.rcItem, DT_LEFT or DT_VCENTER or DT_SINGLELINE
INVOKE DeleteObject, hBR
.endif
mov dis.itemState, ODS_DEFAULT
mov dis.hdc, 0
.endif
.elseif wMsg == WM_CLOSE
INVOKE DeleteObject, hMBmp1
INVOKE DeleteObject, hMBmp2
INVOKE DeleteObject, hMBmp3
INVOKE DeleteObject, hMBmp4
INVOKE DeleteObject, hMBmp5
INVOKE DeleteObject, hMBmp6
INVOKE DeleteObject, hMBmp7
INVOKE DeleteObject, hMBmp8
INVOKE DestroyWindow, hwnd
.elseif wMsg == WM_DESTROY
INVOKE PostQuitMessage, NULL
.else
DefWin:
INVOKE DefWindowProc, hwnd, wMsg, wParam, lParam
ret
.endif
Ret0:
xor eax, eax
ret
WndProc endp
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -