Lazarus
Programming => Packages and Libraries => Ported from Delphi/Kylix => Topic started by: Anonymous on January 06, 2006, 01:43:56 pm
-
Hi!
I have problem with a tray icon program on win32.
The icon is created, but i can't get any messages from the tray icon.
If i use a local hook, it's works only on the mainform. I have a global hook too, but if i call a function from the dll, i get an error message:
Access Violation
Address : $00000000
Function : ??
I declarated the dll's functions this way:
pointer(InstallHook) := GetProcAddress(Handle, 'InstallHook');
pointer(UnInstallHook) := GetProcAddress(Handle, 'UninstallHook');
My dll source:
library keyboardhook;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, Windows, Messages;
var
HookHandle: Cardinal = 0;
WindowHandle: Cardinal = 0;
voltuzenet : boolean = False;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
//it's possible to call CallNextHookEx conditional only.
Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
case nCode < 0 of
TRUE: exit; //if code smaller 0 nothing has to be done
FALSE:
begin
Voltuzenet := True; // it means there is an message
end;
end;
end;
function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
begin
Result := False;
if HookHandle = 0 then begin
//First install the hook
HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,
HInstance, 0);
//Save the given window handle
WindowHandle := Hwnd;
Result := TRUE;
end;
voltuzenet := False;
end;
function UninstallHook: Boolean; stdcall;
begin
//Uninstall hook from hook chain
Result := UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;
function Volteuzenet : Boolean; stdcall;
begin
Result := voltuzenet;
end;
exports
//Export the installation and deinstallation routine
InstallHook,
UninstallHook,
Volteuzenet; // it means, there is an message
begin
end.
First i load the dll at the dynamic way:
procedure TForm1.Button8Click(Sender: TObject);
begin
lib := LoadLibrary('keyboardhook.dll');
if lib <> INVALID_HANDLE_VALUE then begin
//InstallHook := GetProcAddress(lib, 'InstallHook');
//UnInstallHook := GetProcAddress(lib, 'UninstallHook');
pointer(InstallHook) := GetProcAddress(Handle, 'InstallHook');
pointer(UnInstallHook) := GetProcAddress(Handle, 'UninstallHook');
pointer(Volteuzenet) := GetProcAddress(Handle, 'Volteuzenet');
end
else
begin
Showmessage ('Nem lehetett a dll-t betölteni!'); // it means : unlabe to load the dll
FreeLIbrary(lib);
end;
end;
After thet, i try to install the hook:
procedure TForm1.Button4Click(Sender: TObject);
begin
InstallHook(Form1.Handle);
end;
At this moment i get the error message :(
I have Lazarus 0.9.10beta, fpc 2.0.1.
I comlipped the dll, wiht the fpc 2.0.2 because the dll bug.
The Tray Program is compilled with the old fpc (fpc 2.0.1) because i try to compile the lazarus with the new fpc, and i get an error message.
What is wrong?
Is there any simlpe way to get a tray icon? Like a Component?
Thx.
Mammuth
ps: excuse me for my terrible english, i'm working on it
-
I have problem with a
What is wrong?
Is there any simlpe way to get a tray icon? Like a Component?
You may want to try TTrayIcon component. It features tray icons in an easy to use way, and is also multiplatform.
wiki.lazarus.freepascal.org/index.php/TrayIcon
It works currently on win32 and gtk. In the future it will also work with Gtk2, Carbon, Windows CE and Qt.