MenuToolbar.Asm
上传用户:yoyoxiao
上传日期:2021-10-16
资源大小:31k
文件大小:9k
源码类别:

工具条

开发平台:

Asm

  1. .386
  2. .model flat,stdcall
  3. option casemap:none
  4. include MenuToolbar.inc
  5. .code
  6. start:
  7. invoke GetModuleHandle,NULL
  8. mov    hInstance,eax
  9. invoke GetCommandLine
  10. invoke InitCommonControls
  11. invoke LoadLibrary,OFFSET DllName
  12. mov hHookDll,eax
  13. invoke GetProcAddress,hHookDll,OFFSET szInstallHook
  14. mov pInstallHook,eax
  15. invoke BuildMenus
  16. invoke CreateFontIndirect,OFFSET CapFont
  17. mov hFont,eax
  18. invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
  19. push eax
  20. invoke FreeLibrary,hHookDll
  21. invoke DestroyMenu,hMenus[0]
  22. invoke DestroyMenu,hMenus[4]
  23. invoke DestroyMenu,hMenus[8]
  24. invoke DestroyMenu,hMenus[12]
  25. invoke DeleteObject,hBmp
  26. invoke DeleteObject,hBkGrnd
  27. invoke DeleteObject,hFont
  28. pop eax
  29. invoke ExitProcess,eax
  30. WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
  31. LOCAL wc:WNDCLASSEX
  32. LOCAL msg:MSG
  33. mov wc.cbSize,SIZEOF WNDCLASSEX
  34. mov wc.style,CS_HREDRAW or CS_VREDRAW
  35. mov wc.lpfnWndProc,OFFSET WndProc
  36. mov wc.cbClsExtra,NULL
  37. mov wc.cbWndExtra,DLGWINDOWEXTRA
  38. push hInst
  39. pop wc.hInstance
  40. mov wc.hbrBackground,COLOR_BTNFACE+1
  41. mov wc.lpszMenuName,NULL
  42. mov wc.lpszClassName,OFFSET ClassName
  43. invoke LoadIcon,NULL,IDI_APPLICATION
  44. mov wc.hIcon,eax
  45. mov wc.hIconSm,eax
  46. invoke LoadCursor,NULL,IDC_ARROW
  47. mov wc.hCursor,eax
  48. invoke RegisterClassEx,addr wc
  49. invoke CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL
  50. invoke ShowWindow,hWnd,SW_SHOWNORMAL
  51. invoke UpdateWindow,hWnd
  52. .while TRUE
  53. invoke GetMessage,addr msg,NULL,0,0
  54.   .BREAK .if !eax
  55. invoke TranslateMessage,addr msg
  56. invoke DispatchMessage,addr msg
  57. .endw
  58. mov eax,msg.wParam
  59. ret
  60. WinMain endp
  61. WndProc proc uses edi esi hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
  62. LOCAL hPopMenu :DWORD
  63. LOCAL rct :RECT
  64. LOCAL pt :POINT
  65. LOCAL tbb :TBBUTTON
  66. LOCAL pID :DWORD
  67. mov eax,uMsg
  68. .if eax==WM_INITDIALOG
  69. push hWin
  70. pop hWnd
  71. invoke GetDlgItem,hWnd,1001
  72. mov hToolBar,eax
  73. invoke CreateToolBar
  74. .elseif eax==WM_COMMAND
  75. .elseif eax==WM_CLOSE
  76. invoke DestroyWindow,hWin
  77. .elseif eax==WM_NOTIFY
  78. mov edx,lParam
  79. mov eax,[edx].NMHDR.code
  80. .IF eax == TBN_DROPDOWN
  81. mov edi,lParam
  82. mov eax,[edi].NMTOOLBAR.iItem
  83. invoke SendMessage,hToolBar,TB_COMMANDTOINDEX,eax,0
  84. mov ecx,eax
  85. invoke SendMessage,hToolBar,TB_GETITEMRECT,ecx,ADDR rct
  86. mov eax,rct.left
  87. mov pt.x,eax
  88. mov eax,rct.bottom
  89. mov pt.y,eax
  90. invoke ClientToScreen,hToolBar,ADDR pt
  91. mov eax,[edi].NMTOOLBAR.iItem
  92. dec eax
  93. mov eax,hMenus[eax*4]
  94. mov hPopMenu,eax
  95. .IF hHook
  96. invoke UnhookWindowsHookEx,hHook
  97. mov hHook,NULL
  98. .endif
  99. push hToolBar
  100. call pInstallHook
  101. mov hHook,eax
  102. invoke SendMessage,hToolBar,TB_PRESSBUTTON,[edi].NMTOOLBAR.iItem,TRUE
  103. invoke TrackPopupMenu,hPopMenu,TPM_LEFTALIGN or TPM_RETURNCMD,pt.x,pt.y,NULL,hToolBar,NULL
  104. .IF eax
  105. invoke SendMessage,hWnd,WM_COMMAND,eax,0
  106. .ENDIF
  107. invoke SendMessage,hToolBar,TB_PRESSBUTTON,[edi].NMTOOLBAR.iItem,FALSE
  108. invoke UnhookWindowsHookEx,hHook
  109. mov hHook,NULL
  110. .ELSEIF eax == TBN_HOTITEMCHANGE
  111. mov edi,lParam
  112. invoke SendMessage,hToolBar,TB_GETSTATE,[edi].NMTBHOTITEM.idNew,0
  113. .IF !(hHook) || !(eax & TBSTATE_ENABLED)
  114. invoke DefWindowProc,hWin,uMsg,wParam,lParam
  115. ret
  116. .endif
  117. mov eax,[edi].NMTBHOTITEM.idNew
  118. .IF eax && eax != CurrentBtn
  119. push eax
  120. invoke SendMessage,hToolBar,TB_PRESSBUTTON,CurrentBtn,FALSE
  121. pop eax
  122. mov CurrentBtn,eax
  123. mov nmtb.iItem,eax
  124. mov eax,hToolBar
  125. mov nmtb.hdr.hwndFrom,eax
  126. mov nmtb.hdr.code,TBN_DROPDOWN
  127. invoke SendMessage,hToolBar,WM_CANCELMODE,0,0
  128. invoke PostMessage,hWnd,WM_NOTIFY,0,ADDR nmtb
  129. .ELSE
  130. invoke DefWindowProc,hWin,uMsg,wParam,lParam
  131. ret
  132. .ENDIF
  133. .ELSEIF eax == TBN_QUERYINSERT
  134. mov eax,TRUE
  135. ret
  136. .ELSEIF eax == TBN_QUERYDELETE
  137. mov eax,TRUE
  138. ret
  139. .ELSEIF eax == TBN_GETBUTTONINFO
  140. mov edi,lParam
  141. mov eax,[edi].NMTOOLBAR.hdr.hwndFrom
  142. .IF eax == hToolBar
  143. mov esi,[edi].NMTOOLBAR.iItem
  144. add edi,NMTOOLBAR.tbButton
  145. .IF esi < nTbBtns
  146. mov eax,SIZEOF TBBUTTON
  147. mul esi
  148. add eax,OFFSET TbBtns
  149. invoke MemCopy,eax,edi,SIZEOF TBBUTTON
  150. mov eax,TRUE
  151. .ELSE
  152. mov eax,FALSE
  153. .ENDIF
  154. .ELSE
  155. mov eax,FALSE
  156. .ENDIF
  157. ret
  158. .ELSEIF eax == TBN_INITCUSTOMIZE
  159. mov eax,TBNRF_HIDEHELP
  160. ret
  161. .ENDIF
  162. .ELSEIF eax == WM_KEYDOWN
  163. invoke SendMessage,hToolBar,TB_BUTTONCOUNT,0,0
  164. dec eax
  165. mov edi,eax
  166. invoke SendMessage,hToolBar,TB_GETHOTITEM,0,0
  167. .IF wParam == VK_RIGHT && eax != -1
  168. .IF eax == edi
  169. mov eax,0
  170. .ELSE
  171. inc eax
  172. .endif
  173. invoke SendMessage,hToolBar,TB_SETHOTITEM,eax,0
  174. .ELSEIF wParam == VK_LEFT && eax != -1
  175. .IF eax == 0
  176. mov eax,edi
  177. .ELSE
  178. dec eax
  179. .endif
  180. invoke SendMessage,hToolBar,TB_SETHOTITEM,eax,0
  181. .ELSEIF wParam == VK_DOWN && eax != -1
  182. mov ecx,eax
  183. invoke SendMessage,hToolBar,TB_GETBUTTON,ecx,ADDR tbb
  184. mov eax,tbb.idCommand
  185. mov CurrentBtn,eax
  186. mov nmtb.iItem,eax
  187. mov eax,hToolBar
  188. mov nmtb.hdr.hwndFrom,eax
  189. mov nmtb.hdr.code,TBN_DROPDOWN
  190. invoke SendMessage,hToolBar,WM_CANCELMODE,0,0
  191. invoke PostMessage,hWnd,WM_NOTIFY,0,ADDR nmtb
  192. .endif
  193. .ELSEIF eax == WM_SYSKEYDOWN
  194. .IF wParam != VK_F10
  195. invoke SendMessage,hToolBar,TB_MAPACCELERATOR,wParam,ADDR pID
  196. .IF eax
  197. invoke SendMessage,hToolBar,TB_COMMANDTOINDEX,pID,0
  198. mov ecx,eax
  199. invoke SendMessage,hToolBar,TB_GETBUTTON,ecx,ADDR tbb
  200. mov eax,tbb.idCommand
  201. mov CurrentBtn,eax
  202. mov nmtb.iItem,eax
  203. mov eax,hToolBar
  204. mov nmtb.hdr.hwndFrom,eax
  205. mov nmtb.hdr.code,TBN_DROPDOWN
  206. invoke SendMessage,hToolBar,WM_CANCELMODE,0,0
  207. invoke PostMessage,hWnd,WM_NOTIFY,0,ADDR nmtb
  208. .ENDIF
  209. .ELSE
  210. invoke SendMessage,hToolBar,TB_SETHOTITEM,0,0
  211. .ENDIF
  212. .elseif eax==WM_DESTROY
  213. invoke PostQuitMessage,NULL
  214. .else
  215. invoke DefWindowProc,hWin,uMsg,wParam,lParam
  216. ret
  217. .endif
  218. xor    eax,eax
  219. ret
  220. WndProc endp
  221. CreateToolBar proc
  222. invoke GetWindowLong,hToolBar,GWL_WNDPROC
  223. invoke SetWindowLong,hToolBar,GWL_USERDATA,eax
  224. invoke SetWindowLong,hToolBar,GWL_WNDPROC,OFFSET SubClassTB
  225. invoke GetWindowLong,hToolBar,GWL_STYLE
  226. or eax,040h or CCS_ADJUSTABLE
  227. invoke SetWindowLong,hToolBar,GWL_STYLE,eax
  228. invoke ImageList_LoadImage,hInstance,5000,16,10,0FF00FFh,IMAGE_BITMAP,LR_CREATEDIBSECTION
  229. invoke SendMessage,hToolBar,TB_SETIMAGELIST,0,eax
  230. invoke ImageList_LoadImage,hInstance,5002,16,10,0FF00FFh,IMAGE_BITMAP,LR_CREATEDIBSECTION
  231. invoke SendMessage,hToolBar,TB_SETDISABLEDIMAGELIST,0,eax
  232. invoke SendMessage,hToolBar,TB_BUTTONSTRUCTSIZE,SIZEOF TBBUTTON,0
  233. invoke SendMessage,hToolBar,TB_ADDSTRING,NULL,OFFSET TbStrings
  234. invoke SendMessage,hToolBar,TB_ADDBUTTONS,nTbBtns,OFFSET TbBtns
  235. invoke SendMessage,hToolBar,TB_AUTOSIZE,0,0
  236. ret
  237. CreateToolBar endp
  238. BuildMenus proc
  239. LOCAL mi :MENUINFO
  240. invoke LoadImage,hInstance,5001,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION
  241. mov hBmp,eax
  242. invoke CreatePatternBrush,eax
  243. mov hBkGrnd,eax
  244. mov mi.hbrBack,eax
  245. mov mi.cbSize,SIZEOF MENUINFO
  246. mov mi.fmask,MIM_BACKGROUND
  247. invoke CreatePopupMenu
  248. mov hMenus[0],eax
  249. invoke AppendMenu,hMenus[0],MF_STRING,6001,OFFSET Mnu0Item0
  250. invoke AppendMenu,hMenus[0],MF_STRING,6002,OFFSET Mnu0Item1
  251. invoke AppendMenu,hMenus[0],MF_STRING,6003,OFFSET Mnu0Item2
  252. invoke SetMenuInfo,hMenus[0],ADDR mi
  253. invoke CreatePopupMenu
  254. mov hMenus[4],eax
  255. invoke AppendMenu,hMenus[4],MF_STRING,6101,OFFSET Mnu1Item0
  256. invoke AppendMenu,hMenus[4],MF_STRING,6102,OFFSET Mnu1Item1
  257. invoke AppendMenu,hMenus[4],MF_STRING,6103,OFFSET Mnu1Item2
  258. invoke AppendMenu,hMenus[4],MF_STRING,6104,OFFSET Mnu1Item3
  259. invoke AppendMenu,hMenus[4],MF_STRING,6105,OFFSET Mnu1Item4
  260. invoke AppendMenu,hMenus[4],MF_STRING,6106,OFFSET Mnu1Item5
  261. invoke SetMenuInfo,hMenus[4],ADDR mi
  262. invoke CreatePopupMenu
  263. mov hMenus[8],eax
  264. invoke AppendMenu,hMenus[8],MF_STRING,6201,OFFSET Mnu2Item0
  265. invoke AppendMenu,hMenus[8],MF_STRING,6202,OFFSET Mnu2Item1
  266. invoke AppendMenu,hMenus[8],MF_STRING,6203,OFFSET Mnu2Item2
  267. invoke AppendMenu,hMenus[8],MF_STRING,6204,OFFSET Mnu2Item3
  268. invoke SetMenuInfo,hMenus[8],ADDR mi
  269. invoke CreatePopupMenu
  270. mov hMenus[12],eax
  271. invoke AppendMenu,hMenus[12],MF_STRING,6301,OFFSET Mnu3Item0
  272. invoke AppendMenu,hMenus[12],MF_STRING,6302,OFFSET Mnu3Item1
  273. invoke SetMenuInfo,hMenus[12],ADDR mi
  274. ret
  275. BuildMenus endp
  276. SubClassTB proc uses edi esi hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
  277. LOCAL hdc :DWORD
  278. LOCAL rect :RECT
  279. .IF uMsg == WM_ERASEBKGND
  280. mov eax,wParam
  281. mov hdc,eax
  282. invoke GetClientRect,hWin,ADDR rect
  283. invoke FillRect,hdc,ADDR rect,hBkGrnd
  284. dec rect.bottom
  285. invoke CreatePen,PS_SOLID,1,0
  286. push eax
  287. invoke SelectObject,hdc,eax
  288. push eax
  289. invoke MoveToEx,hdc,rect.left,rect.bottom,NULL
  290. invoke LineTo,hdc,rect.right,rect.bottom
  291. pop eax
  292. invoke SelectObject,hdc,eax
  293. pop eax
  294. invoke DeleteObject,eax
  295. mov eax,0
  296. ret
  297. .endif
  298. invoke GetWindowLong,hWin,GWL_USERDATA
  299. invoke CallWindowProc,eax,hWin,uMsg,wParam,lParam
  300. ret
  301. SubClassTB endp
  302. ; ############################################
  303. end start