Announcement

Collapse
No announcement yet.

DDT Popup Menu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gregery D Engle
    replied
    Semen,

    You still seem to amaze me! Thanks, it works perfect.

    ------------------
    -Greg

    Leave a comment:


  • Semen Matusovski
    replied
    Greg --
    To make natural popup menu is not more difficult (at least, under Win2000, where following was written)

    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
    
       Type COPYDATASTRUCT
           dwData As Dword Ptr
           cbData As Dword
           lpData As Asciiz Ptr
       End Type
    
       Declare Function SetHookMouseWindow Lib "HookMs.Dll" _
          Alias "SetHookMouseWindow" (hWnd As Long) As Long
       Declare Function UnHookMouseWindow  Lib "HookMs.Dll" _
          Alias "UnHookMouseWindow" As Long
    
       CallBack Function DlgProc
          Static pt As PointApi, Msg As String
          Select Case CbMsg
             Case %WM_INITDIALOG: SetHookMouseWindow CbHndl
             Case %WM_ERASEBKGND: ShowWindow CbHndl, 0
             Case %WM_DESTROY   : UnHookMouseWindow
             Case %WM_USER + 1  : Msg = "": PostMessage CbHndl, %WM_CANCELMODE, 0, 0
             Case %WM_COPYDATA  : Local cdt As COPYDATASTRUCT Ptr
                                  cdt = CbLparam: Msg = Mid$(@[email protected], 9): GetCursorPos pt
                                  PostMessage CbHndl, %WM_CANCELMODE, 0, 0
                                  Function = 1: Exit Function
             Case %WM_CANCELMODE: PostMessage CbHndl, %WM_USER + 2, 0, 0
             Case %WM_USER + 2
                If Msg <> "" Then
                   Local hPopup As Long, rz As Long
                   Menu New Popup To hPopup
                   Menu Add String, hPopup, "Op-1 with " + Msg, 101, %MF_ENABLED
                   Menu Add String, hPopup, "Op-2 with " + Msg, 102, %MF_ENABLED
                   Menu Add String, hPopup, "Stop monitoring", %IDCANCEL, %MF_ENABLED         
                   rz = TrackPopupMenuEx (hPopup, %TPM_RETURNCMD Or %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON, pt.x, pt.y, CbHndl, ByVal 0)
                   DestroyMenu hPopup
                   If rz = %IDCANCEL Then PostMessage CbHndl, %WM_SYSCOMMAND, %SC_CLOSE, 0
                   ' Process other
                End If
          End Select
       End Function
       
       Function PbMain
          Local hDlg As Long
          Dialog New 0, "Icons", , , 150, 70, %WS_POPUP Or %WS_BORDER, %WS_EX_TOPMOST Or %WS_EX_TOOLWINDOW To hDlg
          Dialog Show Modal hDlg Call DlgProc
          MsgBox "Finish"
       End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Gregery D Engle
    replied
    Semen,

    My client is wanting to use a popupmenu, here is the modified code
    that you just posted that I'm having problems with:

    If you notice when you move over an icon, the popup menu pops up
    like it should but it seems as if it actually stops further
    messages to my program until someone selects something or
    clicks on the dialog (which will be invisible)

    Mainly I'm wanting to be able to destroy a popup menu at
    anytime but it seems that there is no way unless someone clicks
    on something.

    Any ideas?

    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    #INCLUDE "Win32Api.Inc"
    
    TYPE COPYDATASTRUCT
    dwData AS DWORD PTR
    cbData AS DWORD
    lpData AS ASCIIZ PTR
    END TYPE
    DECLARE FUNCTION SetHookMouseWindow LIB "HookMs.Dll" _
    ALIAS "SetHookMouseWindow" (hWnd AS LONG) AS LONG
    DECLARE FUNCTION UnHookMouseWindow LIB "HookMs.Dll" _
    ALIAS "UnHookMouseWindow" AS LONG
    %ID_Cmd1 = 301
    %ID_Cmd2 = 302
    %ID_Text = 201
    
    CALLBACK FUNCTION DlgProc
    STATIC ActClose AS LONG, ListId AS STRING, ListIdC AS STRING, pt AS PointApi, _
    cdt AS COPYDATASTRUCT PTR, hWnd AS LONG, hWnd1 AS LONG
    SELECT CASE CBMSG
    CASE %WM_INITDIALOG: SetHookMouseWindow CBHNDL: ActClose = -1
    CASE %WM_ERASEBKGND: IF ActClose = -1 THEN ShowWindow CBHNDL, 0: ActClose = 0
    CASE %WM_DESTROY : UnHookMouseWindow
    CASE %WM_USER + 1 : SetTimer CBHNDL, 1, 1000, BYVAL %Null: ActClose = %True
    CASE %WM_TIMER :
    'MSGBOX "yo"
    GetCursorPos pt
    hWnd = WindowFromPoint(pt.x, pt.y)
    DO
    hWnd1 = GetParent(hWnd): IF hWnd1 = 0 THEN EXIT DO
    hWnd = hWnd1
    LOOP
    IF hWnd <> CBHNDL THEN
    KillTimer CBHNDL, 1
    IF ActClose THEN ActClose = 0: GetCursorPos pt: _
    ShowWindow CBHNDL, 0: ListIdC = ""
    END IF
    CASE %WM_COPYDATA
    ActClose = 0
    cdt = CBLPARAM
    ListId = LEFT$(@[email protected], 8)
    IF ListIdC <> ListId THEN
    ListIdC = ListId
    CONTROL SET TEXT CBHNDL, %ID_Text, MID$(@[email protected], 9)
    GetCursorPos pt
    SetWindowPos CBHNDL, 0, pt.x + 20, pt.y + 10, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER OR _
    %SWP_NOACTIVATE OR %SWP_SHOWWINDOW
    '-----------------------
    LOCAL hPopup AS LONG
    MENU NEW POPUP TO hPopup
    MENU ADD STRING, hPopup, "Test1", 101, %MF_ENABLED
    MENU ADD STRING, hPopup, "Test2", 102, %MF_ENABLED
    MENU ADD STRING, hPopup, "Test3", 103, %MF_ENABLED
    MENU ADD STRING, hPopup, "Test4", 104, %MF_ENABLED
    TrackPopupMenu hPopup, %TPM_LEFTALIGN OR %TPM_RIGHTBUTTON, pt.x, pt.y, 0, CBHNDL, BYVAL 0
                                             
    END IF
    FUNCTION = 1: EXIT FUNCTION
    CASE %WM_COMMAND
    SELECT CASE CBCTL
    CASE %IDCANCEL: DIALOG END CBHNDL
    CASE %ID_CMD1: MSGBOX "Command1"
    CASE %ID_CMD2: MSGBOX "Command2"
    END SELECT
    END SELECT
    END FUNCTION
    
    FUNCTION PBMAIN
    'DIM pt AS PointApi
    'GetCursorPos pt
    LOCAL hDlg AS LONG
    DIALOG NEW 0, "Icons", , , 150, 70, %WS_POPUP OR %WS_BORDER OR %SW_HIDE, %WS_EX_TOPMOST OR %WS_EX_TOOLWINDOW TO hDlg
    'CONTROL ADD FRAME, hDlg, %ID_Text, "", 5, 0, 140, 65
    'CONTROL ADD BUTTON, hDlg, %ID_Cmd1, "Command1", 10, 15, 130, 15
    'CONTROL ADD BUTTON, hDlg, %ID_Cmd2, "Command2", 10, 30, 130, 15
    'CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Stop monitoring", 10, 45, 130, 15
    DIALOG SHOW MODAL hDlg CALL DlgProc
    
    
    MSGBOX "Finish"
    END FUNCTION
    ------------------
    -Greg

    Leave a comment:


  • Semen Matusovski
    replied
    Gregory --
    Something like this (written under Win2000, but hope that works in all OSes)

    Dll:
    Code:
       #Compile Dll "HookMs.Dll"
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       #Include "COMMCTRL.INC"
    
       Type COPYDATASTRUCT
        dwData As Dword Ptr
        cbData As Dword
        lpData As Dword
       End Type
    
       Global LastInfo As Long
    
       $HookFile = "C:\HookMs.Id"
       Global hInstDll As Long, TmpAsciiz As Asciiz * %MAX_PATH
       Global tRectExp As RECT, hWndLV As Long, hDlg As Long, hHook As Long
    
       Function LibMain(ByVal hInstance As Long, ByVal fwdReason As Long, _
          ByVal lpvReserved As Long) Export As Long
          Static hWnd As Long
          Select Case fwdReason
             Case %DLL_PROCESS_ATTACH: hInstDll = hInstance: LibMain = 1
             Case %DLL_PROCESS_DETACH: LibMain = 1
          End Select
       End Function
    
       Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) Export As Long
          Static id As Long, i As Long, hWnd As Long
          Static TmpAsciizC As Asciiz * %MAX_PATH
          Static pt As PointApi, ptc As pointApi, Cdt As COPYDATASTRUCT
    
          Function = CallNextHookEx(hHook, nCode, wParam, ByVal lParam)
    
          If nCode < 0 Then Exit Function
          If hDlg = 0 Then Open $HookFile For Input Shared As #1: _
             Input #1, hDlg, hWndLv: Close #1: ptc.x = -1000
          If IsWindow(hDlg) = %False Then FreeLibrary hInstDLL: Exit Function
          GetCursorPos pt: If pt.x = ptc.x And pt.y = ptc.y Then Exit Function
          ptc.x = pt.x: ptc.y = pt.y: hWnd = WindowFromPoint (pt.x,pt.y)
          If hWndLV = 0 Then Exit Function
          If hWnd <> hWndLV Then
             If LastInfo <> 1 Then PostMessage hDlg, %WM_USER + 1, 0, 0: LastInfo = 1
             Exit Function
          End If
          If GetWindowThreadProcessId(hWndLv, ByVal 0) <> GetCurrentThreadId Then Exit Function
          ScreenToClient hWndLv, pt
          id = -1
          For i = 0 To ListView_GetItemCount(hWndLv) - 1
             tRectExp.nLeft = %LVIR_BOUNDS
             ListView_GetItemRect hwndLv, i, tRectExp, %LVIR_BOUNDS
             If pt.x >= tRectExp.nLeft And pt.x < tRectExp.nRight And _
                pt.y >= tRectExp.nTop And pt.y < tRectExp.nBottom Then id = i
          Next
          ListView_GetItemText hwndLv, id, 0, TmpAsciiz, SizeOf(TmpAsciiz)
          If LastInfo <> 2 Or TmpAsciiz <> TmpAsciizC Then
             TmpAsciizC = TmpAsciiz
             Local Msg As String
             Msg = Hex$(id, 8) + TmpAsciiz
             Cdt.cbdata = Len(Msg) + 1
             Cdt.lpData  = StrPtr(Msg)
             SendMessage hDlg, %WM_COPYDATA, 0, VarPtr(Cdt)
             LastInfo = 2
          End If
       End Function
    
       Function ENCW(ByVal hWnd As Long, ByVal lParam As Long) As Long
          Static tRect As RECT
          GetClassName hWnd, TmpAsciiz, SizeOf(TmpAsciiz): Function = 1
          If UCase$(TmpAsciiz) <> "SYSLISTVIEW32" Then
          Else
             GetClientRect hWnd, tRect
             If (tRect.nRight - tRect.nLeft) = (tRectExp.nRight - tRectExp.nLeft) And _
                (tRect.nBottom - tRect.nTop) = (tRectExp.nBottom - tRectExp.nTop) Then _
                hWndLV = hWnd: Function = 0
          End If
       End Function
    
       Function SetHookMouseWindow Alias "SetHookMouseWindow" (hWnd As Long) Export As Long
          InitCommonControls
          SystemParametersInfo %SPI_GETWORKAREA, 0, ByVal VarPtr(tRectExp), 0
          EnumChildWindows FindWindow ("Progman", ""), CodePtr(ENCW), 0
          hHook = SetWindowsHookEx (%WH_MOUSE, CodePtr(HookProc), ByVal hInstDLL, ByVal 0)
          Open $HookFile For Output As #1: Print #1, hWnd, hWndLv;: Close
       End Function
    
       Function UnHookMouseWindow Alias "UnHookMouseWindow" Export As Long
          UnhookWindowsHookEx hHook: Kill $HookFile
       End Function
    Exe
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       
       Type COPYDATASTRUCT
           dwData As Dword Ptr
           cbData As Dword
           lpData As Asciiz Ptr
       End Type
       Declare Function SetHookMouseWindow Lib "HookMs.Dll" _
          Alias "SetHookMouseWindow" (hWnd As Long) As Long
       Declare Function UnHookMouseWindow  Lib "HookMs.Dll" _
          Alias "UnHookMouseWindow" As Long
       %ID_Cmd1 = 301
       %ID_Cmd2 = 302
       %ID_Text = 201
       
       CallBack Function DlgProc
          Static ActClose As Long, ListId As String, ListIdC As String, pt As PointApi, _
             cdt As COPYDATASTRUCT Ptr, hWnd As Long, hWnd1 As Long
          Select Case CbMsg
             Case %WM_INITDIALOG: SetHookMouseWindow CbHndl: ActClose = -1
             Case %WM_ERASEBKGND: If ActClose = -1 Then ShowWindow CbHndl, 0: ActClose = 0
             Case %WM_DESTROY   : UnHookMouseWindow
             Case %WM_USER + 1  : SetTimer CbHndl, 1, 1000, ByVal %Null: ActClose = %True
             Case %WM_TIMER     :
                GetCursorPos pt
                hWnd = WindowFromPoint(pt.x, pt.y)
                Do
                   hWnd1 = GetParent(hWnd): If hWnd1 = 0 Then Exit Do
                   hWnd = hWnd1
                Loop
                If hWnd <> CbHndl Then
                   KillTimer CbHndl, 1
                   If ActClose Then ActClose = 0: GetCursorPos pt: _
                      ShowWindow CbHndl, 0: ListIdC = ""
                End If
             Case %WM_COPYDATA
                ActClose = 0
                cdt = CbLparam
                ListId = Left$(@[email protected], 8)
                If ListIdC <> ListId Then
                   ListIdC = ListId
                   Control Set Text CbHndl, %ID_Text, Mid$(@[email protected], 9)
                   GetCursorPos pt
                   SetWindowPos CbHndl, 0, pt.x + 20, pt.y + 10, 0, 0, %SWP_NOSIZE Or %SWP_NOZORDER Or _
                      %SWP_NOACTIVATE Or %SWP_SHOWWINDOW
                End If
                Function = 1: Exit Function
             Case %WM_COMMAND
                Select Case CbCtl
                   Case %IDCANCEL: Dialog End CbHndl
                   Case %ID_CMD1: MsgBox "Command1"
                   Case %ID_CMD2: MsgBox "Command2"
                End Select
          End Select
       End Function
       Function PbMain
          Local hDlg As Long
          Dialog New 0, "Icons", , , 150, 70, %WS_POPUP Or %WS_BORDER, %WS_EX_TOPMOST Or %WS_EX_TOOLWINDOW To hDlg
          Control Add Frame, hDlg, %ID_Text, "", 5, 0, 140, 65
          Control Add Button, hDlg, %ID_Cmd1, "Command1", 10, 15, 130, 15
          Control Add Button, hDlg, %ID_Cmd2, "Command2", 10, 30, 130, 15
          Control Add Button, hDlg, %IDCANCEL, "Stop monitoring", 10, 45, 130, 15
          Dialog Show Modal hDlg Call DlgProc
          MsgBox "Finish"
       End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Gregery D Engle
    replied
    Originally posted by Semen Matusovski:
    Gregory --
    It looks that you want to expand a sample with global mouse hook.
    If so, you have a DLL, which is integrated in the same process as Explorer.Exe.
    Instead of popup menu you can create Dialog Modeless, which will imitate popup menu (Explorer.Exe will supply message pump).
    Depends of mouse/keyboard events you can move, show/hide this window.



    Semen,

    That somewhat makes sense to me, do you have a small example?


    ------------------
    -Greg

    Leave a comment:


  • Semen Matusovski
    replied
    Gregory --
    It looks that you want to expand a sample with global mouse hook.
    If so, you have a DLL, which is integrated in the same process as Explorer.Exe.
    Instead of popup menu you can create Dialog Modeless, which will imitate popup menu (Explorer.Exe will supply message pump).
    Depends of mouse/keyboard events you can move, show/hide this window.


    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Gregery D Engle
    replied
    originally posted by peter p stephensen:
    ok...then take a look at http://www.powerbasic.com/support/pb...ad.php?t=22566

    regards
    peter

    peter,

    i already tried that code, the problem i am running into is that
    when a popup menu is created my program pauses and waits for a
    user to click on something or click on the forum.

    trackpopupmenu hpopup, %tpm_leftalign or %tpm_rightbutton, pt.x, pt.y, 0, cbhndl, byval 0

    i read that the byval 0 :

    tells the menu to disappear if it is click on the forum, well the
    problem is that i am going to have the popup menu appear on the
    desktop and it is not going to be owned by any dialog at all.

    furthermore, i am wanting to have it disappear simply when it
    looses focus instead of having to click around and wait for
    it to disappear.

    any insight?




    ------------------
    -greg

    Leave a comment:


  • Peter P Stephensen
    replied
    ok...then take a look at http://www.powerbasic.com/support/pb...ad.php?t=22566

    regards
    peter

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

    Leave a comment:


  • Gregery D Engle
    replied
    originally posted by peter p stephensen:
    take a look at http://www.powerbasic.com/support/pb...ad.php?t=22766

    regards
    peter

    peter,

    maybe i'm missing something but all i see there is how to make
    popup help dialogs. i am wanting to make popup-menu's like when
    you right click but:

    1) i want them to disappear on certain event (after 2 seconds or wiggle mouse)
    2) i want them to follow wherever the cursor goes on the desktop

    any ideas?

    ------------------
    -greg

    Leave a comment:


  • Peter P Stephensen
    replied
    take a look at http://www.powerbasic.com/support/pb...ad.php?t=22766

    regards
    peter

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

    Leave a comment:


  • Gregery D Engle
    started a topic DDT Popup Menu

    DDT Popup Menu

    I am wanting to make a DDT Popup menu or SDK if it can't be done
    in DDT that I can POPUP at the current X,Y cordinates of the mouse.

    Kinda like when you right click on an ICON on the desktop and
    the popup menu pops up.

    I don't want to have a dialog though, I just want to be able
    to popup a menu at anytime on any dialog.

    Basically I am wanting to popup a menu on the desktop on
    certian events but it has to be at the current x,y cordinates.

    It also seems that if I use POINTAPI that it only works on
    my dialog and in this case I don't even want a dialog I want
    to make a floating popupmenu wherever my mouse goes.

    Thanks

    ------------------
    -Greg

    [This message has been edited by Gregery D Engle (edited September 08, 2000).]
Working...
X