I read here about how to create a Window Handle into a non-windowed conrol. I did just the way I read, but nothing happens. So I come to you guys.
My class is this way right now:
interface
type
TMyObject = class
private
fMsgHandlerHWND : HWND;
procedure WndMethod(var Msg: TMessage);
public
constructor Create;
destructor Destroy; Override;
end;
implementation
constructor TMyObject.Create;
begin
inherited;
fMsgHandlerHWND := AllocateHWnd(WndMethod);
end;
destructor TMyObject.Destroy;
begin
deallocatehwnd(fMsgHandlerHWND);
inherited;
end;
procedure TMyObject.WndMethod(var Msg: TMessage);
begin
if Msg.Msg = WM_KEYUP then
MessageBeep(0)
else
Msg.Result := DefWindowProc(fMsgHandlerHWND, Msg.Msg, Msg.wParam, Msg.lParam);
end;
I do use my FormCreate
to execute var := TMyObject.Create
.
Following the line where Windows sends broadcast messages when I press/release a key (correct me if I'm wrong); I'm not sure why it did not work. Somoeone can tell me what did I do wrong? There is another way to catch KeyBoard input with a non-windowed object? If so, how?
Keyboard events are delivered to the window with input focus. That's never going to be your hidden window.
if you want to catch input events the cleanest way is to use the OnMessage
event of the global Application
object. All queued messages pass through this event handler. Subscribe to it using a TApplicationEvents
instance.