Multiple intances of lister with plugin

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
ZiPo
Junior Member
Junior Member
Posts: 10
Joined: 2004-09-25, 12:03 UTC

Multiple intances of lister with plugin

Post by *ZiPo »

I'm trying to figure out a smart way to handle multiple lister instances so that i can have more than one lister window open at the same time...the following code works if lister is opened one time...when opening more than one, the errors come when closing those lister windows again. It simply crashes. I thought of using some sort of TList to store window handles and only destroy the right one in ListClose, but can't figure out how to do it, so a little help would be great! Maybe someone have some good examples on how to handle multiple lister windows ??

Code: Select all

function ListLoad(ParentWin: THandle; FileToLoad: PChar; ShowFlags: Integer): THandle; stdcall;
begin
  frmMain := TfrmMain.CreateParented(ParentWin);

  frmMain.Show;
  frmMain.SetFocus;

  Result := frmMain.Handle;
end;

procedure ListCloseWindow(ListWin: THandle); stdcall;
begin
  frmMain.Close;
  frmMain.Free;
end;
It compiles..Let's ship it!
poiuytr
Senior Member
Senior Member
Posts: 243
Joined: 2003-02-23, 17:33 UTC

Post by *poiuytr »

Your problem is that you are using global variable frmMain.

AFAIK you can obtain a pointer to your form from handle by using VCL function FindControl.
Check this code, port it to delphi

Code: Select all

extern "C" void __export WINAPI ListCloseWindow(HWND ListWin)
{
  TWinControl *pWinControl = FindControl(ListWin);
  if (pWinControl->ClassNameIs("TForm1"))
  {
     // this is my form
    delete (TForm1*)pWinControl;
  }
}
ZiPo
Junior Member
Junior Member
Posts: 10
Joined: 2004-09-25, 12:03 UTC

Post by *ZiPo »

Thanks alot poiuytr (easy to type nick huh ? :))

Converted your code to delphi and it works like a charm!

Code: Select all

procedure ListCloseWindow(ListWin: THandle); stdcall;
var
  pWinControl: TWinControl;
begin
  pWinControl := FindControl(ListWin);
  if pWinControl.ClassNameIs('TfrmMain') then
    pWinControl.Free;
end;
It compiles..Let's ship it!
poiuytr
Senior Member
Senior Member
Posts: 243
Joined: 2003-02-23, 17:33 UTC

Post by *poiuytr »

ZiPo wrote:Converted your code to delphi and it works like a charm!
Sweet 8)
Post Reply