only for RuBoard - do not distribute or recompile |
We start by adding a class called clsQueryInfo to the RadEx project. The class implements IQueryInfo and IPersistFile . Example 10.2 is the project listing. It's really short, so let's walk through the whole thing.
'clsQueryInfo.cls Implements IPersistFile Implements IQueryInfo Private m_sFile As String Private Sub IPersistFile_Load( ByVal pszFileName As VBShellLib.LPCOLESTR, _ ByVal dwMode As VBShellLib.DWORD) m_sFile = Space(255) CopyMemory ByVal StrPtr(m_sFile), ByVal pszFileName, Len(m_sFile) End Sub Private Sub IQueryInfo_GetInfoTip( ByVal dwFlags As VBShellLib.DWORD, _ ppwszTip As VBShellLib.LPWSTRVB) Dim b( ) As Byte Dim sTemp As String sTemp = Space(255) Dim sMsg As String GetPrivateProfileString "Animal", _ "Type", _ "Unknown", _ sTemp, _ Len(sTemp), _ m_sFile sMsg = "Type: " & sTemp & vbCrLf ppwszTip = StrPtr(sMsg) End Sub
First, let's get IPersistFile::Load out of the way. This should be very familiar to you, since we have already implemented Load for icon handlers, drop handlers, and data handlers. InfoTip handlers are no different: we simply copy the name of the selected file, which is passed to the Load method in the pszFileName argument, to a local variable, m_sFile .
To complete the implementation of IPersistFile , you can just add the following line of code for the remainder of the methods :
Err.Raise E_NOTIMPL
After you have implemented the remaining methods of IPersistFile , we can begin implementing IQueryInfo . And for once, we can breathe easy, because IQueryInfo could not be simpler to implement. Here's what happens: the shell calls GetInfoTip and passes us a pointer to a buffer that we can copy the InfoTip into.
The pointer to the tool tip function is declared with the [in, out] attribute, so we can just assign the pointer to our InfoTip right to ppwszTip . We don't have to use CopyMemory . That's all there is to it.
Well, we actually have to register the handler, and that's done a little bit differently than in previous chapters. The handler is registered under the file association key, not the application identifier. Also, the handler is not named. It uses the CLSID for IQueryInfo as the key name. The default value of this key points to our InfoTip handler. Figure 10.2 shows the appropriate entries.
This is the only entry that needs to be made for the InfoTip handler. It does not have to be added to the approved shell extensions list. The following registry script will register the example for this chapter:
REGEDIT4 [HKEY_CLASSES_ROOT\.rad] @ = "radfile" [HKEY_CLASSES_ROOT\.rad\shellex\ {00021500-0000-0000-C000-000000000046}] @ = "{1CBC449C-065A-11D3-BB7C-444553540000}"
|
Before trying out the handler, you should restart the shell.
only for RuBoard - do not distribute or recompile |