На любое нажатие (не важно, обрабатываю я его через ActionList или через onKeyPress формы) плагин почему-то реагирует дважды, подряд то есть два раза.
Вот такой код без всего лишнего:
lpr
- Код: Выделить всё
library examp;
{$mode objfpc}{$H+}
uses
Windows, SysUtils, Forms, Interfaces, umain
{ you can add units after this };
const
PARSE_FUNCTION = 'SIZE>23';
procedure ListGetDetectString(DetectString: PChar; MaxLen: integer); stdcall;
begin
StrLCopy(DetectString, PChar(PARSE_FUNCTION), MaxLen);
end;
function ListLoad(ListerWin: HWND; FileToLoad: Pchar; ShowFlags: integer): HWND; stdcall;
begin
Result := TfmMain.PluginShow(ListerWin, FileToLoad);
end;
procedure ListCloseWindow(PluginWin: HWND); stdcall;
begin
TfmMain.PluginHide(PluginWin);
end;
exports
ListGetDetectString,
ListLoad,
ListCloseWindow;
begin
Application.Initialize;
end.
pas
- Код: Выделить всё
unit umain;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, Controls, LclType, Windows, Dialogs;
type
{ TfmMain }
TfmMain = class(TForm)
procedure FormKeyPress(Sender: TObject; var Key: char);
private
{ private declarations }
FTotCmdWin: HWND; // handle of TotalCommander window
FParentWin: HWND; // handle of Lister window
FQuickView: Boolean; // Ctrl+Q panel protected
procedure CreateParams(var Params: TCreateParams); override;
public
{ public declarations }
constructor CreateParented(AParentWindow: HWND);
class function PluginShow(ListerWin: HWND; FileToLoad: string): HWND;
class function PluginHide(PluginWin: HWND): HWND;
procedure InFileOpen(ImageFileName: String);
end;
implementation
{$R *.lfm}
{ TfmMain }
procedure TfmMain.FormKeyPress(Sender: TObject; var Key: char);
begin
if (Key='K') or (Key='k') then ShowMessage('Key K Pressed');
end;
procedure TfmMain.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := (WS_CHILD or WS_MAXIMIZE) and not WS_CAPTION and not WS_BORDER;
Params.WindowClass.cbWndExtra := SizeOf(PtrInt);
end;
constructor TfmMain.CreateParented(AParentWindow: HWND);
begin
inherited CreateParented(AParentWindow);
FTotCmdWin := FindWindow('TTOTAL_CMD', nil);
FParentWin := AParentWindow;
FQuickView := Windows.GetParent(FParentWin) <> 0;
end;
class function TfmMain.PluginShow(ListerWin: HWND; FileToLoad: string): HWND;
var
fmMain: TfmMain;
begin
fmMain := nil;
try
fmMain := TfmMain.CreateParented(ListerWin);
//fmMain.InFileOpen(FileToLoad);
fmMain.Show;
SetWindowLongPTR(fmMain.Handle, GWL_USERDATA, PtrInt(fmMain));
// set focus to our window
if not fmMain.FQuickView then
begin
PostMessage(fmMain.Handle, WM_SETFOCUS, 0, 0);
fmMain.SetFocus;
end;
Result := fmMain.Handle;
except
if Assigned(fmMain) then
fmMain.Free;
Result := 0;
end;
end;
class function TfmMain.PluginHide(PluginWin: HWND): HWND;
var
fmMain: TfmMain;
begin
Result := 0;
fmMain := TfmMain(GetWindowLongPTR(PluginWin, GWL_USERDATA));
try
fmMain.Close;
fmMain.Free;
except
end;
end;
procedure TfmMain.InFileOpen(ImageFileName: String);
begin
end;
end.
lfm
- Код: Выделить всё
object fmMain: TfmMain
Left = 397
Height = 240
Top = 223
Width = 320
BorderStyle = bsNone
Caption = 'fmMain'
KeyPreview = True
OnKeyPress = FormKeyPress
LCLVersion = '1.6.0.4'
end
Устанавливаем, открываем по F3 практически любой файл, жмем K, читаем сообщение об этом, кликаем ОК и... снова читаем сообщение о том, что нажали К...
Почему так?