SetMenu的简单示例

 

'Code By 魑魅魍魉

'mailto:DemonStudio@hotmail.com

 

Private Declare Function SetMenu Lib "user32" _

(ByVal hwnd As Long, _

ByVal hMenu As Long) _

As Long

 

Private Declare Function GetMenu Lib "user32" _

(ByVal hwnd As Long) _

As Long

 

Private Declare Function DrawMenuBar Lib "user32" _

(ByVal hwnd As Long) _

As Long

 

Private Declare Function DestroyMenu Lib "user32" _

(ByVal hMenu As Long) _

As Long

 

Private Declare Function GetCursorPos Lib "user32" _

(lpPoint As POINTAPI) _

As Long

Private Declare Function WindowFromPoint Lib "user32" _

(ByVal xPoint As Long, _

ByVal yPoint As Long) _

As Long

 

Private Type POINTAPI

        x As Long

        y As Long

End Type

 

Dim hMenu, mHwnd As Long

Dim Cur As POINTAPI

 

 

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

GetCursorPos Cur

mHwnd = WindowFromPoint(Cur.x, Cur.y)

Me.Caption = mHwnd

If mHwnd <> Me.hwnd Then hMenu = GetMenu(mHwnd)

If hMenu <> 0 Then SetMenu Me.hwnd, hMenu

DrawMenuBar Me.hwnd

End Sub

 

 

 

Private Sub Form_Unload(Cancel As Integer)

DestroyMenu hMenu

End Sub

 

效果如下:

以下是一个简单的JavaFX二级菜单示例: ```java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class TwoLevelMenuExample extends Application { @Override public void start(Stage primaryStage) throws Exception { BorderPane root = new BorderPane(); MenuBar menuBar = new MenuBar(); Menu fileMenu = new Menu("File"); MenuItem openFile = new MenuItem("Open File"); MenuItem saveFile = new MenuItem("Save File"); fileMenu.getItems().addAll(openFile, saveFile); Menu editMenu = new Menu("Edit"); MenuItem cut = new MenuItem("Cut"); MenuItem copy = new MenuItem("Copy"); MenuItem paste = new MenuItem("Paste"); editMenu.getItems().addAll(cut, copy, paste); MenuBar subMenu = new MenuBar(); Menu optionsMenu = new Menu("Options"); MenuItem settings = new MenuItem("Settings"); optionsMenu.getItems().add(settings); subMenu.getMenus().add(optionsMenu); menuBar.getMenus().addAll(fileMenu, editMenu, subMenu); root.setTop(menuBar); Scene scene = new Scene(root, 400, 300); primaryStage.setTitle("Two Level Menu Example"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` 该示例创建了一个包含文件和编辑两个主菜单以及一个选项子菜单的菜单栏。选项子菜单包含一个设置菜单项。当用户单击菜单项时,可以显示相应的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值