Activating program with windows class name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    Activating program with windows class name

    Hi

    I am trying to activate a program using its Windows Class Name. Here is the code. :

    [code=vb]
    Private Sub Command0_Click( )
    Dim rVal As Integer
    rVal = AppActivateClas s("SciCalc")
    End Sub

    Function AppActivateClas s(lpclassname$)
    Dim hWnd As Integer 'the application's window handle
    Dim dummy As Integer 'Dummy variable

    'Get the Window Handle
    hWnd = alias_FindWindo w("lpclassname$ ", 0&)

    'Activate the Application
    dummy = alias_SetActive Window(hWnd)
    dummy = alias_ShowWindo w(hWnd, SW_SHOW)

    'Return True if Application Running, or False if not.
    AppActivateClas s = hWnd

    End Function
    [/code]

    In module:
    [code=vb]
    Declare Function alias_ShowWindo w Lib "User" Alias "ShowWindow " _
    (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer

    Declare Function alias_FindWindo w Lib "User" Alias "FindWindow " _
    (ByVal lpclassname As String, ByVal lpCaption As Any) As Integer

    Declare Function alias_SetActive Window Lib "User" Alias _
    "SetActiveWindo w" (ByVal hWnd As Integer) As Integer

    Const SW_SHOW = 9
    [/code]

    I am keep getting error 53: File not Found 'User'

    I have no idea what this error means and what file error has to do with this program?

    Any ideas?

    Thanks
    Qi
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by questionit
    Hi

    I am trying to activate a program using its Windows Class Name. Here is the code. :

    [code=vb]
    Private Sub Command0_Click( )
    Dim rVal As Integer
    rVal = AppActivateClas s("SciCalc")
    End Sub

    Function AppActivateClas s(lpclassname$)
    Dim hWnd As Integer 'the application's window handle
    Dim dummy As Integer 'Dummy variable

    'Get the Window Handle
    hWnd = alias_FindWindo w("lpclassname$ ", 0&)

    'Activate the Application
    dummy = alias_SetActive Window(hWnd)
    dummy = alias_ShowWindo w(hWnd, SW_SHOW)

    'Return True if Application Running, or False if not.
    AppActivateClas s = hWnd

    End Function
    [/code]

    In module:
    [code=vb]
    Declare Function alias_ShowWindo w Lib "User" Alias "ShowWindow " _
    (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer

    Declare Function alias_FindWindo w Lib "User" Alias "FindWindow " _
    (ByVal lpclassname As String, ByVal lpCaption As Any) As Integer

    Declare Function alias_SetActive Window Lib "User" Alias _
    "SetActiveWindo w" (ByVal hWnd As Integer) As Integer

    Const SW_SHOW = 9
    [/code]

    I am keep getting error 53: File not Found 'User'

    I have no idea what this error means and what file error has to do with this program?

    Any ideas?

    Thanks
    Qi
    To the best of my knowledge, the AppActivateClas s() Function has not been supported by Access since Version 2.0. Use the AppActivate Statement instead.

    Comment

    • dima69
      Recognized Expert New Member
      • Sep 2006
      • 181

      #3
      Originally posted by questionit
      Hi

      I am trying to activate a program using its Windows Class Name. Here is the code. :

      [code=vb]
      Private Sub Command0_Click( )
      Dim rVal As Integer
      rVal = AppActivateClas s("SciCalc")
      End Sub

      Function AppActivateClas s(lpclassname$)
      Dim hWnd As Integer 'the application's window handle
      Dim dummy As Integer 'Dummy variable

      'Get the Window Handle
      hWnd = alias_FindWindo w("lpclassname$ ", 0&)

      'Activate the Application
      dummy = alias_SetActive Window(hWnd)
      dummy = alias_ShowWindo w(hWnd, SW_SHOW)

      'Return True if Application Running, or False if not.
      AppActivateClas s = hWnd

      End Function
      [/code]

      In module:
      [code=vb]
      Declare Function alias_ShowWindo w Lib "User" Alias "ShowWindow " _
      (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer

      Declare Function alias_FindWindo w Lib "User" Alias "FindWindow " _
      (ByVal lpclassname As String, ByVal lpCaption As Any) As Integer

      Declare Function alias_SetActive Window Lib "User" Alias _
      "SetActiveWindo w" (ByVal hWnd As Integer) As Integer

      Const SW_SHOW = 9
      [/code]

      I am keep getting error 53: File not Found 'User'

      I have no idea what this error means and what file error has to do with this program?

      Any ideas?

      Thanks
      Qi
      Your API functions declarations are wrong.
      It should be "Lib User32" instead of "Lib User". See full declarations HERE

      Comment

      • questionit
        Contributor
        • Feb 2007
        • 553

        #4
        dima69

        I changed it to user32 from user, but now i get this error:

        Cant find DLL entry point FindWindow in user32.

        Adezii,

        "AppActivateCla ss" that i use is a function that i have defined in the code - not a VB pre-defined function! What did you mean when you said this is not in the new versions?

        Qi


        Originally posted by dima69
        Your API functions declarations are wrong.
        It should be "Lib User32" instead of "Lib User". See full declarations HERE

        Comment

        • dima69
          Recognized Expert New Member
          • Sep 2006
          • 181

          #5
          Originally posted by questionit
          dima69

          I changed it to user32 from user, but now i get this error:

          Cant find DLL entry point FindWindow in user32.

          Adezii,

          "AppActivateCla ss" that i use is a function that i have defined in the code - not a VB pre-defined function! What did you mean when you said this is not in the new versions?

          Qi
          This is the correct declaration for FindWindow:
          [CODE=vb]Declare Function FindWindow Lib "user32" Alias "FindWindow A" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long[/CODE]
          See the link in my previous post for the rest.

          Comment

          • Scott Price
            Recognized Expert Top Contributor
            • Jul 2007
            • 1384

            #6
            It looks like you are already using some copy'n'pasted code from this link: have a look at the bottom of the page, and you will see this applies to Microsoft Access 1.0, 1.1, and 2.0... If you are using another version of Access you'll have to update the code to fit the different version of VBA.

            Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


            Regards,
            Scott

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by questionit
              dima69

              I changed it to user32 from user, but now i get this error:

              Cant find DLL entry point FindWindow in user32.

              Adezii,

              "AppActivateCla ss" that i use is a function that i have defined in the code - not a VB pre-defined function! What did you mean when you said this is not in the new versions?

              Qi
              You are starting gto retrofit outdated Code and Declarations into a newer Version of Access and Windows. Start from scratch with the correct Function Declarations.

              Comment

              Working...