CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    How to display system menu with VB when you click on picturebox(when you press with right mouse butt

    Thank You


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How to display system menu with VB when you click on picturebox(when you press with right mouse

    this code displays the system menu in the upper left corner upon click of the button

    option Explicit
    private Type RECT
    Left as Long
    Top as Long
    Right as Long
    Bottom as Long
    End Type
    private Type TPMPARAMS
    cbSize as Long
    rcExclude as RECT
    End Type
    private Declare Function TrackPopupMenuEx Lib "user32" (byval hMenu as Long, byval un as Long, byval n1 as Long, byval n2 as Long, byval hwnd as Long, lpTPMParams as Any) as Long
    private Declare Function GetSystemMenu Lib "user32" (byval hwnd as Long, byval bRevert as Long) as Long

    private Sub Command1_Click()
    Dim hsys as Long
    Dim tp as TPMPARAMS
    hsys = GetSystemMenu(me.hwnd, 0)
    If hsys then
    Call TrackPopupMenuEx(hsys, 0, 0, 0, Command1.hwnd, byval 0&)
    End If
    End Sub





  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: How to display system menu with VB when you click on picturebox(when you press with right mouse

    OK, this one might be more useful:
    it places the systemmenu directly below the commnd button and
    if traps the selected menu choice


    option Explicit
    private Type RECT
    Left as Long
    Top as Long
    Right as Long
    Bottom as Long
    End Type
    private Type TPMPARAMS
    cbSize as Long
    rcExclude as RECT
    End Type
    Const TPM_RETURNCMD as Long = &H100
    private Declare Function TrackPopupMenuEx Lib "user32" (byval hMenu as Long, byval un as Long, byval n1 as Long, byval n2 as Long, byval hwnd as Long, lpTPMParams as Any) as Long
    private Declare Function GetSystemMenu Lib "user32" (byval hwnd as Long, byval bRevert as Long) as Long
    private Const SC_CLOSE = &HF060&
    private Type POINTAPI
    x as Long
    y as Long
    End Type
    private Declare Function ClientToScreen Lib "user32" (byval hwnd as Long, lpPoint as POINTAPI) as Long
    private Declare Function GetWindowRect Lib "user32" (byval hwnd as Long, lpRect as RECT) as Long

    private Sub Command1_Click()
    Dim hsys as Long
    Dim tp as TPMPARAMS
    hsys = GetSystemMenu(me.hwnd, 0)
    If hsys then
    Dim lcmd as Long
    Dim rc as RECT
    GetWindowRect Command1.hwnd, rc
    lcmd = TrackPopupMenuEx(hsys, TPM_RETURNCMD, rc.Left + 10, rc.Bottom, Command1.hwnd, byval 0&)
    Select Case lcmd
    Case SC_CLOSE
    MsgBox "close selected"
    End Select
    End If
    End Sub





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured