资源描述:
《在用户窗体上添加菜单》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、技巧1在用户窗体上添加菜单在VBA中,用户窗体上是没有菜单的,为了使用方便,我们可以使用API函数在用户窗体上添加菜单,示例代码如下:#001PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong#002PrivateDeclareFunctionSetMenuLib"user32"(ByValhwndAsLong,ByValhMenuAs
2、Long)AsLong#003PrivateDeclareFunctionCreateMenuLib"user32"()AsLong#004PrivateDeclareFunctionAppendMenuLib"user32"Alias"AppendMenuA"(ByValhMenuAsLong,ByValwFlagsAsLong,ByValwIDNewItemAsLong,ByVallpNewItemAsAny)AsLong#005PrivateDeclareFunctionDestroyMenuLib"user32"
3、(ByValhMenuAsLong)AsLong#006PrivateDeclareFunctionCreatePopupMenuLib"user32"()AsLong#007PrivateDeclareFunctionSetWindowLongLib"user32"Alias"SetWindowLongA"(ByValhwndAsLong,ByValnIndexAsLong,ByValdwNewLongAsLong)AsLong#008PrivateDeclareFunctionGetWindowLongLib"use
4、r32"Alias"GetWindowLongA"(ByValhwndAsLong,ByValnIndexAsLong)AsLong#009PrivateConstGWL_WNDPROC=(-4)#010PrivateConstMF_STRING=&H0PrivateConstMF_POPUP=&H10PrivateConstMF_SEPARATOR=&H800
DimMenuWndAsLong,DumpAsLong,PopupMenuIDAsLong,PopupMenuWndAsLong,M
5、enuIDAsLong#014PrivateSubUserForm_Initialize()#015IfVal(Application.Version)<9Then#016hwnd=FindWindow("ThunderXFrame",Me.Caption)#017Else#018hwnd=FindWindow("ThunderDFrame",Me.Caption)#019EndIf#020MenuWnd=CreateMenu()#021PopupMenuID=CreatePopupMenu()#022Dump=Appe
6、ndMenu(MenuWnd,MF_STRING+MF_POPUP,PopupMenuID,"系统设置(&X)")#023Dump=AppendMenu(PopupMenuID,MF_STRING,100,"保存(&S)...")#024Dump=AppendMenu(PopupMenuID,MF_STRING,101,"备份(&E)")#025Dump=AppendMenu(PopupMenuID,MF_STRING,102,"退出(&X)")#026PopupMenuID=CreatePopupMenu()#027D
7、ump=AppendMenu(MenuWnd,MF_STRING+MF_POPUP,PopupMenuID,"会计凭证(&P)")#028Dump=AppendMenu(PopupMenuID,MF_STRING,110,"录入(&L)")#029Dump=AppendMenu(PopupMenuID,MF_STRING,111,"审核(&C)")#030PopupMenuID=CreatePopupMenu()#031Dump=AppendMenu(MenuWnd,MF_STRING+MF_POPUP,PopupMen
8、uID,"会计账簿(&Z)")#032Dump=AppendMenu(PopupMenuID,MF_STRING,112,"记账(&T)")#033Dump=AppendMenu(PopupMenuID,MF_STRING,113,"结账(&J)")#034PopupMenuID=CreatePopupMenu()#