largo_winch
04-05-2011, 11:38
I need little help for context menu creation. see my example. the context menu doesn't place where mouse is standing. any help would be nice. bye, largo
Empty GUI script created on 05-03-2011 20:19:05 by largo_winch (ThinAIR)
Uses "UI", "console"
---Define a button ID %ButtonClose = 1001 %textboxy = 1002
Type POINTAPI x As Long y As Long End Type
Type CHARRANGE cpMin As Long cpMax As Long End Type
Dim hDlg As DWord
%IDM_UNDO = %WM_USER + 220 %IDM_CUT = %WM_USER + 222 %IDM_COPY = %WM_USER + 223 %IDM_PASTE = %WM_USER + 224 %IDM_DELETE = %WM_USER + 225 %IDM_SELALL = %WM_USER + 226
Global hEdit2 As Long
Declare Function TrackPopupMenu Lib "USER32.DLL" Alias "TrackPopupMenu" (ByVal hMenu As DWord, ByVal uFlags As DWord, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hWnd As DWord, lprc As RECT) As Long Declare Function ClientToScreen Lib "USER32.DLL" Alias "ClientToScreen" (ByVal hWnd As DWord, lpPoint As POINTAPI) As Long DECLARE FUNCTION CheckMenuItem LIB "USER32.DLL" ALIAS "CheckMenuItem" (BYVAL hMenu AS DWORD, BYVAL uIDCheckItem AS DWORD, BYVAL uCheck AS DWORD) AS DWORD Declare Function GetCursorPos Lib "USER32.DLL" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Dialog New 0, "context_menu, right_click!",-1,-1, 330, 214, _ %WS_POPUP Or _ %WS_VISIBLE Or _ %WS_CLIPCHILDREN Or _ %WS_CAPTION Or _ %WS_SYSMENU Or _ %WS_MINIMIZEBOX, _ 0 To hDlg
Control Add Button, hDlg, %ButtonClose, "Click to kill", 90, 50, 75, 50 Control Add Textbox, hDlg, %textboxy, " ",120,10,80,20
Dialog Show Modal hDlg Call cbDialog
------------------------------------------------ Callback function used to handle dialog events ------------------------------------------------ CallBack Function cbDialog() As Long Local cr As CHARRANGE, hMenuedit2 As DWord,pt As POINTAPI
Select Case CBMSG Case %WM_COMMAND If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
Case %WM_RBUTTONDOWN
Control_AppendText CBHNDL, %textboxy, "%NM_RCLICK " & $CRLF, %TRUE 'SendMessage hEdit2, %EM_EXGETSEL, 0, VarPtr(cr)
MENU New Popup To hMenuEdit2 MENU Add Popup, hEdit2, "test", hMenuEdit2, 4 MENU Add String, hMenuEdit2, "Cu&t" & $TAB & "Ctrl + X", %IDM_CUT, IIf$(cr.cpMin <> cr.cpMax, %MF_ENABLED, %MF_GRAYED) '_ '%MF_ENABLED ', _
MENU Add String, hMenuEdit2, "&Copy" & $TAB & "Ctrl + C", %IDM_COPY, _ IIf$(cr.cpMin <> cr.cpMax, %MF_ENABLED, %MF_GRAYED)' MENU Add String, hMenuEdit2, "&Paste" & $TAB & "Ctrl + V", %IDM_PASTE, _ IIf$(SendMessage(hEdit2, %EM_CANPASTE, 0, 0), %MF_ENABLED, %MF_GRAYED) Call CheckMenuItem(hMenuEdit2, %IDM_COPY, %MF_CHECKED) MENU Add String, hMenuEdit2, "&Delete" & $TAB & "Del", %IDM_DELETE, _ IIf$(cr.cpMin <> cr.cpMax, %MF_ENABLED, %MF_GRAYED) MENU Add String, hMenuEdit2, "-", 0, 0 MENU Add String, hMenuEdit2, "&Select all" & $TAB & "Ctrl + A", %IDM_SELALL, _ IIf$(SendMessage(hEdit2, %WM_GETTEXTLENGTH, 0, 0), %MF_ENABLED, %MF_GRAYED)
pt.x = LOWRD(CBLPARAM) pt.y = HIWRD(CBLPARAM)
MsgBox 0, "x-pos " + Str$(pt.x) & $TAB & " y-pos " + Str$(pt.y) 'ClientToScreen hEdit2, pt 'convert mouse position 'TrackPopupMenu hMenuEdit2, %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON, pt.x, pt.y, 0, hEdit2, ByVal %NULL Function = 0 MENU Attach hMenuEdit2, hDlg '?
Case %WM_DESTROY MsgBox 0, "Window is to be destroyed."
End Select
End Function
Empty GUI script created on 05-03-2011 20:19:05 by largo_winch (ThinAIR)
Uses "UI", "console"
---Define a button ID %ButtonClose = 1001 %textboxy = 1002
Type POINTAPI x As Long y As Long End Type
Type CHARRANGE cpMin As Long cpMax As Long End Type
Dim hDlg As DWord
%IDM_UNDO = %WM_USER + 220 %IDM_CUT = %WM_USER + 222 %IDM_COPY = %WM_USER + 223 %IDM_PASTE = %WM_USER + 224 %IDM_DELETE = %WM_USER + 225 %IDM_SELALL = %WM_USER + 226
Global hEdit2 As Long
Declare Function TrackPopupMenu Lib "USER32.DLL" Alias "TrackPopupMenu" (ByVal hMenu As DWord, ByVal uFlags As DWord, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hWnd As DWord, lprc As RECT) As Long Declare Function ClientToScreen Lib "USER32.DLL" Alias "ClientToScreen" (ByVal hWnd As DWord, lpPoint As POINTAPI) As Long DECLARE FUNCTION CheckMenuItem LIB "USER32.DLL" ALIAS "CheckMenuItem" (BYVAL hMenu AS DWORD, BYVAL uIDCheckItem AS DWORD, BYVAL uCheck AS DWORD) AS DWORD Declare Function GetCursorPos Lib "USER32.DLL" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Dialog New 0, "context_menu, right_click!",-1,-1, 330, 214, _ %WS_POPUP Or _ %WS_VISIBLE Or _ %WS_CLIPCHILDREN Or _ %WS_CAPTION Or _ %WS_SYSMENU Or _ %WS_MINIMIZEBOX, _ 0 To hDlg
Control Add Button, hDlg, %ButtonClose, "Click to kill", 90, 50, 75, 50 Control Add Textbox, hDlg, %textboxy, " ",120,10,80,20
Dialog Show Modal hDlg Call cbDialog
------------------------------------------------ Callback function used to handle dialog events ------------------------------------------------ CallBack Function cbDialog() As Long Local cr As CHARRANGE, hMenuedit2 As DWord,pt As POINTAPI
Select Case CBMSG Case %WM_COMMAND If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
Case %WM_RBUTTONDOWN
Control_AppendText CBHNDL, %textboxy, "%NM_RCLICK " & $CRLF, %TRUE 'SendMessage hEdit2, %EM_EXGETSEL, 0, VarPtr(cr)
MENU New Popup To hMenuEdit2 MENU Add Popup, hEdit2, "test", hMenuEdit2, 4 MENU Add String, hMenuEdit2, "Cu&t" & $TAB & "Ctrl + X", %IDM_CUT, IIf$(cr.cpMin <> cr.cpMax, %MF_ENABLED, %MF_GRAYED) '_ '%MF_ENABLED ', _
MENU Add String, hMenuEdit2, "&Copy" & $TAB & "Ctrl + C", %IDM_COPY, _ IIf$(cr.cpMin <> cr.cpMax, %MF_ENABLED, %MF_GRAYED)' MENU Add String, hMenuEdit2, "&Paste" & $TAB & "Ctrl + V", %IDM_PASTE, _ IIf$(SendMessage(hEdit2, %EM_CANPASTE, 0, 0), %MF_ENABLED, %MF_GRAYED) Call CheckMenuItem(hMenuEdit2, %IDM_COPY, %MF_CHECKED) MENU Add String, hMenuEdit2, "&Delete" & $TAB & "Del", %IDM_DELETE, _ IIf$(cr.cpMin <> cr.cpMax, %MF_ENABLED, %MF_GRAYED) MENU Add String, hMenuEdit2, "-", 0, 0 MENU Add String, hMenuEdit2, "&Select all" & $TAB & "Ctrl + A", %IDM_SELALL, _ IIf$(SendMessage(hEdit2, %WM_GETTEXTLENGTH, 0, 0), %MF_ENABLED, %MF_GRAYED)
pt.x = LOWRD(CBLPARAM) pt.y = HIWRD(CBLPARAM)
MsgBox 0, "x-pos " + Str$(pt.x) & $TAB & " y-pos " + Str$(pt.y) 'ClientToScreen hEdit2, pt 'convert mouse position 'TrackPopupMenu hMenuEdit2, %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON, pt.x, pt.y, 0, hEdit2, ByVal %NULL Function = 0 MENU Attach hMenuEdit2, hDlg '?
Case %WM_DESTROY MsgBox 0, "Window is to be destroyed."
End Select
End Function