Results 1 to 4 of 4

Thread: Windows Programs 'n Rigth Botton

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Talking 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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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:
    1. Option Explicit
    2.  
    3. Public Const WH_MOUSE As Long = 7
    4.  
    5. 'API Declarations
    6. 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
    7. Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    8. Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    9.  
    10. 'Global mouse/keyboard function callback handles
    11. Public g_hMouseHook As Long
    12.  
    13. Public Sub HookMouse()
    14. g_hMouseHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, App.hInstance, App.ThreadID)
    15. End Sub
    16.  
    17. Public Sub UnhookMouse()
    18.     If g_hMouseHook Then
    19.         Call UnhookWindowsHookEx(g_hMouseHook)
    20.         g_hMouseHook = 0
    21.     End If
    22. End Sub
    23.  
    24. Public Function MouseProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    25.     'Mouse Function Hook...
    26.     If idHook < 0 Then
    27.         MouseProc = CallNextHookEx(g_hMouseHook, idHook, wParam, ByVal lParam)
    28.     Else
    29.         Debug.Print wParam
    30.         If wParam = 516 Or wParam = 518 Or wParam = 164 Then 'single or double-click of mouse
    31.             Debug.Print "Left mouse click disabled..."
    32.             'Setting the return value to -1 cancels Mouse input...
    33.             MouseProc = -1
    34.         Else
    35.             MouseProc = CallNextHookEx(g_hMouseHook, idHook, wParam, ByVal lParam)
    36.         End If
    37.            
    38.     End If
    39. End Function

    To diable the right mouse click, application wide call the functions like this for example:
    VB Code:
    1. Private Sub Command1_Click()
    2. HookMouse 'diable right click
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6. UnhookMouse 'enable right click
    7. End Sub

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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
  •  



Click Here to Expand Forum to Full Width