Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Right Click (vb6)

    Sorry to post 2 requests within minutes.

    I've just written the below function for the right click event (Mouse_Up)

    <pre>Private Function imgRclick(i As Integer, )

    Dim intIndex As Integer
    Dim strFile As String
    Dim j As Integer
    For j = 1 To intNumberOfImages
    If j = i Then
    If MsgBox("Add To E:Mail", vbYesNo, "Image Selection") = vbYes Then
    Me.lstEmail.AddItem strFolder & "" & Left$(Me.Controls("Text" & i), 8) & ".jpg"
    Me.txtInfo.Text = Me.lstEmail.ListCount & " Images To Mail"
    End If
    Else
    End If
    Next j
    End Function</pre>


    But I forgot to add the code for the Right Mouse Button and was working with both mouse buttons!, So I added:

    <pre>Private Function imgRclick(i As Integer, button As Long)
    If button = vbRightButton Then

    Dim intIndex As Integer
    Dim strFile As String
    Dim j As Integer
    For j = 1 To intNumberOfImages
    If j = i Then
    If MsgBox("Add To E:Mail", vbYesNo, "Image Selection") = vbYes Then
    Me.lstEmail.AddItem strFolder & "" & Left$(Me.Controls("Text" & i), 8) & ".jpg"
    Me.txtInfo.Text = Me.lstEmail.ListCount & " Images To Mail"
    End If
    Else
    End If
    End If
    Next j
    End Function</pre>


    Now it doesn't work, where did I go wrong ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Right Click (vb6)

    Your new "If ... Then" statement comes right at the beginning, before the "For j = ..." statement. Therefore, the "End If" must be after the "Next j" statement. You must always nest one "block" completely inside another "block".

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    Then I get "Argument Not Optional"

    Private Sub img1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    imgRclick 1
    End Sub

    I also have a imgClick function also.

    Would I be better concatinating the two functions together ?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Right Click (vb6)

    Yes, if you look at the new definition of the imgRclick function, you will see that you have added an argument named Button. So pass it to imgRclick:

    imgRclick 1, Button

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    Hans, I never realised that, silly me !!

    Just to be on the safe side, (although it now works) I've included the functions & click functions below, same question applies,
    should I contatinate the two (imgClick & MouseDown) into one function for efficiency sake.
    I'm afraid the two as separate, may conflict at some time, and there seems alot going on with all the events firing:
    They all work.

    *********** Functions **************
    <pre>Private Function imgclick(i As Integer)
    Dim intIndex As Integer
    Dim strFile As String
    Dim j As Integer
    For j = 1 To intNumberOfImages
    If j = i Then
    Pdf1.Visible = False
    Me.PreviewImg.Picture = Me.Controls("img" & j).Picture
    Else
    End If
    Next j
    End Function</pre>

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

    <pre>Private Function imgRclick(i As Integer, Button As Integer)

    If Button = vbRightButton Then
    Dim intIndex As Integer
    Dim strFile As String
    Dim j As Integer
    For j = 1 To intNumberOfImages
    If j = i Then
    If MsgBox("Add To E:Mail", vbYesNo, "Image Selection") = vbYes Then
    Me.lstEmail.AddItem strFolder & "" & Left$(Me.Controls("Text" & i), 8) & ".jpg"
    Me.txtInfo.Text = Me.lstEmail.ListCount & " Images To Mail"
    End If
    Else
    End If
    Next j
    End If
    End Function</pre>

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

    <pre> Private Sub imgDblClick(i As Integer)
    Dim stAppName As String

    If Me.Controls("Text" & i).Text = vbNullString Then
    MsgBox "No Image To Comment", vbInformation, "Information"
    Exit Sub
    End If

    stAppName = "L:mmpdfutilitiesedjpgcom.exe" & " " & "L:MMPDFImage" & _
    Left$(Me.Controls("Text" & i), 8) & ".jpg"
    Call Shell(stAppName, 1)

    End Sub</pre>

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

    ************ Click Events *****************

    <pre>Private Sub img1_Click()
    imgclick 1
    End Sub</pre>



    <pre>Private Sub Img1_DblClick()
    imgDblClick 1
    End Sub</pre>



    <pre>Private Sub img1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    imgRclick 1, Button
    End Sub</pre>


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Right Click (vb6)

    I think it's fine as it is. When you click the right mouse button, the On Mouse Down event occurs, but not the On Click event. When you click the left mouse button, both On Mouse Down and On Click occur, and you can choose which one you use to handle it.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    Thanks for that.
    Clarification is peace of mind.
    Have a good evening <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    A long shot really !

    The msgbox opens to the centre of the screen, Is there a way to have the msgbox open where the mouse pointer is?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Right Click (vb6)

    No, you'd have to create a custom form and use that as message box. You can position a form where you like.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    I didn't think so, the users will have to live with it.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Right Click (vb6)

    There is always a chance that <!profile=MarkD>MarkD<!/profile> will come up with a very clever solution using Windows API functions...

  12. #12
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Right Click (vb6)

    Did someone mention my name? <img src=/S/confused.gif border=0 alt=confused width=15 height=20> You'd think this would be simple, which it would be if the MsgBox function provided xpos & ypos arguments to position msgbox on screen the way the InputBox function does. The Windows MessageBox API function is declared as follows:

    Declare Function MessageBox Lib "user32" Alias "MessageBoxA" _
    (ByVal hwnd As Long, _
    ByVal lpText As String, _
    ByVal lpCaption As String, _
    ByVal wType As Long) As Long

    Example of use in Access app:

    Sub TestMessageBoxAPI()

    Dim strMsg As String
    strMsg = "ATTENTION DUMMY" & vbCrLf & vbCrLf & _
    "Please correct your stupid mistake. " & vbCrLf & vbCrLf & _
    "E-mail address must include the ''@'' symbol!"
    MessageBox Application.hWndAccessApp, strMsg, "ERROR MSG", MB_ICONEXCLAMATION

    End Sub

    Note the API does not provide args for xpos or ypos screen coordinates. The hwnd arg refers to the process (application) that invokes the msgbox. A Windows (or VB) msgbox is part of the dialog box message loop that falls under User32 in Windows (User32.dll), which cannot be modified without using hooks and similar methods. According to MSKB 180936:

    "You can create a CBT hook for your application so that it receives notifications when windows are created and destroyed. If you display a message box with this CBT hook in place, your application will receive a HCBT_ACTIVATE message when the message box is activated. Once you receive this HCBT_ACTIVATE message, you can position the window with the SetWindowPos API function and then release the CBT hook if it is no longer needed. "

    That sounds simple enough.... For more details and sample code, see MSKB 180936:

    HOWTO: Position a MsgBox Using a Windows Hook Procedure

    I haven't tried this technique myself, when I have time this weekend may try it just for "fun" (??). Of course you would also have to determine the mouse pointer's screen coordinates, which should be possible in VB. A simpler approach would be, instead of trying to bring the msgbox to the mouse pointer (doing things the hard way), is to bring the mouse pointer to the msgbox, by recommending to users that they avail themselves of the "Snap To" option provided by most modern mouse drivers. See att'd pic. Enabling this option will automatically move the mouse pointer to the dialog box's default button. This would be simpler than tangling with Windows hooks, etc.

    HTH

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    Thanks Mark
    As ever very informative.

    Looking at the Microsoft example, it may be possible to find the co-ordinates for each Image Control, and position the
    msgbox to the left and top positions ?

    What do you think ?

    If you do manage to find time and come up with something, I'm sure it will be quite useful.

    Have fun

  14. #14
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    Dave,

    I couldn't figure if this refers to VB or VBA. If the former, then this ExtendedMsgBox-module might do the trick. If it's VBA though, then I'm pretty sure this method is not workable.

    Alan

    Edited - Always helps to read the Subject! <img src=/S/blush.gif border=0 alt=blush width=15 height=15> I see it's VB6.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Right Click (vb6)

    Nice find, thanks.

    p.s

    It does work in VB6

Page 1 of 2 12 LastLast

Posting Permissions

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