MenuToolbar.Asm
上传用户:yoyoxiao
上传日期:2021-10-16
资源大小:31k
文件大小:9k
- .386
- .model flat,stdcall
- option casemap:none
- include MenuToolbar.inc
- .code
- start:
- invoke GetModuleHandle,NULL
- mov hInstance,eax
- invoke GetCommandLine
- invoke InitCommonControls
- invoke LoadLibrary,OFFSET DllName
- mov hHookDll,eax
- invoke GetProcAddress,hHookDll,OFFSET szInstallHook
- mov pInstallHook,eax
- invoke BuildMenus
- invoke CreateFontIndirect,OFFSET CapFont
- mov hFont,eax
- invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
- push eax
- invoke FreeLibrary,hHookDll
- invoke DestroyMenu,hMenus[0]
- invoke DestroyMenu,hMenus[4]
- invoke DestroyMenu,hMenus[8]
- invoke DestroyMenu,hMenus[12]
- invoke DeleteObject,hBmp
- invoke DeleteObject,hBkGrnd
- invoke DeleteObject,hFont
- pop eax
- invoke ExitProcess,eax
- WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
- LOCAL wc:WNDCLASSEX
- LOCAL msg:MSG
- mov wc.cbSize,SIZEOF WNDCLASSEX
- mov wc.style,CS_HREDRAW or CS_VREDRAW
- mov wc.lpfnWndProc,OFFSET WndProc
- mov wc.cbClsExtra,NULL
- mov wc.cbWndExtra,DLGWINDOWEXTRA
- push hInst
- pop wc.hInstance
- mov wc.hbrBackground,COLOR_BTNFACE+1
- mov wc.lpszMenuName,NULL
- mov wc.lpszClassName,OFFSET ClassName
- invoke LoadIcon,NULL,IDI_APPLICATION
- mov wc.hIcon,eax
- mov wc.hIconSm,eax
- invoke LoadCursor,NULL,IDC_ARROW
- mov wc.hCursor,eax
- invoke RegisterClassEx,addr wc
- invoke CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL
-
-
- invoke ShowWindow,hWnd,SW_SHOWNORMAL
- invoke UpdateWindow,hWnd
- .while TRUE
- invoke GetMessage,addr msg,NULL,0,0
- .BREAK .if !eax
- invoke TranslateMessage,addr msg
- invoke DispatchMessage,addr msg
- .endw
-
- mov eax,msg.wParam
- ret
- WinMain endp
- WndProc proc uses edi esi hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
- LOCAL hPopMenu :DWORD
- LOCAL rct :RECT
- LOCAL pt :POINT
- LOCAL tbb :TBBUTTON
- LOCAL pID :DWORD
- mov eax,uMsg
- .if eax==WM_INITDIALOG
- push hWin
- pop hWnd
- invoke GetDlgItem,hWnd,1001
- mov hToolBar,eax
- invoke CreateToolBar
- .elseif eax==WM_COMMAND
- .elseif eax==WM_CLOSE
- invoke DestroyWindow,hWin
- .elseif eax==WM_NOTIFY
- mov edx,lParam
- mov eax,[edx].NMHDR.code
- .IF eax == TBN_DROPDOWN
- mov edi,lParam
- mov eax,[edi].NMTOOLBAR.iItem
- invoke SendMessage,hToolBar,TB_COMMANDTOINDEX,eax,0
- mov ecx,eax
- invoke SendMessage,hToolBar,TB_GETITEMRECT,ecx,ADDR rct
- mov eax,rct.left
- mov pt.x,eax
- mov eax,rct.bottom
- mov pt.y,eax
- invoke ClientToScreen,hToolBar,ADDR pt
- mov eax,[edi].NMTOOLBAR.iItem
- dec eax
- mov eax,hMenus[eax*4]
- mov hPopMenu,eax
- .IF hHook
- invoke UnhookWindowsHookEx,hHook
- mov hHook,NULL
- .endif
- push hToolBar
- call pInstallHook
- mov hHook,eax
- invoke SendMessage,hToolBar,TB_PRESSBUTTON,[edi].NMTOOLBAR.iItem,TRUE
- invoke TrackPopupMenu,hPopMenu,TPM_LEFTALIGN or TPM_RETURNCMD,pt.x,pt.y,NULL,hToolBar,NULL
- .IF eax
- invoke SendMessage,hWnd,WM_COMMAND,eax,0
- .ENDIF
- invoke SendMessage,hToolBar,TB_PRESSBUTTON,[edi].NMTOOLBAR.iItem,FALSE
- invoke UnhookWindowsHookEx,hHook
- mov hHook,NULL
- .ELSEIF eax == TBN_HOTITEMCHANGE
- mov edi,lParam
- invoke SendMessage,hToolBar,TB_GETSTATE,[edi].NMTBHOTITEM.idNew,0
- .IF !(hHook) || !(eax & TBSTATE_ENABLED)
- invoke DefWindowProc,hWin,uMsg,wParam,lParam
- ret
- .endif
- mov eax,[edi].NMTBHOTITEM.idNew
- .IF eax && eax != CurrentBtn
- push eax
- invoke SendMessage,hToolBar,TB_PRESSBUTTON,CurrentBtn,FALSE
- pop eax
- mov CurrentBtn,eax
- mov nmtb.iItem,eax
- mov eax,hToolBar
- mov nmtb.hdr.hwndFrom,eax
- mov nmtb.hdr.code,TBN_DROPDOWN
- invoke SendMessage,hToolBar,WM_CANCELMODE,0,0
- invoke PostMessage,hWnd,WM_NOTIFY,0,ADDR nmtb
- .ELSE
- invoke DefWindowProc,hWin,uMsg,wParam,lParam
- ret
- .ENDIF
- .ELSEIF eax == TBN_QUERYINSERT
- mov eax,TRUE
- ret
- .ELSEIF eax == TBN_QUERYDELETE
- mov eax,TRUE
- ret
- .ELSEIF eax == TBN_GETBUTTONINFO
- mov edi,lParam
- mov eax,[edi].NMTOOLBAR.hdr.hwndFrom
- .IF eax == hToolBar
- mov esi,[edi].NMTOOLBAR.iItem
- add edi,NMTOOLBAR.tbButton
- .IF esi < nTbBtns
- mov eax,SIZEOF TBBUTTON
- mul esi
- add eax,OFFSET TbBtns
- invoke MemCopy,eax,edi,SIZEOF TBBUTTON
- mov eax,TRUE
- .ELSE
- mov eax,FALSE
- .ENDIF
- .ELSE
- mov eax,FALSE
- .ENDIF
- ret
- .ELSEIF eax == TBN_INITCUSTOMIZE
- mov eax,TBNRF_HIDEHELP
- ret
- .ENDIF
- .ELSEIF eax == WM_KEYDOWN
- invoke SendMessage,hToolBar,TB_BUTTONCOUNT,0,0
- dec eax
- mov edi,eax
- invoke SendMessage,hToolBar,TB_GETHOTITEM,0,0
- .IF wParam == VK_RIGHT && eax != -1
- .IF eax == edi
- mov eax,0
- .ELSE
- inc eax
- .endif
- invoke SendMessage,hToolBar,TB_SETHOTITEM,eax,0
- .ELSEIF wParam == VK_LEFT && eax != -1
- .IF eax == 0
- mov eax,edi
- .ELSE
- dec eax
- .endif
- invoke SendMessage,hToolBar,TB_SETHOTITEM,eax,0
- .ELSEIF wParam == VK_DOWN && eax != -1
- mov ecx,eax
- invoke SendMessage,hToolBar,TB_GETBUTTON,ecx,ADDR tbb
- mov eax,tbb.idCommand
- mov CurrentBtn,eax
- mov nmtb.iItem,eax
- mov eax,hToolBar
- mov nmtb.hdr.hwndFrom,eax
- mov nmtb.hdr.code,TBN_DROPDOWN
- invoke SendMessage,hToolBar,WM_CANCELMODE,0,0
- invoke PostMessage,hWnd,WM_NOTIFY,0,ADDR nmtb
- .endif
- .ELSEIF eax == WM_SYSKEYDOWN
- .IF wParam != VK_F10
- invoke SendMessage,hToolBar,TB_MAPACCELERATOR,wParam,ADDR pID
- .IF eax
- invoke SendMessage,hToolBar,TB_COMMANDTOINDEX,pID,0
- mov ecx,eax
- invoke SendMessage,hToolBar,TB_GETBUTTON,ecx,ADDR tbb
- mov eax,tbb.idCommand
- mov CurrentBtn,eax
- mov nmtb.iItem,eax
- mov eax,hToolBar
- mov nmtb.hdr.hwndFrom,eax
- mov nmtb.hdr.code,TBN_DROPDOWN
- invoke SendMessage,hToolBar,WM_CANCELMODE,0,0
- invoke PostMessage,hWnd,WM_NOTIFY,0,ADDR nmtb
- .ENDIF
- .ELSE
- invoke SendMessage,hToolBar,TB_SETHOTITEM,0,0
- .ENDIF
- .elseif eax==WM_DESTROY
- invoke PostQuitMessage,NULL
- .else
- invoke DefWindowProc,hWin,uMsg,wParam,lParam
- ret
- .endif
- xor eax,eax
- ret
- WndProc endp
- CreateToolBar proc
- invoke GetWindowLong,hToolBar,GWL_WNDPROC
- invoke SetWindowLong,hToolBar,GWL_USERDATA,eax
- invoke SetWindowLong,hToolBar,GWL_WNDPROC,OFFSET SubClassTB
- invoke GetWindowLong,hToolBar,GWL_STYLE
- or eax,040h or CCS_ADJUSTABLE
- invoke SetWindowLong,hToolBar,GWL_STYLE,eax
- invoke ImageList_LoadImage,hInstance,5000,16,10,0FF00FFh,IMAGE_BITMAP,LR_CREATEDIBSECTION
- invoke SendMessage,hToolBar,TB_SETIMAGELIST,0,eax
-
- invoke ImageList_LoadImage,hInstance,5002,16,10,0FF00FFh,IMAGE_BITMAP,LR_CREATEDIBSECTION
- invoke SendMessage,hToolBar,TB_SETDISABLEDIMAGELIST,0,eax
- invoke SendMessage,hToolBar,TB_BUTTONSTRUCTSIZE,SIZEOF TBBUTTON,0
- invoke SendMessage,hToolBar,TB_ADDSTRING,NULL,OFFSET TbStrings
- invoke SendMessage,hToolBar,TB_ADDBUTTONS,nTbBtns,OFFSET TbBtns
- invoke SendMessage,hToolBar,TB_AUTOSIZE,0,0
- ret
- CreateToolBar endp
- BuildMenus proc
- LOCAL mi :MENUINFO
- invoke LoadImage,hInstance,5001,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION
- mov hBmp,eax
- invoke CreatePatternBrush,eax
- mov hBkGrnd,eax
- mov mi.hbrBack,eax
- mov mi.cbSize,SIZEOF MENUINFO
- mov mi.fmask,MIM_BACKGROUND
- invoke CreatePopupMenu
- mov hMenus[0],eax
- invoke AppendMenu,hMenus[0],MF_STRING,6001,OFFSET Mnu0Item0
- invoke AppendMenu,hMenus[0],MF_STRING,6002,OFFSET Mnu0Item1
- invoke AppendMenu,hMenus[0],MF_STRING,6003,OFFSET Mnu0Item2
- invoke SetMenuInfo,hMenus[0],ADDR mi
- invoke CreatePopupMenu
- mov hMenus[4],eax
- invoke AppendMenu,hMenus[4],MF_STRING,6101,OFFSET Mnu1Item0
- invoke AppendMenu,hMenus[4],MF_STRING,6102,OFFSET Mnu1Item1
- invoke AppendMenu,hMenus[4],MF_STRING,6103,OFFSET Mnu1Item2
- invoke AppendMenu,hMenus[4],MF_STRING,6104,OFFSET Mnu1Item3
- invoke AppendMenu,hMenus[4],MF_STRING,6105,OFFSET Mnu1Item4
- invoke AppendMenu,hMenus[4],MF_STRING,6106,OFFSET Mnu1Item5
- invoke SetMenuInfo,hMenus[4],ADDR mi
-
- invoke CreatePopupMenu
- mov hMenus[8],eax
- invoke AppendMenu,hMenus[8],MF_STRING,6201,OFFSET Mnu2Item0
- invoke AppendMenu,hMenus[8],MF_STRING,6202,OFFSET Mnu2Item1
- invoke AppendMenu,hMenus[8],MF_STRING,6203,OFFSET Mnu2Item2
- invoke AppendMenu,hMenus[8],MF_STRING,6204,OFFSET Mnu2Item3
- invoke SetMenuInfo,hMenus[8],ADDR mi
-
- invoke CreatePopupMenu
- mov hMenus[12],eax
- invoke AppendMenu,hMenus[12],MF_STRING,6301,OFFSET Mnu3Item0
- invoke AppendMenu,hMenus[12],MF_STRING,6302,OFFSET Mnu3Item1
- invoke SetMenuInfo,hMenus[12],ADDR mi
- ret
- BuildMenus endp
- SubClassTB proc uses edi esi hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
- LOCAL hdc :DWORD
- LOCAL rect :RECT
- .IF uMsg == WM_ERASEBKGND
- mov eax,wParam
- mov hdc,eax
- invoke GetClientRect,hWin,ADDR rect
- invoke FillRect,hdc,ADDR rect,hBkGrnd
- dec rect.bottom
- invoke CreatePen,PS_SOLID,1,0
- push eax
- invoke SelectObject,hdc,eax
- push eax
- invoke MoveToEx,hdc,rect.left,rect.bottom,NULL
- invoke LineTo,hdc,rect.right,rect.bottom
- pop eax
- invoke SelectObject,hdc,eax
- pop eax
- invoke DeleteObject,eax
- mov eax,0
- ret
- .endif
- invoke GetWindowLong,hWin,GWL_USERDATA
- invoke CallWindowProc,eax,hWin,uMsg,wParam,lParam
- ret
- SubClassTB endp
- ; ############################################
- end start