Browser Launcher

Currently I use multiple browsers to complete my assigned task.  To accomodate multiple browsers a block of code was created.

The main method is listed below.

[codesyntax lang=”cpp”]

void DlgTstFrame::fireBrowser(string bn)
{
//  bn is the variable that holds the browser name

    string url = checkForURL(); // check the clipboard for a URL

    if (url > "")
    {
        Xqt(bn + " " + url);  // If the URL is present on the clipboard use that URL

    }
    else
    {
        Xqt(bn); // Start the browser without a URL designation

    }

}

[/codesyntax]

The check for URLfunction is listed below.

[codesyntax lang=”cpp”]

string DlgTstFrame::checkForURL()
{
    string url = "";
    wxTextDataObject data;
    // Read some text
    if (wxTheClipboard->Open())
    {
        if (wxTheClipboard->IsSupported(wxDF_TEXT)) // Does text exists on the clopboard?
        {
            wxTextDataObject data;
            wxTheClipboard->GetData(data);
            url = data.GetText().ToStdString(); // Place the clipboard contents in the variable URL
            if (url.find("http") == 0) // Is the string "http" in the first four characters of the string?
            {
                wxTheClipboard->Close(); // Close the clipboard
                // The clipboard contains a URL
                return url;
            }
            else
            {
                wxTheClipboard->Close(); // Close the clipboard
                // No URL was detected so return a null string
                return "";
            }
        }
    }
    wxTheClipboard->Close(); // Close the clipboard
}

[/codesyntax]

This utility will work for any number of browsers.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *