Hi everyone

Hi everyone,
does anyone know how to handle Window messages in #firemonkey   form?
I mean posting messages by PostMessage/SendMessage() methods.

PS: Actually I wanted to uncheck single RadioButton, as far as I can't uncheck it in its OnClick event handler, I wanted to post message in message queue and handle it after OnClick event.

Comments

  1. Use TCheckBox instead of TRadioButton
    but set property StyleLookUp to "radiobuttonstyle" - it will looks like radiobutton but acts as checkbox

    ReplyDelete
  2. Sergionn Rad that is obvious answer :)

    the question remains: how to handle window messages in FMX form in Windows

    ReplyDelete
  3. Andrew Terekhov TMessageManager.DefaultManager.SendMessage(const Sender: TObject; AMessage :TMessage;  ADispose : Boolean);
    in FMX.Messages

    ReplyDelete
  4. Or in FMX.Platform.Win use
    FormToHWND and then do PostMessage with it as Handle

    ReplyDelete
  5. Sergionn Rad TForm class itself does not recieve messages as it was in VCL, so we can't PostMessage directly to window and handle it in message procedure (procedure wmTest(var msg : TMessage); message WM_ TEST) because of crossplaform.

    ReplyDelete
  6. Andrew Terekhov Yes we can, you asked about windows remember?
    TForm contains HWND under windows
    use  FMX.Platform.Win, Winapi.Windows;

    if (Application.MainForm <> nil) then
     PostMessage(FormToHWND(Application.MainForm), bla, bla, bla))

    ReplyDelete
  7. Just say what do you want to do exactly, i did a lot things in fmx but handle messages any way was not needed at all..........

    ReplyDelete
  8. Sergionn Rad have you tried to run this code? It does not work in fmx as in vcl (in xe4). It was the first thing i did, thats why i asked about hooking window messages here. Anyway I do not need anything special, I'm just curious

    ReplyDelete
  9. yes did about year ago in my journey with fmx to fix cursor blinks, but finaly did it the other way without messages
    http://stackoverflow.com/questions/9186098/firemonkey-message-handling

    ReplyDelete
  10. Messages are indeed still present in the windows implementations of FMX forms, but controls and components don't get them the same way.  Mouse and keyboard (for example) events are handled differently by the framework, but you can still, for windows at least, use them.  You should be able to simulate mouse clicks on your forms and controls etc

    ReplyDelete
  11. one thing with radiobuttons...they are now grouped...in FMX..set the group name...the same..for all grouped radiobuttons

    ReplyDelete
  12. Paul Foster Something the other way:
    for win, and from p.2 to all:
    1) Messages parse in  FMX.Platform.Win
    2) Then active Form get it by:
     LForm.MouseDown(TMouseButton.mbMiddle, KeysToShiftState(wParam), P.X, P.Y);
    3) Then MouseDown in CustomForm looks for control under Mouse coordinates: 
    Obj := IControl(ObjectAtPoint(ClientToScreen(FMousePos)));
    and then pass in to control if found:
    Obj.MouseDown(Button, Shift, P.X, P.Y);
    - long way of little mouse click!

    ReplyDelete
  13. Simulate is very easy need just call 
    MouseClick() in needed control
    or better can call method Click

    ReplyDelete
  14. Sergionn Rad indeed, some things are better here than in vcl, but also the abstraction from the hardware can be a problem too, but it also means (for example) that you can simulate that click on osx, ios and android in the exact same way.

    I would advise not using windows messages in firemonkey to maintain this as much as possible :-)

    ReplyDelete
  15. Paul Foster sometimes you have to register window handle in third party libraries or Windows itseft to recieve notifications via Messages. Of course I mean not crossplatform apps.

    ReplyDelete
  16. In which case you might be better sticking to the VCL

    ReplyDelete
  17. Paul Foster seems SetWindowHookEx is the only solution to recieve messages from Message queue

    ReplyDelete
  18. Indeed. I'd stick to the vcl if you need to use windows messages....

    ReplyDelete
  19. Paul Foster From step 2 it all crossplatform: units and code...

    ReplyDelete

Post a Comment