How to implement advanced custom properties in VB6 usercontrols? - com

Sorry I don't know how to name it other than "advanced custom properties". If I know, I would search it first.
I am dealing with a legacy code using 3-rd party controls.
In VB6, When you drag that control onto the form, you can see all the properties supported by the control in the "Properties" window. Such as MarginLeft, MarginRight etc. etc.
That's no problem.
In the "Property" window, the top-most property is generally the "(Name)" field, which is the name of the control.
But the 3-rd party control I am using, has another two "fake properties" above "(Name)", which are "(About)" and "(Custom)".
When you click "(About)", there will be a dialog box showing the company info. When you click "(Custom)", there will be another dialog box showing more properties. These dialog boxes are shown in VB6.
In the "(Custom)" dialog box, you can modify normal properties (same as modifying directly in the Property window). You can do more. There are more properties that are not normal properties (at least you cannot find anything in the Property window).
When you save this form, for normal properties, everything are saved into .FRM file. E.g.,
Control1.MarginLeft = 5
Control1.Text = "I am a control"
However, for the "advanced properties" edited in the (Custom) dialog box, they are not saved in .FRM, they are saved in .FRX in binary format.
E.g., in (Custom) dialog box, you can edit a property called "Caption", which includes text of this caption, the font, the weight, the display style, and a lot of similar properties for Caption. In .FRM, it is something like,
Control1.Caption = "frmForm1.frx":013F
All the text and related properties of Caption are saved in binary format in .FRX file.
Note that, there's no Caption property in the normal Property window, you can only edit it in the "(Custom)" dialog box.
My question is as follows,
How to implement such a (Custom) dialog box that can be shown in VB6?
How to let VB6's Property window display (About) and (Custom)?
How to tell VB6 that Caption property shall not be displayed in Property window, but you can use directly in code as Control1.Caption = xxxx.frx:offset?
How to tell VB6 that this Caption property shall be saved in .FRX, and how to tell VB6 the size of the data, so that VB6 can manages the offset automatically?
How to load the data automatically via VB6 so that the correct values can be displayed in (Custom) dialog box?
As far as I know, .frx formats are secrets, there are a lot of ppl digging into various .frx for standard controls such as Binary(images), List, and Text. I am curious how can a 3-rd party control utilizing .frx, shall the 3-rd party control define its own .frx format? Including for example, how many bytes in front for Length (or no length field at all, it's fixed length), how many bytes for style1, how many bytes for style2, etc.
Thanks a lot. If you know what proper name it is for this "advanced properties", just tell me the name and I can search myself.
I tried to search for advanced properties but didn't really get anything I want to know.

The frx files are for binary or other non-basic data types. The frm will store the simple properties. What you need to do is to hook into the UserControl events WriteProperties and ReadProperties. You don't need to know where the backing storage is (frm vs frx)., you just need to access the PropBag to read and write your data.
Google is your friend to find the documentation:
https://msdn.microsoft.com/en-us/library/aa242140(v=vs.60).aspx
Or additional information on the topic:
http://www.vbforums.com/showthread.php?365735-Classic-VB-How-do-the-ReadProperties-and-WriteProperties-work-(PropertyBags)&s=3cfbd675928ad1eb94f68fbfb13ccd88&p=3672781&viewfull=1#post3672781
Good luck!

Related

How to navigate to specific contents of madcap flare's document from vb.net code?

We have been using PDF file as a part of help docs in our vb.net desktop application. In PDF, we would traverse to the certain chapter in the PDF doc.
Now we have decided to use MadCap Flare as documentation tool. We have a menu item in vb.net form for documentation. On click of the link, we want to open the specific chapter of the Flare documentation.
You know managing content with single-source XML authoring is possible when using MapCad Flare (I'm not using Flare!). You can publish content to an increasing number of formats including HTML5, WebHelp, PDF, Word, XHTML, Clean XHTML, EPUB, DITA and more by MapCad Flare.
So, you may continue using PDF and the way connecting your vb.net desktop application help.
Using HTML based topics maybe another solution for your needs by creating Help for a form, a dialog or control with HTML files (See also: Help for controls with VB .NET).
Properties to display help (HTML file - local)
Activate the hlpProvider component hlpHtmlLocal and set the HelpNameSpace property of hlpHtmlLocal to the file name you want to work with.
We open a local HTML file with the dialog using the little button to the right.
The next step is to set the HelpNavigator property of a control (e.g. button) to a value of the HelpNavigator enumeration (see table below). Here we use Topic.
When the application is running click the HelpButton to enable "What's this .." Help. The cursor changes. Now click the button or press F1 when the button has focus. This will open the single HTML file in your browser.
It seems you can't use anchor names to jump to a specific part of your HTML file.
Properties to display help (HTML file - Server http://..)
Activate the hlpProvider component and set the HelpNameSpace property of hlpHtmlServer to the file name you want to work with. Here we use a http:// address of a single HTML file. If you provide the file on your company server, you don't have to update the help file with the customer.
The next step is to set the HelpNavigator property of a control (e.g. button) to a value of the HelpNavigator enumaration (see table below). Here we use Topic. Then we set the HelpKeyword on hlpHtmlSever property to e.g. "anchor3". Don't add a leading "#". Leave it empty if you want to open a HTML file without anchors. The Help Handles cmdControl2.Click Dim sHelpFile As String Dim sStartupPath As String '--- Initialize context-sensitive help --- Keyword property provides the key information to retrieve the help associated with the control.
When the application is running click the HelpButton to enable "What's this .." Help. The cursor changes. Now click the button or press F1 when the button has focus. This will open the single HTML file over the Internet in your browser.

VBA Adding a User Defined Control to Userform at Runtime

So I've made the following control in Design Mode then added the control to a new page Custom in my toolbox.
Now, what would I use for the progID parameter in Controls.Add()? How do I look up this value? Controls.Add("Forms.Frame.1") adds a regular frame, not the desired custom control.
As far as I am aware, you do not generate a new progID with a custom control. Per the MSDN documentation for custom/modified controls:
Note: When you drag a control onto the Control Toolbox, you only transfer the advanced property values.
So only the properties are transferred; the actual control is still of the same type/s as the one you created it from. Further, it looks like this progID is "a unique system-wide string that the Windows operating system can use to identify your control's type." So unless you are up to coding your own control, it looks as though you're just passing properties to the custom toolbox controls you create there.
You'll have to just replicate the custom control each time you want to add it. Just create a sub with all the correct properties and call it. Not what you were looking for, but it'll get the job done.

How Can I Comprehensively Manage my VBA UserForm's Properties?

I am writing my first VBA Add-In under Microsoft Office Word 2007 with Windows 7 Pro/64. Part of this Add-In is a UserForm. Using the Visual Basic editor that runs from Word, I find there are two ways of viewing, and two ways of modifying a UserForm's properties:
View all properties from Object Browser (F2)
View some properties and edit them from Properties Window (F4)
Manually enter and edit any property from the Code window (F7)
Here is a screenshot of my Properties and Code windows:
A problem I find is that the Properties Window contains only a subset of the UserForm's properties (notice that CanPaste, CanRedo, and CanUndo don't appear in Properties), and changes made in the Properties Window are overridden by changes made in the Code window (e.g., at runtime, Me.Caption from the Code window above overrides the Caption field in Properties).
I suppose I should avoid using Properties at all then, and enter all settings via UserForm_Initialize as shown above. But (a) for some settings, Properties makes several settings at once. For example, selecting Verdana Bold from Properties equals Font = Verdana and Font.Bold = True in Code. And (b) it seems Properties sets the subset of properties it controls to defaults of its choosing, and if I change them I can't see what they started out as.
I therefore desire unified and comprehensive access to all my UserForm's properties at once, including the aforementioned default settings. Does anyone know how to reveal a UserForm's default settings as code, or to automatically open all its current settings in the Code window? Is there an umbrella mechanism I'm not aware of?
I'm not a veteran VBA programmer, but I can't believe my experience is unique. I've searched the 'net in vain for a solution. How do you with more experience manage this dilemma?
You use the Properties window to set appearance-related properties at design time. Those property values will then always apply unless you explicitly change them at run-time with VBA code.
Properties that don't relate to appearance, such as CanPaste and CanRedo relate to the state of the form at run-time, so it doesn't make sense to have them configurable at design-time.
You can change nearly all of the properties at run-time, whether it is in the Initialize event or elsewhere. You can even add controls at run-time, but your changes won't be persisted once the instance of the form terminates.

Where does Windows Search look for file properties?

We've implemented a shell property handler for a custom file format, with some standard properties and some custom. When we browse our files in Explorer our properties display nicely, but when our files appear in search results they don't. It seems that Explorer isn't querying our property handler when it displays search results.
My question is this: When Explorer displays an item in search results, where does it look for the item's properties? Does it query the appropriate handler, or does it look somewhere in some kind of search cache?
If it queries the handler then I'll investigate why our handler isn't called. (Maybe it's a registration fault.) If it looks in a search cache then I'll investigate why our files aren't indexed properly.
A secondary question: Is the search results pane restricted to a limited subset of the standard properties? In other words, should we just give up trying to display interesting properties here?
Some observations:
Our file format is just .msg (Outlook email message) renamed to .msga. Our handler knows how to read the .msg file format.
Property values display correctly in Browse mode.
They don't display in Search mode.
Property values are displayed correctly in Explorer's details pane, in either mode.
Some standard properties display OK in the search results, but not others, and no custom properties do. For example, these all display OK but are not served by our handler: System.ItemName, System.ItemUrl, System.Size, System.DateCreated. These are available in our handler but do not display: System.Title, System.Message.FromAddress, System.Message.DateSent.
Explorer is clearly reading our HKCR\<progid> registry key, because the display adapts as we edit ContentViewModeForSearch etc.
Our .msga file type is listed in Control Panel as an indexed file type, and our files are in an indexed directory. And I rebuilt the entire index this morning.
We haven't implemented a filter. Control Panel says that it's using "Office Outlook MSG IFilter" for .msga. (I don't know how it figured this out - maybe I copied a registry setting early in the project, or maybe Windows inferred it because we use Outlook for preview.)
Our handler implements IPropertyStore but its methods seem never to be called. (We've implemented some logging, to a file that the search indexer should have access to, but we can't be sure about that.)
Event Viewer shows gatherer error 3036 during indexing: "The content source <csc://{S-1-5-21-2153095834-1917727522-598830505-500}/> cannot be accessed." I think that SID is my user account, and so I wonder whether it's trying to index something to which it doesn't have privileges.

Text selected / right click event (Outlook 2007 VBA)

I'm looking for an event that's raised when a user selects text in the preview pane of an email. E.g. you're viewing an email in the preview pane and select some text. I didn't see anything in the object reference to this effect, but the namespace is so large, it seems like there's always some object somewhere that does exactly what I need, which I'm not aware of.
Overall, what I'd like to do is see if the selected text matches a pattern and if so, insert a sub-menu in the right click menu (the one that says Copy, Who Is, Synonyms, Translate..). Help with this would be appreciated too. I believe the CommandBar is "text", but I'm unsure how to go about accessing this via name.
The Outlook object model doesn't provide anything for that.