Results 1 to 8 of 8

Thread: Automatically Load most recent project at startup?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005

    Automatically Load most recent project at startup?

    How the heck do you get the VB6 IDE to automatically open the last project at start-up? I get this annoying window every time. It makes no difference if you check that "show at startup" or not. I know I can make an icon on my desktop to run the IDE with a command line pointing to my project but I'd like to know if there's an easier way. This has been bugging me for 20 years and I finally decided to see if there's a solution. Thanks in advance.

  2. #2
    Frenzied Member
    Join Date
    Nov 2017

    Re: Automatically Load most recent project at startup?

    VB6 out of the box won't do this I don't think. I would imagine creating an add-on to do this should be feasible, but I've never created an add-on, so who knows.

    Another option would be to write a program that acts as a VB 6.0 launcher. It would need to read the contents of the "1" String value in HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0\RecentFiles\ (if it exists) and then execute VB6.exe and pass the path from that registry key as the parameter.

  3. #3
    Join Date
    Feb 2012
    West Virginia

    Re: Automatically Load most recent project at startup?

    If I want to work on an existing project I always just double click the vbp file for that project. You may even want to create a folder on your desktop or off the start menu and places shortcuts to the various projects you may want to work with in order to make it easier to access them quickly.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Near Nashville TN

    Re: Automatically Load most recent project at startup?

    The "recent files" on the IDE's Menu --> File also works just fine. That's the way most other programs do it, even the most recent versions of Word, Excel, etc.

    Darkbob, I just have one project that I primarily work on, and, as you suggested, I just keep a shortcut to the VBP on my desktop to that project. Regarding all other projects, I either use the "recent files" from within the IDE, or I right-click my VB6 IDE's shortcut on the Windows 10 taskbar and select one of those "recent files".

    Beyond that, I'm not sure I see the problem.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    Join Date
    Feb 2006

    Re: Automatically Load most recent project at startup?

    In Explorer you can right-click the .VBP file and choose Send to|Desktop (create shortcut) which is at least another alternative that properly sets CD when VB6.exe is started.

    Oops, I duplicated that suggestion.

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013

    Re: Automatically Load most recent project at startup?

    I have the IDE in the taskbar (edit: it isn't called the toolbar) and pinned my favourite projects in the recent list.
    Instead of left click on VB6 icon I do a right click and select the desired project
    Last edited by Arnoutdv; Sep 29th, 2020 at 02:25 AM.

  7. #7
    Hyperactive Member
    Join Date
    Aug 2017

    Re: Automatically Load most recent project at startup?

    Quote Originally Posted by OptionBase1 View Post
    I would imagine creating an add-on to do this should be feasible, ...
    Here it is:

    Option Explicit     'Connect.dsr
    Private Declare Function SetWindowsHookExW Lib "user32.dll" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hMod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
    Private m_AfterStartup As Boolean
    Private m_hHook        As Long
    Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
        If m_AfterStartup Then AddinInstance_OnStartupComplete custom()
    End Sub
    Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
        Const WH_CBT = 5&
        Set g_VBE = Application
        g_ConnectMode = ConnectMode
        If ConnectMode = ext_cm_Startup Then
           'If the "New Project" dialog pops up, cancel it and open the last project instead, if it exists
            m_hHook = SetWindowsHookExW(WH_CBT, AddressOf CBTProc, 0&, App.ThreadID): Debug.Assert m_hHook
            If Not OpenLastProject Then MsgBox Err.Description, vbCritical
           'Can't unload yet in this event so will have to wait until the OnAddInsUpdate event
            m_AfterStartup = True
        End If
    End Sub
    Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
        If m_hHook Then m_hHook = UnhookWindowsHookEx(m_hHook): Debug.Assert m_hHook
    End Sub
    Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
        Dim MyProgID As String, AddIn As VBIDE.AddIn
        On Error Resume Next
        Err.Raise vbObjectError
        MyProgID = Err.Source & "." & TypeName(Me)
        On Error GoTo 0
        For Each AddIn In g_VBE.Addins
            If AddIn.ProgId = MyProgID Then
                AddIn.Connect = False       'Disconnect (unload) automatically after completing the job
                Exit For
            End If
    End Sub
    Option Explicit     'Module1.bas
    Option Compare Text
    Private Declare Function CallNextHookEx Lib "user32.dll" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function GetClassNameW Lib "user32.dll" (ByVal hWnd As Long, ByVal lpClassName As Long, ByVal nMaxCount As Long) As Long
    Private Declare Function GetModuleFileNameW Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpFilename As Long, ByVal nSize As Long) As Long
    Private Declare Function GetWindowLongW Lib "user32.dll" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SysReAllocStringLen Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As Long
    Public g_ConnectMode As AddInDesignerObjects.ext_ConnectMode
    Public g_VBE         As VBIDE.VBE
    Public Function CBTProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Const HCBT_CREATEWND = 3&, GWL_STYLE = (-16&), WS_CHILD = &H40000000
        If nCode = HCBT_CREATEWND Then
            If (GetWindowLongW(wParam, GWL_STYLE) And WS_CHILD) <> WS_CHILD Then
                If GetClassName(wParam) = "#32770" Then
                    If GetModuleName(wParam) Like "*\comdlg32.dll" Then
                        If OpenLastProject Then
                            CBTProc = True
                            Exit Function
                        End If
                    End If
                End If
            End If
        End If
        CBTProc = CallNextHookEx(0&, nCode, wParam, lParam)
    End Function
    Public Function OpenLastProject() As Boolean
        Const LAST_PROJECT = "HKCU\Software\Microsoft\Visual Basic\6.0\RecentFiles\1"
        Dim sLastProjectPath As String
        On Error Resume Next
        With New WshShell
            sLastProjectPath = .RegRead(LAST_PROJECT)
        End With
        If LenB(sLastProjectPath) Then
            g_VBE.VBProjects.AddFromFile sLastProjectPath, Exclusive:=g_ConnectMode = ext_cm_Startup
            OpenLastProject = Err = 0&
        End If
    End Function
    Private Function GetClassName(ByVal hWnd As Long) As String
        Const MAX_CLASS_NAME = 256&
        SysReAllocStringLen VarPtr(GetClassName), , MAX_CLASS_NAME
        SysReAllocStringLen VarPtr(GetClassName), StrPtr(GetClassName), _
        GetClassNameW(hWnd, StrPtr(GetClassName), MAX_CLASS_NAME + 1&)
    End Function
    Private Function GetModuleName(ByVal hWnd As Long) As String
        Const GWL_HINSTANCE = (-6&), MAX_PATH = 260&
        SysReAllocStringLen VarPtr(GetModuleName), , MAX_PATH - 1&
        SysReAllocStringLen VarPtr(GetModuleName), StrPtr(GetModuleName), _
        GetModuleFileNameW(GetWindowLongW(hWnd, GWL_HINSTANCE), StrPtr(GetModuleName), MAX_PATH)
    End Function
    Compile the attached add-in project to a permanent location (e.g., the VB6 directory).
    Attached Files Attached Files

  8. #8
    Frenzied Member
    Join Date
    Dec 2008
    Melbourne Australia

    Re: Automatically Load most recent project at startup?

    Use a File manager (with Tabs).
    XYPlorerFree can be used as a portable program, so you could have one (or more) XYPlorers with Tabs for various (VB project) folders.
    If you are rich, you could use DO (Directory Opus).
    I just have one instance of that running all the time.
    It brilliantly has a feature called Tab Groups, so you can have a Tab Group for all your current VB projects
    You might have more than one set of VB projects (I do)
    DO can additionally have a tree hierarchy within the Tab Groups.
    To switch to another Tab Group, all you have to do is right click the Tab bar, and you are presented with a menu of your Tab Groups to choose from.
    I was a senior IT Systems Analyst for 20 years, and could not design a better program.
    There is a learning curve with DO, but it is worth the effort (and cost)


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