
'====================================================================
'' Popup menu demo, fully programmed (no menu resource), modal
'' dialog as main.
'====================================================================

#include "dialogs.bas"

'====================================================================

#define TPM_HORPOSANIMATION &h0400
#define TPM_HORNEGANIMATION &h0800
#define TPM_VERPOSANIMATION &h1000
#define TPM_VERNEGANIMATION &h2000
#define TPM_NOANIMATION     &h4000

'====================================================================

Function DialogProc( Byval hDlg As  HWND, _
                     Byval uMsg As UINT, _
                     Byval wParam As WPARAM, _
                     Byval lParam As LPARAM ) As Integer

  Static As HMENU hMenuPop
  Dim As RECT rc
  Dim As Integer i

  Select Case uMsg

    Case WM_INITDIALOG

      hMenuPop = CreatePopupMenu()

      AppendMenu( hMenuPop, MF_STRING, 1001, "Option &1" )
      AppendMenu( hMenuPop, MF_STRING, 1002, "Option &2" )
      AppendMenu( hMenuPop, MF_SEPARATOR, 0, 0 )
      AppendMenu( hMenuPop, MF_STRING, 1003, "Option &3" )
      AppendMenu( hMenuPop, MF_SEPARATOR, 0, 0 )
      AppendMenu( hMenuPop, MF_STRING, 1004, "Option &4" )
      AppendMenu( hMenuPop, MF_STRING, 1005, "Option &5" )

    Case WM_COMMAND

      If hiword(wParam) = BN_CLICKED Then

        Select Case loword(wParam)

          Case IDCANCEL

            '' This allows the user to close the
            '' dialog by pressing the Escape key.

            EndDialog( hDlg, null )

          Case 100

            GetWindowRect( GetDlgItem( hDlg, 100 ), @rc )

            i = TrackPopupMenu( hMenuPop, _
                                TPM_LEFTALIGN Or _
                                TPM_RETURNCMD Or _
                                TPM_TOPALIGN Or _
                                TPM_HORPOSANIMATION, _
                                rc.left, _
                                rc.top, _
                                0, _
                                hDlg, _
                                0 )

            MessageBox( hDlg, "Selected ID = "& Str(i), _
                          "From TrackPopupMenu", 0 )

        End Select

      End If

    Case WM_CLOSE

      EndDialog( hDlg, null )

  End Select

  Return 0

End Function

'====================================================================

Dim As LPDLGTEMPLATE lpdt

Dialog( 1, 0, 0, 120, 90, "Popup Menu Demo", lpdt, _
        WS_OVERLAPPEDWINDOW Or DS_CENTER )

PushButton( 100, -1, 40, 35, 12, "Pop" )

CreateModalDialog( 0, @DialogProc, 0, lpdt )

'====================================================================
 