|
-
Aug 21st, 2001, 07:09 AM
#1
Thread Starter
Fanatic Member
Windows Programs 'n Rigth Botton
Two q's
1.- How do i find every application programs. i.e.: Word, Excel, CorelDraw, etc. Installed on a PC?
2.- How do i control the rigth botton of my mouse? I do not want that users use it.
-
Aug 21st, 2001, 07:23 AM
#2
In order for users to use the right mouse button, you would have to write code so they can. It seems to me that if you don't want them to use it, don't write the code.
The only default right mouse button code is the popup menu built into controls like a text box. If you want that disabled, then try this code:
Private Declare Function LockWindowUpdate Lib "User32" (ByVal hwndLock As Long) As Long
In the Mousedown event of your textbox, put:
If Button = vbRightButton Then
'lock the text box for my personal use
LockWindowUpdate Text1.hWnd
'the text box MUST be disabled to
'prohibit default popup menu
Text1.Enabled = False
Now, however, in order for them to use the text box, you have to re-enable it, so in the MouseUp event put:
If Button = vbRightButton Then
'this releases the lock
LockWindowUpdate 0&
Text1.Enabled = True
I don't know about CorelDraw and other such stuff. You will need to do some research on that, but this code should tell you what MS Office Products are installed on the machine:
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, _
ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As Long) _
As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal lpReserved As Long, _
lpType As Long, ByVal lpData As String, lpcbData As Long) _
As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F
Private Const HKEY_LOCAL_MACHINE = &H80000002
'*****************************************************
'These functions return the path to the specified office
'application or a 0-length string if the application does not
'exist on the machine. This is one good way to check whether a
'specific office application is present before trying to run
'automation code for that application
'*****************************************************
Public Function GetWordPath() As String
GetWordPath = GetOfficeAppPath("Word.Application")
End Function
Public Function GetExcelPath() As String
GetExcelPath = GetOfficeAppPath("Excel.Application")
End Function
Public Function GetAccessPath() As String
GetAccessPath = GetOfficeAppPath("Access.Application")
End Function
Public Function GetOutlookPath() As String
GetOutlookPath = GetOfficeAppPath("Outlook.Application")
End Function
Public Function GetPowerPointPath() As String
GetPowerPointPath = _
GetOfficeAppPath("PowerPoint.Application")
End Function
Public Function GetFrontPagePath() As String
GetFrontPagePath = GetOfficeAppPath("FrontPage.Application")
End Function
Private Function GetOfficeAppPath(ByVal ProgID As String) As String
Dim lKey As Long
Dim lRet As Long
Dim sClassID As String
Dim sAns As String
Dim lngBuffer As Long
Dim lPos As Long
'GetClassID
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Classes\" & ProgID & "\CLSID", 0&, _
KEY_ALL_ACCESS, lKey)
If lRet = 0 Then
lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
sClassID = Space(lngBuffer)
lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sClassID, _
lngBuffer)
'drop null-terminator
sClassID = Left(sClassID, lngBuffer - 1)
RegCloseKey lKey
End If
'Get AppPath
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Classes\CLSID\" & sClassID & _
"\LocalServer32", 0&, KEY_ALL_ACCESS, lKey)
If lRet = 0 Then
lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
sAns = Space(lngBuffer)
lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sAns, _
lngBuffer)
sAns = Left(sAns, lngBuffer - 1)
RegCloseKey lKey
End If
'Sometimes the registry will return a switch
'beginning with "/" e.g., "/automation"
lPos = InStr(sAns, "/")
If lPos > 0 Then
sAns = Trim(Left(sAns, lPos - 1))
End If
GetOfficeAppPath = sAns
End Function
-
Aug 21st, 2001, 08:01 AM
#3
Registered User
For 2, you can disable the right button click for your entire application (not system wide though) using the following code to subclass the mouse.
In a module:
VB Code:
Option Explicit
Public Const WH_MOUSE As Long = 7
'API Declarations
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Global mouse/keyboard function callback handles
Public g_hMouseHook As Long
Public Sub HookMouse()
g_hMouseHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, App.hInstance, App.ThreadID)
End Sub
Public Sub UnhookMouse()
If g_hMouseHook Then
Call UnhookWindowsHookEx(g_hMouseHook)
g_hMouseHook = 0
End If
End Sub
Public Function MouseProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Mouse Function Hook...
If idHook < 0 Then
MouseProc = CallNextHookEx(g_hMouseHook, idHook, wParam, ByVal lParam)
Else
Debug.Print wParam
If wParam = 516 Or wParam = 518 Or wParam = 164 Then 'single or double-click of mouse
Debug.Print "Left mouse click disabled..."
'Setting the return value to -1 cancels Mouse input...
MouseProc = -1
Else
MouseProc = CallNextHookEx(g_hMouseHook, idHook, wParam, ByVal lParam)
End If
End If
End Function
To diable the right mouse click, application wide call the functions like this for example:
VB Code:
Private Sub Command1_Click()
HookMouse 'diable right click
End Sub
Private Sub Command2_Click()
UnhookMouse 'enable right click
End Sub
-
Aug 21st, 2001, 08:04 AM
#4
Oooh...I like this Nucleus - Good code!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|