資源描述:
《一個浮動窗口和窗口按鈕切換的參考代碼》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在學術論文-天天文庫。
1、參考代碼Module1.Bas模塊代碼如下:OptionExplicitDeclareFunctionGetMenuLib"user32"(ByValhwndAsLong)AsLongDeclareFunctionGetSubMenuLib"user32"(ByValhMenuAsLong,ByValnPosAsLong)AsLongDeclareFunctionGetMenuItemIDLib"user32"(ByValhMenuAsLong,ByValnPosAsLong)AsLongDeclareFunctionModifyMenuLib"user32"Alias"Modify
2、MenuA"(ByValhMenuAsLong,ByValnPositionAsLong,ByValwFlagsAsLong,ByValwIDNewItemAsLong,ByVallpStringAsAny)AsLongDeclareFunctionCreateCompatibleDCLib"gdi32"(ByValhdcAsLong)AsLongDeclareFunctionDeleteDCLib"gdi32"(ByValhdcAsLong)AsLongDeclareFunctionCreateCompatibleBitmapLib"gdi32"(ByValhdcAsLong,By
3、ValnWidthAsLong,ByValnHeightAsLong)AsLong’創(chuàng)建一幅與設備有關位圖,它與指定的設備場景兼容DeclareFunctionSelectObjectLib"gdi32"(ByValhdcAsLong,ByValhObjectAsLong)AsLong’得到以前選入設備場景的句柄DeclareFunctionBitBltLib"gdi32"(ByValhDestDCAsLong,ByValxAsLong,ByValyAsLong,ByValnWidthAsLong,ByValnHeightAsLong,ByValhSrcDCAsLong,ByValx
4、SrcAsLong,ByValySrcAsLong,ByValdwRopAsLong)AsLongPublicConstSRCCOPY=&HCC0020PublicConstMF_BYPOSITION=&H400&PublicConstMF_BITMAP=&H4&Form1程序代碼如下:PrivateSubForm_Load()DimnLoopCtrAsIntegerDimlResultAsLongDimhTempDCAsLongDimnWidthAsIntegerDimnHeightAsIntegerDimlTempIDAsLongDimhMenuIDAsLon
5、gDimlItemCountAsLongDimhBitmapAsLongnLoopCtr=0nWidth=Picture1(nLoopCtr).WidthScreen.TwipsPerPixelXnHeight=Picture1(nLoopCtr).HeightScreen.TwipsPerPixelYhMenuID=GetSubMenu(GetMenu((Me.hwnd)),0)'獲取菜單的位置hTempDC=CreateCompatibleDC(Picture1(nLoopCtr).hdc)FornLoopCtr=0To3'這個循環(huán)把圖片放入菜單里hBitmap=Cre
6、ateCompatibleBitmap(Picture1(nLoopCtr).hdc,nWidth,nHeight)lTempID=SelectObject(hTempDC,hBitmap)lResult=BitBlt(hTempDC,0,0,nWidth,nHeight,(Picture1(nLoopCtr).hdc),0,0,SRCCOPY)lTempID=SelectObject(hTempDC,lTempID)MnuMain_Select(nLoopCtr).Caption=""lResult=ModifyMenu(hMenuID,nLoopCtr,MF_BYPOSITION
7、OrMF_BITMAP,GetMenuItemID(hMenuID,nLoopCtr),hBitmap)NextnLoopCtrlResult=DeleteDC(hTempDC)EndSubPrivateSubMnuMain_Select_Click(IndexAsInteger)'處理菜單選擇事件SelectCaseIndexCase0Label1.Caption="選中---打開"Case1Label1.Caption="選中---關于"C