-
Jan 19th, 2021, 04:30 PM
#1
Code snippet (for Add-In) to fix .vbw (workspace) issue
It didn't seem worthwhile creating an Add-In just for this (it seems more appropriate that it be incorporated into other addins), hence posting as a snippet...
Don't know about anybody else, but the IDE's insistence, upon opening a project, of randomly restoring windows, is one VB6 development annoyance that I've lived with for a long time.
Anyway, whilst in the process of developing a related Add-in, I applied my new-found familiarity with the IDE object model, to come up with this:
Somewhere in your Add-In, you'll need a reference to VBIDE.VBProjectsEvents
e.g.
Code:
Private WithEvents mProjectEvents As VBIDE.VBProjectsEvents
...
Private Sub mProjectEvents_ItemRemoved(ByVal VBProject As VBIDE.VBProject)
SaveVBWFile VBProject
End Sub
...and the following code, which you can put in a module (or wherever)
Code:
Option Explicit
Private Declare Function DeleteFileW Lib "kernel32" (ByVal lpFileName As Long) As Long
Public Sub SaveVBWFile(ByRef VBProj As VBProject)
Dim FileNo As Integer
Dim FilePath As String
Dim s() As String
Dim ComponentName As String
Dim W As VBIDE.Window
FilePath = Replace(VBProj.FileName, ".vbp", ".vbw")
DeleteFileW (StrPtr(FilePath))
FileNo = FreeFile
Open FilePath For Output As #FileNo
For Each W In gVBInstance.Windows
'Window captions take the form 'Project Name - Component Name (type suffix)', where Project name
'can be absent if the Component belongs to the Active Project
If W.Type = vbext_wt_CodeWindow Then
'strip the suffix - we're not intersted in that
s = Split(W.Caption, " (")
'If Project name is missing, add it in
If InStr(s(0), " - ") = 0 Then s(0) = gVBInstance.ActiveVBProject.Name & " - " & s(0)
'Now attempt to replace the Project Name...
ComponentName = Replace(s(0), VBProj.Name & " - ", vbNullString)
'...if that worked, we are interested in this Window
If InStr(ComponentName, " - ") = 0 Then
Print #FileNo, ComponentName & " = " & W.Left & "," & W.Top & "," & W.Width & "," & W.Height & ",0,0,0,0,C"
End If
End If
Next W
Close #FileNo
End Sub
It's not perfect, as it won't allow you to save vbw data for Designer Windows. Unfortunately, by the time mProjectEvents_ItemRemoved fires, all such windows have already been destroyed. Still, I can live with that versus the chaos that the IDE sometimes inflicts on me.
Last edited by ColinE66; Jan 19th, 2021 at 04:39 PM.
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Jan 19th, 2021, 05:47 PM
#2
Hyperactive Member
Re: Code snippet (for Add-In) to fix .vbw (workspace) issue
very interesting utility for the ide.
I for small utilities for the ide use add-in with small plugins.
https://www.vbforums.com/showthread....VB6&highlight=
a greeting
-
Jan 19th, 2021, 07:46 PM
#3
Re: Code snippet (for Add-In) to fix .vbw (workspace) issue
Hello. I directly made an Add-In that deletes the *.vbw files.
Also, posted this one to study IDE events (that might be of interest).
-
Jan 19th, 2021, 08:14 PM
#4
Re: Code snippet (for Add-In) to fix .vbw (workspace) issue
Hi Eduardo,
Thanks, but I don't want to delete the vbw file - I just want it to correctly restore the windows that I had open, which it often fails to do! I'm currently writing a Tab-Strip addin, and therefore need the vbw to behave as expected so that the correct tabs are displayed when a project is opened.
Thanks for the other link, but I've already gained a pretty good understanding of the IBE event handlers. There's a few things missing, though, unfortunately. Like there's no way of knowing when the active Code Pane has changed, for example.
I can pm you a link if you'd like to see where I'm up to. I know you are an occasional Add-In developer yourself. This one is my first attempt...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Jan 19th, 2021, 08:59 PM
#5
Re: Code snippet (for Add-In) to fix .vbw (workspace) issue
Originally Posted by ColinE66
Hi Eduardo,
Thanks, but I don't want to delete the vbw file - I just want it to correctly restore the windows that I had open, which it often fails to do!
Ah, OK. I never noticed that the windows failed to restore properly, but really never cared about that feature, in fact before I had the delete *.vbw Add-in running, most of the times I manually closed all opened windows before closing the IDE or just after starting it.
Originally Posted by ColinE66
I'm currently writing a Tab-Strip addin, and therefore need the vbw to behave as expected so that the correct tabs are displayed when a project is opened.
Yes, in that case it becomes important (and not annoying)
Originally Posted by ColinE66
Thanks for the other link, but I've already gained a pretty good understanding of the IBE event handlers. There's a few things missing, though, unfortunately. Like there's no way of knowing when the active Code Pane has changed, for example.
No... The Add-in environment seems a bit limited/underdeveloped sometimes. In my sample project I think I used all the events.
Perhaps you'll need to subclass the Edit control.
Originally Posted by ColinE66
I can pm you a link if you'd like to see where I'm up to. I know you are an occasional Add-In developer yourself. This one is my first attempt...
Yes, I am occasional, I didn't do much with Add-Ins, just some things I needed/wanted.
OK, PM if you would like to share something.
I never did anything regarding code modules/panes, just dealt with designers and controls so far.
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
|