Results 1 to 3 of 3

Thread: Start Menu Run List

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    NY
    Posts
    45

    Post

    I need more help The run list such as when you go to Start->Run, (hkey current user\software\microsoft\currentversion\exporer\runmru) is stored in a funky format, any programmer can glance at it and see how it works, but problem is, i cant get this code to work properly:
    (i suggest you visit that key before looking at this)

    nDex = Asc(Right(MRUList(0), 1)) - 96
    MRUList(nDex) = txtApp & "\1"
    MRUList(0) = Right(MRUList(0), 1) & Left(MRUList(0), Len(MRUList(0)) - 1)
    Stry = MRUList(nDex)
    SaveRegistryString HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU", Right(MRUList(0), 1), Stry
    Stry = MRUList(0)
    SaveRegistryString HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU", "MRUList", Stry

    This works on the fact that a small a is chr(95), it subtracts to get the index in MRUList.

    What it does, is if the user runs something that isn't already in the list, it's supposed to replace the last index, the entries are contained with MRUList(1 to 26), the list of entries are contained in MRUList(0), with txtApp, then take the last letter of MRUList(0) and place it in front, then save the changes. It is saving it wrong, and i dont know what the problem is. I spent a half hour to 45 minutes and only made myself want to shoot the people who's idea it was to write it like this. You don't have to edit my code, any cleaner home-made code will work fine.

    ------------------
    -Mystiq

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Try something along these lines:

    Add a Combobox and a Command Button to the Form..
    Code:
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, 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, lpData As Any, lpcbData As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const CB_FINDSTRINGEXACT = &H158
    Private Const HKEY_CURRENT_USER = &H80000001
    Private sMRUList As String
    
    Private Sub Form_Load()
        sMRUList = GetReg(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\", "MRUList")
        FillList
    End Sub
    
    Private Sub Command1_Click()
        Dim iIndex As Integer
        Dim sNew As String
        Dim iVal As Integer
        
        If Len(Trim(Combo1)) = 0 Then Exit Sub
        iIndex = SendMessage(Combo1.hwnd, CB_FINDSTRINGEXACT, -1, ByVal Combo1.Text)
        If iIndex > -1 Then
            sNew = Mid$(sMRUList, iIndex + 1, 1)
            If iIndex > 0 Then sNew = sNew & Left$(sMRUList, iIndex)
            sMRUList = sNew & Mid$(sMRUList, iIndex + 2)
        Else
            If Len(sMRUList) = 26 Then
                sMRUList = Right$(sMRUList, 1) & Left$(sMRUList, Len(sMRUList) - 1)
            Else
                iIndex = 1
                While InStr(sMRUList, Chr(iIndex + 96))
                    iIndex = iIndex + 1
                Wend
                sMRUList = Chr(iIndex + 96) & sMRUList
            End If
            Call SetReg(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\", Left$(sMRUList, 1), Combo1.Text & "\1")
        End If
        Call SetReg(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\", "MRUList", sMRUList)
        FillList
    End Sub
    
    Private Sub FillList()
        Dim iIndex As Integer
        Dim sItem As String
        
        Combo1.Clear
        For iIndex = 1 To Len(sMRUList)
            sItem = GetReg(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU\", Mid$(sMRUList, iIndex, 1))
            Combo1.AddItem Left$(sItem, Len(sItem) - 2)
        Next
        If Combo1.ListCount Then Combo1.ListIndex = 0
    End Sub
    
    Private Function GetReg(ByVal lRoot As Long, ByVal sKey As String, ByVal sValue As String) As String
        Dim lRegKey As Long
        Dim sBuff As String * 255
        Call RegOpenKey(lRoot, sKey, lRegKey)
        If RegQueryValueEx(lRegKey, sValue, 0&, 1, ByVal sBuff, 255) = 0 Then GetReg = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
        Call RegCloseKey(lRegKey)
    End Function
    
    Private Sub SetReg(ByVal lRoot As Long, ByVal sKey As String, ByVal sValue As String, ByVal sData As String)
        Dim lRegKey As Long
        Call RegOpenKey(lRoot, sKey, lRegKey)
        Call RegSetValueEx(lRegKey, sValue, 0&, 1, ByVal sData, Len(sData))
        Call RegCloseKey(lRegKey)
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    NY
    Posts
    45

    Post

    All that does is add And i fixed my problem, i had two statements switched.

    ------------------
    -Mystiq

    [This message has been edited by mystiq (edited 11-28-1999).]

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