Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the Window/Application Name by Clicking on it

Status
Not open for further replies.

allannichols

Programmer
Apr 27, 2001
3
GB
How can i get the Window/Application name by clicking on it.

I am trying to write code for a virtual keyboard for a touch screen PC. I can use SendKeys to send the character to the application, but I need to know the window/application name first so I can do AppActivate then SendKeys sends to that application.

I was wondering if there was any way you could first click on the application to get the name then use that name in AppActivate.

i.e. AppActivate Name,true
SendKeys "A",true
 
When you double click on file with MP3 extension, it opens with WinAmp (or other player).
This example will show you how to associate your own extension with your application.
When the user will double click on .xxx file (for example), it will open with your application, and your application will get the file name as parameter.

Preparations
Add 1 Command Button to your form.
Click the button to associate the .xxx extension with your application.

Module Code

Declare Function RegCreateKey Lib "advapi32.dll" Alias _
"RegCreateKeyA" (ByVal hKey As Long, _
ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegSetValue Lib "advapi32.dll" Alias _
"RegSetValueA" (ByVal hKey As Long, _
ByVal lpSubKey As String, ByVal dwType As Long, _
ByVal lpData As String, ByVal cbData As Long) As Long

' Return codes from Registration functions.
Public Const ERROR_SUCCESS = 0&
Public Const ERROR_BADDB = 1&
Public Const ERROR_BADKEY = 2&
Public Const ERROR_CANTOPEN = 3&
Public Const ERROR_CANTREAD = 4&
Public Const ERROR_CANTWRITE = 5&
Public Const ERROR_OUTOFMEMORY = 6&
Public Const ERROR_INVALID_PARAMETER = 7&
Public Const ERROR_ACCESS_DENIED = 8&

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const MAX_PATH = 260&
Public Const REG_SZ = 1



Form Code
Private Sub Command1_Click()

Dim sKeyName As String 'Holds Key Name in registry.
Dim sKeyValue As String 'Holds Key Value in registry.
Dim ret& 'Holds error status if any from API calls.
Dim lphKey& 'Holds created key handle from RegCreateKey.

'This creates a Root entry called "MyApp".
sKeyName = "MyApp"
sKeyValue = "My Application"
ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)

'This creates a Root entry called .XXX associated with "MyApp".
'You can replace ".XXX" with your wanted extension
sKeyName = ".XXX"
'replace all "MyApp" below with your application name
sKeyValue = "MyApp"
ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)

'This sets the command line for "MyApp".
sKeyName = "MyApp"
'replace c:\mydir\my.exe with your exe file. In this example,
'All the .XXX files will be opened with the file c:\mydir\my.exe
sKeyValue = "c:\mydir\my.exe %1"
ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
ret& = RegSetValue&(lphKey&, "shell\open\command", REG_SZ, _
sKeyValue, MAX_PATH)
'*******************************************************
'That's All!
'Now to test this program, after you associate the .XXX files with
'c:\mydir\my.exe (In this example), start a new project, and
'copy the following 3 lines to your form (uncomment the lines)

'Private Sub Form_Load()
' MsgBox Command
'End Sub

'compile the program to my.exe file, and put it in c:\mydir directory.
'Now go back to Windows and change the name of one of your files
'To Test.xxx and double click on it. It will be opened with the program
'c:\mydir\my.exe and it will pop up message box: "c:\Test.xxx"
'***********************************************************
End Sub

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top