• How does one use the SetFocus API in VB? (VB API)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » How does one use the SetFocus API in VB? (VB API)

    Author
    Topic
    #360960

    How does one use the SetFocus API in VB?

    Here is the declare string derived from the API viewer;

    Private Declare Function SetFocus Lib “user32” Alias “SetFocus” (ByVal hwnd As Long) As Long

    When I use this declare string, I get an “object member already exists ina object module from which this object derives” error; I think this is because the function name is the same as a VB command; I have tried changing the alias to other things that might work but still get errors;

    What alias can I use, or is this a “no-deal” API for VB?

    Thanks,

    –Llyal

    Viewing 0 reply threads
    Author
    Replies
    • #544620

      What are you trying to set the focus to that requires an API call?

      • #544623

        Charlotte,

        I have a form focus problem (the details are in another post I made a few days ago under the title “Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)”); I want to try using the windows focus API to see if this might fix the problem; I have found that using the APIs are straightforward, but I am having problems with this Setfocus API;

        Any help is appreciated,

        –Llyal

        • #551162

          Edited by Andrew Cronnolly on 09-Nov-01 16:57.

          Edited to include Hyperlink

          From http://www.vbapi.com: http://www.vbapi.com

          “Visual Basic-Specific Issues:
          This function behaves exactly like the SetFocus method of many VB controls.
          However, because this function shares its name with this method, it must be
          renamed to something like SetFocusAPI when you use it in a VB program,
          or else the compiler will give you an error. See the example for a demonstration
          of this.”

          Hope this helps.
          -RL
          http://www.vbapi.com

          • #551229

            RL,

            Thanks for the tip. I have found that both the SetFocus in API and VB exibit weird flickering behavior when used in a specific way with a form. I described the problem in a related post. This problem occurs on the Windows2000 platform- does not occur on WIn98 or WinNT (don’t know about other platforms);

            –Llyal

    Viewing 0 reply threads
    Reply To: How does one use the SetFocus API in VB? (VB API)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: