凡是用過WINDOWS95或WINDOWS98的用戶,非常熟悉單擊鼠標右鍵會出現一個彈出式菜單,那麼如何在應用系統中也實現上述功能,增加用戶界面的友善性。筆者分別用VB和VFP實現了用鼠標右鍵實現彈出式菜單的效果。
控件NAME CAPTION INDEX
彈出式菜單窗體FORMENU 彈出式窗口實例1
菜單項MENUS 編輯
子菜單項MENUS1 窗口移動0
子菜單項MENUS1 窗口最小化1
子菜單項MENUS1 窗口最大化2
子菜單項MENUS1 - 3 &&分割線
子菜單項MENUS1 退出4
(2)程序清單:顯示效果如圖1所示。
圖1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const WM_SYSCOMMAND = &H112 Private Const SC_MOVE = &HF010& Private Const SC_MINIMIZE = &HF020& Private Const SC_MAXIMIZE = &HF030& > Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then Me.PopupMenu FORMENU!MENUS End If End Sub Private Sub MENUS1_Click(Index As Integer) Dim X As Long Select Case Index Case 0 X = SendMessage((FORMENU.hwnd), WM_SYSCOMMAND, SC_MOVE, 0&) Case 1 X = SendMessage((FORMENU.hwnd), WM_SYSCOMMAND, SC_MINIMIZE, 0&) Case 2 X = SendMessage((FORMENU.hwnd), WM_SYSCOMMAND, SC_MAXIMIZE, 0&) Case 3 Case 4 Unload FORMENU End Select End Sub
用VISUAL FOXPRO 6.0實現彈出式菜單。顯示效果如圖2所示。
圖2
控件NAME CAPTION
窗體FORM1 彈出式菜單實例2
命令按鈕COMMAND1 單擊鼠標右鍵演示彈出式菜單
(2)建立彈出式菜單MENUS.MPR:
菜單項窗口移動
菜單項窗口最小化
菜單項窗口最大化
DO MENUS.MPR &&調用彈出式菜單
運行環境:WINDOWS98,VISUAL BASIC 6.0、VISUAL FOXPRO 6.0 FOR WINDOWS.