Microsoft KB Archive/104710

= ACC: How to Activate an Application with Class Name (1.x/2.0) =

Article ID: 104710

Article Last Modified on 5/6/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q104710



SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

The function AppActivate activates an application using the title bar text of the application. You must use the exact title bar text or the function will fail. For example, the title bar text of Microsoft Access is "Microsoft Access" unless an object (a form or report, for example) is maximized. If an object is maximized, the title bar text is "Microsoft Access - ." Because knowing the exact title bar text ahead of time can be challenging, the following function demonstrates how to activate an application using the application's Class Name and Microsoft Windows API calls.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access Basic," in version 2.0.



MORE INFORMATION
When an application is started from Program Manager, it registers the class name of the form. The window class provides information about the name, attributes, and resources required by your form. The Microsoft Access window has the class name "OMain."

You can determine the class name of an application by using SPY.EXE supplied with the Microsoft Windows Software Development Kit (SDK)version 3.1 or SPYXX.EXE supplied with Microsoft Visual C++ version 2.0.

To use the application's Class Name to activate the application, create a new module with the following Declaration section and function:

NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

NOTE: You may have these Microsoft Windows API functions defined in an existing Microsoft Access library or module; therefore, your declarations may be duplicates causing a duplicate procedure name error message. There are two resolutions to this error:

 Remove or comment out the duplicated declarations statements.  Use function aliasing by replacing the phrase "alias_" throughout the code below with your own unique aliasing characters. This method allows you to remove the other module and not lose the declarations for the API functions in the new module. For more information on aliasing see page Microsoft Access, "Building Applications," version 2.0, page 369.

   '************************************************************** ' MODULE DECLARATION SECTION '**************************************************************   Option Compare Database   'Use database order for string comparisons Option Explicit

'Windows API Declarations Declare Function alias_ShowWindow Lib "User" Alias "ShowWindow" _ (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer

Declare Function alias_FindWindow Lib "user" Alias "FindWindow" _ (ByVal lpclassname As String, ByVal lpCaption As Any) As Integer

Declare Function alias_SetActiveWindow Lib "User" Alias _ "SetActiveWindow" (ByVal hWnd As Integer) As Integer

Const SW_SHOW = 9

'******************************************************************   ' FUNCTION: AppActivateClass '   ' PURPOSE: Used to activate another application by using its '   class name instead of the title bar text as AppActivate does. '   ' ARGUMENTS: '   lpClassName$   - The Class Name of the application. '   ' RETURNS: '    0   - The application was not found - it either was not running '          or the class name is incorrect '   -1   - The application was activated

'******************************************************************

Function AppActivateClass(lpclassname$) Dim hWnd As integer      'the application's window handle Dim dummy as integer     'Dummy variable

'Get the Window Handle hWnd = alias_FindWindow(lpclassname$, 0&)

'Activate the Application dummy = alias_SetActiveWindow(hWnd) dummy = alias_ShowWindow(hWnd, SW_SHOW)

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

End Function 

To use this function, call the function and supply the class name of the application to activate. The following example shows how to activate Microsoft Word for Windows:

  x=AppActivateClass("opusapp")

Below are some class names of common applications that are included in Windows:

  Class Name                   Application OMain                       ACCESS.EXE SciCalc                     CALC.EXE CalWndMain                  CALENDAR.EXE Cardfile                    CARDFILE.EXE Clipboard                   CLIPBOARD.EXE Clock                       CLOCK.EXE CtlPanelClass               CONTROL.EXE XLMain                      EXCEL.EXE Session                     MS-DOS.EXE Notepad                     NOTEPAD.EXE pbParent                    PBRUSH.EXE Pif                         PIFEDIT.EXE PrintManager                PRINTMAN.EXE Progman                     PROGMAN.EXE   (Windows Program Manager) Recorder                    RECORDER.EXE Reversi                     REVERSI.EXE #32770                      SETUP.EXE Solitaire                   SOL.EXE Terminal                    TERMINAL.EXE WFS_Frame                   WINFILE.EXE MW_WINHELP                  WINHELP.EXE #32770                      WINVER.EXE OpusApp                     WINWORD.EXE MSWRITE_MENU                WRITE.EXE

Below are some class names of applications that are new with Windows 95:

  Class Name                   Application CabinetWClass               My Computer Window Internet Explorer_Frame     IEXPLORE.EXE MSPaintApp                  MSPAINT.EXE SageWindowClass             System Agent Com Window Shell_Traywnd               Windows 95 Task Bar WordPadClass                WORDPAD.EXE DialerClass                 DIALER.EXE SJE_CDPlayerClass           CDPLAYER.EXE MyDlgClass                  CHARMAP.EXE MSDefragWClass1             DEFRAG.EXE GFVMainWndClass             FAXVIEW.EXE FreeWClass                  FREECELL.EXE Mplayer                     MPLAYER.EXE AfxFrameorView              HEARTS.EXE NW_Class                    NETWATCH.EXE AppClass                    PACKAGER.EXE System Policy Editor        POLEDIT.EXE PWLEdit                     PWLEDIT.EXE RegEdit_RegEdit             REGEDIT.EXE ScanDskWDlgClass            SCANDSK.EXE SoundRec                    SNDREC32.EXE Volume Control              SNDVOL32.EXE System Monitor              SYSMON.EXE MSTaskSwWClass              TASKMAN.EXE TelnetWClass                TELNET.EXE WinIPCfgClass               WINIPCFG.EXE WordPadClass                WORDPAD.EXE Session_Window              HYPERTRM.EXE

Additional query words: caption

Keywords: kbhowto kbprogramming KB104710

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.