dcsimg
Results 1 to 6 of 6

Thread: sub transform in Public Function

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    sub transform in Public Function

    Code:
    Private Sub STOP_MOVE()
    
        Dim lFrmHdl As Long, iCount As Integer
    
        lFrmHdl = FindWindowA(vbNullString, Me.Caption)
    
        If lFrmHdl <> 0 Then
    
            For iCount = 0 To 10
                RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
            Next iCount
    
        End If
    
    End Sub
    I need to trasform the sub in a public function and pass in () the name of form and assign to Me...

    Similar:

    ...
    call STOP_MOVE(Name_of_form)

    ... lFrmHdl = FindWindowA(vbNullString, Name_of_form.Caption)

    how to?

    Note:
    I use the function in all part of my project

  2. #2
    PowerPoster
    Join Date
    Oct 2013
    Posts
    3,161

    Re: sub transform in Public Function

    Code:
    Public Sub STOP_MOVE(sFormCaption As String)
        Dim lFrmHdl As Long, iCount As Integer
    
        lFrmHdl = FindWindowA(vbNullString, sFormCaption)
    
        If lFrmHdl <> 0 Then
    
            For iCount = 0 To 10
                RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
            Next iCount
    
        End If
    End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: sub transform in Public Function

    Quote Originally Posted by Arnoutdv View Post
    Code:
    Public Sub STOP_MOVE(sFormCaption As String)
        Dim lFrmHdl As Long, iCount As Integer
    
        lFrmHdl = FindWindowA(vbNullString, sFormCaption)
    
        If lFrmHdl <> 0 Then
    
            For iCount = 0 To 10
                RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
            Next iCount
    
        End If
    End Sub
    ... but how to call ?

  4. #4
    PowerPoster
    Join Date
    Oct 2013
    Posts
    3,161

    Re: sub transform in Public Function

    Uh...
    Code:
    STOP_MOVE Me.Caption

  5. #5
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,033

    Re: sub transform in Public Function

    lFrmHdl is just your forms .hWnd property. You only need FindWindow if it's not your app (and won't it be an issue if your caption is not unique or there's more than 1 instance?)

    Code:
    Public Sub STOP_MOVE(lFrmHdl As Long)
        Dim iCount As Integer
    
        If lFrmHdl <> 0 Then
    
            For iCount = 0 To 10
                RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
            Next iCount
    
        End If
    End Sub
    STOP_MOVE Form1.hWnd

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,579

    Re: sub transform in Public Function

    All the above suggestions should work.

    But, if you want to be a bit more consistent with the way you've been doing things, here's how I often move such a procedure to my BAS library:

    Code:
    
    Private Sub STOP_MOVE(frm As Form)
    
        Dim lFrmHdl As Long, iCount As Integer
    
        lFrmHdl = FindWindowA(vbNullString, frm.Caption)
    
        If lFrmHdl <> 0 Then
    
            For iCount = 0 To 10
                RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
            Next iCount
    
        End If
    
    End Sub
    
    That way, if you've got other things you want to do to the form in that procedure, you've still got access to the form object.

    Enjoy,
    Elroy

    EDIT1: Usage: STOP_MOVE Me
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width