How to show your own custom popup in TWebBrowser component

If you want to show your custom popup menu in your TWebBrowser component I really recommend to you to download a EmbeddedWB component by bsalsa productions ( <http://www.bsalsa.com/product.html> ).
It is all the same TWebBowser only more user friendly, with more events and methods, added functionality.
By the way, it is all free.

With this EmbeddedWB you can easily make your own popup menu, even diffrent pop-ups for different selected items in web browser.

So for example, make a default popup when no selection exists, and one custom popup for selected text.

If you have EmbeddedWB installed and have one on your form, look for OnShowContextMenu event.

Then your custom popup can be shown with this example code:

function TForm.WebShowContextMenu(const dwID: Cardinal;

  const ppt: PPoint; const pcmdtReserved: IInterface;

  const pdispReserved: IDispatch): HRESULT;

begin

  //When we want to show our custum menu

  if (dwID = 4) //any text selection menu is about to show

    then begin

      TextPopup.Popup(ppt.X,ppt.Y);

    end

    else

      if Assigned(MyPopup) //if our popup is created

         then begin

           MyPopup.Popup(ppt.X, ppt.Y);

           Result := S_OK; //don't show WB popup

         end

         else Result := S_FALSE; //else show IE Popup

end;

 

IE has several different menus for images, text and so on. You can check what menu is about to show by

checking dwID:



CONTEXT_MENU_DEFAULT = 0;

CONTEXT_MENU_IMAGE = 1;

CONTEXT_MENU_CONTROL = 2;

CONTEXT_MENU_TABLE = 3;

CONTEXT_MENU_TEXTSELECT = 4;

CONTEXT_MENU_ANCHOR = 5;

CONTEXT_MENU_UNKNOWN = 6;

CONTEXT_MENU_IMGDYNSRC = 7;

CONTEXT_MENU_IMGART = 8;

CONTEXT_MENU_DEBUG = 9;

More info can be found here:

http://msdn2.microsoft.com/en-us/library/aa753264.aspx

http://www.bsalsa.com/ewb_on_show_context.html

Hope, this was helpful.

Advertisements

How to uninstall Windows Desktop Search

Some notes about Windows Desktop Search, well, for some people it may be a very good tool. I thought it should help me a lot to find my files. But wait, what a resource eater this WDS is, and really after 2 years of using it I didn’t become satisfactory with search results at all.
So I decided to uninstall it. Everything should be as always when you uninstall any MS program – simple, but really not for WDS.
I uninstalled it from “Add/Remove programs” control panel. OK, finished, restart. WDS doesn’t start and seems gone.

But later, when I pressed F3 in MyPC for file searching, and instead of standard simple windows search I SEE all again Windows Desktop Search, damn… Seems, it wasn’t full uninstall. Then I thought, I will install it again a fresh copy, and then I will uninstall. I downloaded an WDS EN 3.01 version from Microsoft website. Installed it. Going to remove in “Add/Remove Programs”, well…. it shows no WDS is installed (even with “Show updates” option). WTF. Though it clearly runs with my every computer start. So how to get rid of this thing without reinstalling all my pc??

Searching the google…
I found some information from Microsoft:

http://www.microsoft.com/technet/prodtechnol/windows/search/dtstshoot.mspx .

But man I didn’t install neither MSN search toolbars, nor other MS stuff, just WDS. Not useful information.
Found some instructions from Kotsar Andrew:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1456784&SiteID=1 .

OMG you need to create a WDS uninstall information manually, because I didn’t find such uninstall information even in my Windows dir (it should be hidden system folder with $KB….). :((.
But then again I found a very good instructions here:

http://www.davidarno.org/2007/10/26/how-to-remove-windows-desktop-search/ .

Well seems I am not the only one here with WDS. Luckily I had another computer with WDS installed and uninstall information present there. So you need to copy that information to your Windows directory (for WDS 3.01 it should be $NtUninstallKB917013$, hidden system folder ) and manually run spuninst.exe. Then it should uninstall.


FileStream Create error in Delphi

Refresh I’ll share some tip on File Creation in Delphi. Some day I had to make a solution to create same file stream a lot times in a cycle and to show it at regular intervals (it was opened in another application). Well, if file is already created and time interval get’s too short, you might get an exception, that file is "in use on another process" and even setting file permissions doesn’t help:

   1: var File : TFileStream 

   2: File := TFileStream.Create(OutputFile, fmCreate or fmShareExclusive)

The solution is, first to check out if file is in use. We could use Windows API CreateFile function for this task:

   1: function IsFileInUse(FileName: TFileName): Boolean;

   2:   var HFileRes: HFILE;

   3: begin

   4:   Result := False;

   5:   if not FileExists(FileName) then Exit;

   6:   HFileRes := CreateFile( PChar(FileName), //Windows API Create

   7:     GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING,

   8:     FILE_ATTRIBUTE_NORMAL, 0);

   9:   Result := (HFileRes = INVALID_HANDLE_VALUE);

  10:   //returns false File handle if file is in use

  11:   if not Result then CloseHandle(HFileRes); //Deny and close handle

  12: end;

Then you can check if file is in use:

   1: if NOT IsFileInUse(OutputFile)

   2:    then File := TFileStream.Create(OutputFile, fmCreate or  fmShareExclusive);

update: Zarko Gajis from About.com made another universal function for checking if "FileIsInUse" here:

Programmatically Check If File is In Use – Delphi Code