Contact

admin

About Me · Send mail to the author(s) E-mail · Twitter

At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.

Feed Icon

Tags

Open Source Projects

Archives

Blogs of friends

Now playing [?]

Error retrieving information from external service.
Audioscrobbler/Last.fm

ClustrMap

A little Application to extend PC-Bibliothek

Posted in Tools and Software at Saturday, October 29, 2005 7:01 PM W. Europe Daylight Time

PC-Bibliothek is a powerful (and yet not LUA-compatible [1]) application that acts as your personal digital library. There's a wide variety of extensions like dictionaries and encyclopaedias available.

PC-Bibliothek Screenshot

One drawback that bugged me for the last months is that there's no documented way to hand over a search string to the application. You'll either have to type or copy/paste the search term or use their annoying tray application to perform a quick search. Not to speak of browser integration. This application is virtually isolated from the rest of the world. And yet I like it for it's outstandingly good content.

This is when the dev in me awakes :-) I've written a little app, PCBibStarter, that's able to invoke PC-Bibliothek and set the search term in the "Search for" edit box. I had to do it the dirty way by using the FindWindowEx and SendMessage APIs. After PC-Bibliothek has started up, the app searches for the edit box that contains the search term. When the window has been found it sets the search term that has been passed to PCBibStarter as command line arguments.

private void SetKeyword(Process process, string keyword)
{
    
using(process)
    {
        
try
        {
            
// Wait for process to get idle (i.e. started up).
            if (process.WaitForInputIdle())
            {
                // Search tree of windows.
                ...
                




                
// Set search keyword.
                IntPtr result = NativeMethods.SendMessage(parent, NativeDeclarations.WM_SETTEXT, IntPtr.Zero, keyword);
                
if (result == IntPtr.Zero)
                {
                    
throw new ApplicationException(...);
                }
            }
            
else
            {
                
throw new ApplicationException(...);
            }
        }
        
catch(Exception ex)
        {
            MessageBox.Show(ex.ToString(),
...);
        }
    }
}

PCBibStarter reuses already running instances of PC-Bibliothek and sets the search terms accordingly. PC-Bibliothek now integrates well into SlickRun where I can type something like "bib my search term" to get PC-Bibliothek searching for "my search term" ("bib" acts as the magic word). Another nice feature is the browser integration I am now able to come up with.

PCBibStarter Browser Integration

This is accomplished by putting a JavaScript file besides the PCBibStarter executable that extracts the selected text out of a browser window using IE's DOM. PCBibStarter is then launched with the text as the command line argument. The JavaScript file has to be registered with IE by adding a key under HKCU\Software\Microsoft\Internet Explorer\MenuExt in the Registry.

Almost the whole setup is done by the installer. However, there are two files you'll have to tweak. First, there's PCBibStarter.exe.config that tells the location of your PC-Bibliothek installation.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="Executable" value="C:\Programme\PC-Bibliothek\pcbib_bi.exe" />     </appSettings> </configuration>

Secondly, the JavaScript file containing the browser integration code, PCBibStarter.js, has to be adjusted to match the path of PCBibStarter. Note the double backslashes.

shell.ShellExecute("C:\\Programme\\PC-Bibliothek Starter\\PCBibStarter.exe", selectedText, "", "open", "1");

DownloadHere are the files:

[1] PC-Bibliothek stores its settings in an ini file inside of %ProgramFiles%. Limited User Accounts (LUAs) are not allowed to write to this location by default.

All comments require the approval of the site owner before being displayed.
(will show your gravatar icon)
 
[Captcha]Enter the code shown (prevents robots):

Live Comment Preview