⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 用Windows API控制菜单包括如何显示和隐藏菜单项
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   2040
   ClientLeft      =   3525
   ClientTop       =   4470
   ClientWidth     =   3030
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2040
   ScaleWidth      =   3030
   Begin VB.Menu mnuFile 
      Caption         =   "&File"
      Begin VB.Menu mnuFileExit 
         Caption         =   "E&xit"
      End
   End
   Begin VB.Menu mnuHelp 
      Caption         =   "&Help"
      Begin VB.Menu mnuHelpAbout 
         Caption         =   "&About..."
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

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 hMenu As Long
Private Sub HideMenu()
    If hMenu <> 0 Then Exit Sub
    
    ' Get the menu handle and hide the menu.
    hMenu = GetMenu(hwnd)
    SetMenu hwnd, 0
End Sub

Private Sub ShowMenu()
    If hMenu = 0 Then Exit Sub

    ' Restore the old menu.
    SetMenu hwnd, hMenu
    hMenu = 0
End Sub

Private Sub SwitchMenu()
    If hMenu = 0 Then
        HideMenu
    Else
        ShowMenu
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Y < 120 Then SwitchMenu
End Sub


Private Sub mnuFileExit_Click()
    Unload Me
End Sub


Private Sub mnuHelpAbout_Click()
    ' Hide the menu.
    HideMenu

    MsgBox "Show the About dialog here."
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -