You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
How can i create ContextMenu for a dialog menu item.
For example if i choose File -> Save and i press the right mouse
botton a context menu will appear.
In 98+/2000+ there is even a special message - WM_MENURBUTTONUP.
In 95/NT, I guess, should work following algorithm:
%WM_INITMENU - Set a flag "in menu"
%WM_EXITMENULOOP - Turn off "in menu"
%WM_MENUSELECT
If (HiWrd(wParam) And %MF_POPUP) = %MF_POPUP Then
Ignore
ElseIf (HiWrd(wParam) And %MF_SYSMENU) = %MF_SYSMENU Then
Ignore
Else
Remember menu id (LoWrd(wParam))
End If
%WM_RBUTTONUP
If "in menu" then ...
Semen
Thank you for your reply.This works fine when i right click on the
main menu title (eg. File Edit ...) but when i right click a sub item
in the pull down area (eg. File -> Save As) then nothing happens.
Thanks again for your time
Stavros
Stavros --
Following works fine on my PC under Win2000.
Code:
#Compile Exe
#Register None
#Dim All
#Include "Win32Api.Inc"
Function MainWndProc (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case %WM_CREATE
Local hMenu As Long, hPopup As Long
Menu New Bar To hMenu
Menu New Popup To hPopup
Menu Add String, hPopup, "&Load", 101, %MF_ENABLED
Menu Add String, hPopup, "&Save", 102, %MF_ENABLED
Menu Add String, hPopup, "-", 0, 0
Menu Add String, hPopup, "&Exit", 103, %MF_ENABLED
Menu Add Popup, hMenu, "&File", hPopup, %MF_ENABLED
Menu New Popup To hPopup
Menu Add String, hPopup, "&Undo", 111, %MF_ENABLED
Menu Add String, hPopup, "-", 0, 0
Menu Add String, hPopup, "&Cut", 112, %MF_ENABLED
Menu Add String, hPopup, "&Paste", 113, %MF_ENABLED
Menu Add Popup, hMenu, "&Edit", hPopup, %MF_ENABLED
SetMenu hWnd, hMenu
Case %WM_INITMENU
Static InMenu As Long, IdMenu As Long
InMenu = %True: IdMenu = 0
Case %WM_EXITMENULOOP
InMenu = %False
Case %WM_MENUSELECT
IdMenu = 0
If (HiWrd(wParam) And %MF_POPUP) = %MF_POPUP Then
ElseIf (HiWrd(wParam) And %MF_SYSMENU) = %MF_SYSMENU Then
Else
IdMenu = LoWrd(wParam)
End If
Case %WM_RBUTTONUP
If IdMenu Then MsgBox "Id =" + Str$(IdMenu)
Case %WM_DESTROY
PostQuitMessage 0
End Select
Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
End Function
'-------------------------------------------------------------------------------------------------
Function WinMain (ByVal hInstance As Long, ByVal hPrevInstance As Long, _
lpCmdLine As Asciiz Ptr, ByVal iCmdShow As Long) As Long
Local szClassName As Asciiz * 12
Local wc As WndClassEx
szClassName = "LtrXMainWnd"
wc.cbSize = Len(WndClassEx)
wc.style = %CS_HREDRAW Or %CS_VREDRAW
wc.lpfnWndProc = CodePtr(MainWndProc )
wc.hInstance = hInstance
wc.hCursor = LoadCursor(ByVal 0, ByVal %IDC_ARROW)
wc.hbrBackground = %COLOR_WINDOW + 1
wc.lpszClassName = VarPtr(szClassName)
RegisterClassEx wc
Local hWnd As Long
hWnd = CreateWindowEx (0, szClassName, " Ltr-eXpress", _
%WS_SYSMENU Or %WS_THICKFRAME Or %WS_CLIPCHILDREN, _
0, 0, 0, 0, %HWND_DESKTOP, 0, hInstance, ByVal 0)
ShowWindow hWnd, %SW_MAXIMIZE
UpdateWindow hWnd
Local Msg As tagMsg
While GetMessage(Msg, ByVal 0&, 0, 0)
TranslateMessage Msg
DispatchMessage Msg
Wend
End Function
Semen
Thanks again for your reply.Under Win98 second edition this
example doesn't work,the problem is that idMenu remains 0 (zero)
so the If IdMenu in the %WM_MENUSELECT is always false.
I took out the 'IF' just to check on the %WM_RBUTTONUP message and
i found out that i only get it when i press the right click over File or
Edit ,and not over their sub menu items.
A context menu is intended to be used in place of a normal menu, as
a shortcut for actions that make the most sense in context. Using a
context menu in a regular menu is not really appropriate unless,
perhaps, you wish to offer context options that modify the regular
menu itself.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment