Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: контекстное меню Добавлено: 06.09.02 14:54  

Автор вопроса:  alexvba

Я начал писать программу на VB под MS Access и возникла проблема – когда я закрываю рабочую форму(FormAF), то Access пишет “Совершил недопустимую операцию” и закрывается совсем.

Дело в том, что я использую TreeView Control и заполняю дерево используя данные из таблицы. Я создаю динамически PopupMenu используя API, в ответ на событие нажатие правой кнопки мыши. До этого все идет нормально, но когда я отслеживаю сообщение посланное нажатым пунктом контекстного меню (PopupMenu) используя GetMessage или PeekMessage возникает выше указанная проблема, при том что приложение работает нормально и обработка сообщений идет нормально.

Скажите можно ли и как избавиться от проблемы.

Option Compare Database

Option Explicit

Private Type POINTAPI

x As Long

y As Long

End Type

Private Type msg

hwnd As Integer

message As Integer

wParam As Long

lParam As Long

time As Long

pt As POINTAPI

End Type

Private dbs As Database

Private tbl As TableDef

Private rst As Recordset

Const aSf = 7777

Private Declare Function CreatePopupMenu Lib "user32" () As Long

Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) 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 GetMessage Lib "User" (lpMsg As msg, ByVal hWnd As Integer, ByVal wMsgFilterMin As Integer, ByVal wMsgFilterMax As Integer) As Integer

Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long

Private Declare Function TranslateMessage Lib "user32" (lpMsg As msg) As Long

Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As msg) As Long

Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long

Private hMenu As Long

Private lpMsg As msg

---------------------

Private Sub Form_Close()

Set dbs = Nothing

‘DestroyMenu hMenu

End Sub

-------------------

Private Sub TreeView1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)

Dim a As Integer

Dim saret As String

Dim pt As POINTAPI

GetCursorPos pt

If Button = acRightButton Then

hMenu = CreatePopupMenu()

a = AppendMenu(hMenu, MF_STRING, aSf, "Hello13 !")

a = TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, Me.hwnd, ByVal 0&)

'a = TranslateMessage(lpMsg)

'a = DispatchMessage(lpMsg)

'a = GetMessage(lpMsg, Me.hwnd, 0, 0)

'GetMessage lpMsg, Me.hwnd, 0, 0

PeekMessage lpMsg, Me.hwnd, 0, 0, 0

Select Case lpMsg.lParam

Case aSf

saret = "FormTempora"

DoCmd.OpenForm saret

End Select

DestroyMenu hMenu

End If

End Sub

Ответить

  Ответы Всего ответов: 1  

Номер ответа: 1
Автор ответа:
 Nightmare



Вопросов: 0
Ответов: 11
 Профиль | | #1 Добавлено: 09.09.02 17:32

Можно же сделать проще. У формы есть метод PopupMenu.

Sub PopupMenu(Menu As object, [Flags], [X], [Y], [DefaultMenu])

Почему не использовать его?

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам